Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial conversion to ESM module #362

Merged
merged 10 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions actions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RevolverPlugin } from '../plugins/pluginInterface';
import { TagInterface } from '../drivers/tags';
import { RevolverPlugin } from '../plugins/pluginInterface.js';
import { TagInterface } from '../drivers/tags.js';

export abstract class RevolverAction {
public who: RevolverPlugin;
Expand Down
10 changes: 5 additions & 5 deletions drivers/driverInterface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Logger } from 'tslog';
import { logger, RevolverLogObject } from '../lib/logger';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { RevolverAction } from '../actions/actions';
import { ActionAuditEntry } from '../actions/audit';
import dateTime from '../lib/dateTime';
import { logger, RevolverLogObject } from '../lib/logger.js';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { RevolverAction } from '../actions/actions.js';
import { ActionAuditEntry } from '../actions/audit.js';
import dateTime from '../lib/dateTime.js';

export abstract class DriverInterface {
protected accountConfig: any;
Expand Down
12 changes: 6 additions & 6 deletions drivers/ebs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
paginateDescribeInstances,
} from '@aws-sdk/client-ec2';
import { DateTime } from 'luxon';
import { makeResourceTags, paginateAwsCall } from '../lib/common';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { DriverInterface } from './driverInterface';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions';
import { ec2Tagger } from './tags';
import { getAwsClientForAccount } from '../lib/awsConfig';
import { makeResourceTags, paginateAwsCall } from '../lib/common.js';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { DriverInterface } from './driverInterface.js';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions.js';
import { ec2Tagger } from './tags.js';
import { getAwsClientForAccount } from '../lib/awsConfig.js';

class InstrumentedEBS extends ToolingInterface {
private volumeARN: string;
Expand Down
12 changes: 6 additions & 6 deletions drivers/ec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
StopInstancesCommand,
paginateDescribeInstances,
} from '@aws-sdk/client-ec2';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { DriverInterface } from './driverInterface';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions';
import { chunkArray, makeResourceTags, paginateAwsCall } from '../lib/common';
import { ec2Tagger } from './tags';
import { getAwsClientForAccount } from '../lib/awsConfig';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { DriverInterface } from './driverInterface.js';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions.js';
import { chunkArray, makeResourceTags, paginateAwsCall } from '../lib/common.js';
import { ec2Tagger } from './tags.js';
import { getAwsClientForAccount } from '../lib/awsConfig.js';

class InstrumentedEc2 extends ToolingInterface {
private instanceARN: string;
Expand Down
4 changes: 2 additions & 2 deletions drivers/instrumentedResource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '../lib/logger';
import { logger } from '../lib/logger.js';
import { DateTime } from 'luxon';
import { RevolverAction } from '../actions/actions';
import { RevolverAction } from '../actions/actions.js';

export interface InstrumentedResource {
resourceId: string;
Expand Down
12 changes: 6 additions & 6 deletions drivers/rdsCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
StopDBClusterCommand,
Tag,
} from '@aws-sdk/client-rds';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { DriverInterface } from './driverInterface';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions';
import { rdsTagger } from './tags';
import { getAwsClientForAccount } from '../lib/awsConfig';
import { makeResourceTags } from '../lib/common';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { DriverInterface } from './driverInterface.js';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions.js';
import { rdsTagger } from './tags.js';
import { getAwsClientForAccount } from '../lib/awsConfig.js';
import { makeResourceTags } from '../lib/common.js';

class InstrumentedRdsCluster extends ToolingInterface {
constructor(awsResource: any) {
Expand Down
12 changes: 6 additions & 6 deletions drivers/rdsInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
StopDBInstanceCommand,
Tag,
} from '@aws-sdk/client-rds';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { DriverInterface } from './driverInterface';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions';
import { rdsTagger } from './tags';
import { getAwsClientForAccount } from '../lib/awsConfig';
import { makeResourceTags } from '../lib/common';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { DriverInterface } from './driverInterface.js';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions.js';
import { rdsTagger } from './tags.js';
import { getAwsClientForAccount } from '../lib/awsConfig.js';
import { makeResourceTags } from '../lib/common.js';

class InstrumentedRdsInstance extends ToolingInterface {
public tags: Tag[] = [];
Expand Down
14 changes: 7 additions & 7 deletions drivers/redshiftCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
RedshiftClient,
Tag,
} from '@aws-sdk/client-redshift';
import assume from '../lib/assume';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { DriverInterface } from './driverInterface';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions';
import dateTime from '../lib/dateTime';
import { getAwsClientForAccount } from '../lib/awsConfig';
import { makeResourceTags } from '../lib/common';
import assume from '../lib/assume.js';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { DriverInterface } from './driverInterface.js';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions.js';
import dateTime from '../lib/dateTime.js';
import { getAwsClientForAccount } from '../lib/awsConfig.js';
import { makeResourceTags } from '../lib/common.js';

class InstrumentedRedshiftCluster extends ToolingInterface {
public tags: Tag[] = [];
Expand Down
10 changes: 5 additions & 5 deletions drivers/redshiftClusterSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
RestoreFromClusterSnapshotCommand,
Tag,
} from '@aws-sdk/client-redshift';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { DriverInterface } from './driverInterface';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions';
import { getAwsClientForAccount } from '../lib/awsConfig';
import { makeResourceTags } from '../lib/common';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { DriverInterface } from './driverInterface.js';
import { RevolverAction, RevolverActionWithTags } from '../actions/actions.js';
import { getAwsClientForAccount } from '../lib/awsConfig.js';
import { makeResourceTags } from '../lib/common.js';

class InstrumentedRedshiftClusterSnapshot extends ToolingInterface {
public tags: Tag[] = [];
Expand Down
12 changes: 6 additions & 6 deletions drivers/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
paginateDescribeSnapshots,
paginateDescribeVolumes,
} from '@aws-sdk/client-ec2';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource';
import { DriverInterface } from './driverInterface';
import { RevolverActionWithTags } from '../actions/actions';
import { makeResourceTags, paginateAwsCall } from '../lib/common';
import { ec2Tagger } from './tags';
import { getAwsClientForAccount } from '../lib/awsConfig';
import { InstrumentedResource, ToolingInterface } from './instrumentedResource.js';
import { DriverInterface } from './driverInterface.js';
import { RevolverActionWithTags } from '../actions/actions.js';
import { makeResourceTags, paginateAwsCall } from '../lib/common.js';
import { ec2Tagger } from './tags.js';
import { getAwsClientForAccount } from '../lib/awsConfig.js';

class InstrumentedSnapshot extends ToolingInterface {
get resourceId() {
Expand Down
8 changes: 4 additions & 4 deletions drivers/tags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Logger } from 'tslog';
import { RevolverLogObject } from '../lib/logger';
import { ToolingInterface } from './instrumentedResource';
import { RevolverActionWithTags } from '../actions/actions';
import { chunkArray, unique } from '../lib/common';
import { RevolverLogObject } from '../lib/logger.js';
import { ToolingInterface } from './instrumentedResource.js';
import { RevolverActionWithTags } from '../actions/actions.js';
import { chunkArray, unique } from '../lib/common.js';
import { EC2Client, CreateTagsCommand, DeleteTagsCommand } from '@aws-sdk/client-ec2';
import { AddTagsToResourceCommand, RDSClient, RemoveTagsFromResourceCommand } from '@aws-sdk/client-rds';

Expand Down
2 changes: 1 addition & 1 deletion invoke.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-unresolved
import { EventBridgeEvent, Context } from 'aws-lambda';
import { handler as revolverHandle } from './revolver';
import { handler as revolverHandle } from './revolver.js';

const timeStamp = process.env['CURRENT_TIME'] || new Date().toISOString();

Expand Down
18 changes: 9 additions & 9 deletions lib/accountRevolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DriverInterface } from '../drivers/driverInterface';
import { InstrumentedResource, ToolingInterface } from '../drivers/instrumentedResource';
import { RevolverPlugin } from '../plugins/pluginInterface';
import { logger } from './logger';
import { DriverInterface } from '../drivers/driverInterface.js';
import { InstrumentedResource, ToolingInterface } from '../drivers/instrumentedResource.js';
import { RevolverPlugin } from '../plugins/pluginInterface.js';
import { logger } from './logger.js';
import path from 'node:path';
import { promises as fs } from 'fs';
import { buildFilter } from '../plugins/filters/index';
import { promises as fs } from 'node:fs';
import { buildFilter } from '../plugins/filters/index.js';
import {
ActionAuditTable,
ObjectLogTable,
Expand All @@ -13,7 +13,7 @@ import {
ResourceTable,
ObjectLogHtml,
resetFileLogger,
} from './objectLog';
} from './objectLog.js';

export class AccountRevolver {
readonly supportedDrivers = [
Expand Down Expand Up @@ -54,7 +54,7 @@ export class AccountRevolver {
activePlugins.flatMap((xs: string) => {
this.logger.info(`Configuring plugin ${xs}...`);
return this.config.plugins[xs].configs.map(async (xp: any) => {
const PluginModule = await require(`../plugins/${xs}`);
const PluginModule = await import(`../plugins/${xs}.js`);
return new PluginModule['default'](this.config, xs, xp);
});
}),
Expand All @@ -66,7 +66,7 @@ export class AccountRevolver {
.filter((xd: any) => this.supportedDrivers.indexOf(xd.name) > -1)
.map(async (xd: any) => {
this.logger.info(`Configuring driver ${xd.name}...`);
const DriverModule = await require(`../drivers/${xd.name}`);
const DriverModule = await import(`../drivers/${xd.name}.js`);
return new DriverModule.default(this.config, xd);
}),
);
Expand Down
6 changes: 3 additions & 3 deletions lib/assume.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { logger } from './logger';
import { logger } from './logger.js';
import { STS } from '@aws-sdk/client-sts';
import dateTime from './dateTime';
import dateTime from './dateTime.js';
import { DateTime } from 'luxon';
import { AwsCredentialIdentity as Credentials, Provider } from '@aws-sdk/types';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { getAwsConfig } from './awsConfig';
import { getAwsConfig } from './awsConfig.js';

export interface Creds {
expiration: DateTime;
Expand Down
4 changes: 2 additions & 2 deletions lib/awsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import environ from './environ';
import environ from './environ.js';
import { AwsCredentialIdentity as Credentials, Provider } from '@aws-sdk/types';
import { NodeHttpHandler } from '@smithy/node-http-handler';
import { HttpsProxyAgent } from 'https-proxy-agent';
import assume from '../lib/assume';
import assume from '../lib/assume.js';

// In version 3 , there is no longer a global configuration managed by the SDK
function getAwsConfig(region?: string, credentials?: Credentials | Provider<Credentials>) {
Expand Down
12 changes: 6 additions & 6 deletions lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { logger } from './logger';
import { promises as fs } from 'fs';
import { logger } from './logger.js';
import { promises as fs } from 'node:fs';
import path = require('node:path');
import yaml from 'js-yaml';
import { Organizations, paginateListAccounts } from '@aws-sdk/client-organizations';
import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
import { paginateAwsCall } from './common';
import { paginateAwsCall } from './common.js';
import { merge } from 'ts-deepmerge';
import { getAwsConfig } from './awsConfig';
import { ConfigSchema } from './config-schema';
import { getAwsConfig } from './awsConfig.js';
import { ConfigSchema } from './config-schema.js';
import { ZodError, ZodIssueCode, ZodInvalidUnionIssue, ZodInvalidArgumentsIssue, ZodInvalidReturnTypeIssue } from 'zod';
import { ObjectLogJson } from './objectLog';
import { ObjectLogJson } from './objectLog.js';

function flattenZodErrors(ze: ZodError, depth: number): string[] {
let lines: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/dateTime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DateTime as LuxonDateTime } from 'luxon';
import { logger } from './logger';
import { logger } from './logger.js';

/**
* A class for using a consistent time during execution of a cycle of Revolver.
Expand Down
2 changes: 1 addition & 1 deletion lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger, ISettingsParam } from 'tslog';
import environ from './environ';
import environ from './environ.js';

const logLevels: { [key: string]: number } = {
silly: 0,
Expand Down
14 changes: 7 additions & 7 deletions lib/objectLog.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ToolingInterface } from '../drivers/instrumentedResource';
import { logger } from './logger';
import { existsSync, promises as fs } from 'fs';
import { getAwsConfig } from './awsConfig';
import { ToolingInterface } from '../drivers/instrumentedResource.js';
import { logger } from './logger.js';
import { existsSync, promises as fs } from 'node:fs';
import { getAwsConfig } from './awsConfig.js';
import { GetObjectCommand, NoSuchKey, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { SendMessageCommand, SQSClient, MessageAttributeValue } from '@aws-sdk/client-sqs';
import { ActionAuditEntry } from '../actions/audit';
import dateTime from './dateTime';
import { htmlTableReport } from './templater';
import { ActionAuditEntry } from '../actions/audit.js';
import dateTime from './dateTime.js';
import { htmlTableReport } from './templater.js';
import zlib from 'node:zlib';
import { stringify } from 'csv-stringify/sync';
import { PublishCommand, SNSClient } from '@aws-sdk/client-sns';
Expand Down
Loading
Loading