Skip to content

Commit

Permalink
fix: resolved issue with nested options clashing
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-sanare committed Aug 8, 2023
1 parent 86b7739 commit fdb56a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
40 changes: 20 additions & 20 deletions packages/aws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { SourceModule, KeyInfo, getEnv, prefix } from '@refreshly/core';
import * as assert from 'assert';

class AWSSourceModule extends SourceModule {
#options: AWSSourceModule.Options;
#accessKey?: AccessKey;
private options: AWSSourceModule.Options;
private accessKey?: AccessKey;

constructor({ targets, key, secretKey, ...options }: AWSSourceModule.RawOptions) {
super({ targets });

this.#options = {
this.options = {
...options,
key: getEnv('key', key, 'AWS_ACCESS_KEY_ID'),
secretKey: getEnv('secretKey', secretKey, 'AWS_SECRET_ACCESS_KEY'),
Expand All @@ -20,11 +20,11 @@ class AWSSourceModule extends SourceModule {
return [
{
name: 'AWS_ACCESS_KEY_ID',
value: this.#options.key,
value: this.options.key,
},
{
name: 'AWS_SECRET_ACCESS_KEY',
value: this.#options.secretKey,
value: this.options.secretKey,
},
];
}
Expand All @@ -33,8 +33,8 @@ class AWSSourceModule extends SourceModule {
const client = new IAMClient({
region: 'us-east-1',
credentials: {
accessKeyId: this.#options.key,
secretAccessKey: this.#options.secretKey,
accessKeyId: this.options.key,
secretAccessKey: this.options.secretKey,
},
});

Expand All @@ -44,54 +44,54 @@ class AWSSourceModule extends SourceModule {
})
);

this.#accessKey = AccessKey;
this.accessKey = AccessKey;

return [
{
name: prefix(this.#options.prefix, 'AWS_ACCESS_KEY_ID'),
value: this.#accessKey.AccessKeyId,
name: prefix(this.options.prefix, 'AWS_ACCESS_KEY_ID'),
value: this.accessKey.AccessKeyId,
},
{
name: prefix(this.#options.prefix, 'AWS_SECRET_ACCESS_KEY'),
value: this.#accessKey.SecretAccessKey,
name: prefix(this.options.prefix, 'AWS_SECRET_ACCESS_KEY'),
value: this.accessKey.SecretAccessKey,
},
];
}

async revert(): Promise<void> {
if (!this.#accessKey) return;
if (!this.accessKey) return;

// Retain the old key and cleanup the new key
const client = new IAMClient({
region: 'us-east-1',
credentials: {
accessKeyId: this.#options.key,
secretAccessKey: this.#options.secretKey,
accessKeyId: this.options.key,
secretAccessKey: this.options.secretKey,
},
});

await client.send(
new DeleteAccessKeyCommand({
AccessKeyId: this.#accessKey.AccessKeyId,
AccessKeyId: this.accessKey.AccessKeyId,
})
);
}

async cleanup(): Promise<void> {
assert.ok(this.#accessKey);
assert.ok(this.accessKey);

// Retain the new key and cleanup the old key
const client = new IAMClient({
region: 'us-east-1',
credentials: {
accessKeyId: this.#accessKey.AccessKeyId,
secretAccessKey: this.#accessKey.SecretAccessKey,
accessKeyId: this.accessKey.AccessKeyId,
secretAccessKey: this.accessKey.SecretAccessKey,
},
});

await client.send(
new DeleteAccessKeyCommand({
AccessKeyId: this.#options.key,
AccessKeyId: this.options.key,
})
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/core/@types/source-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { KeyInfo } from './key-info';
import { ITargetModule } from './target-module';

export abstract class SourceModule {
#options: SourceModule.Options;
private options: SourceModule.Options;

constructor(options: SourceModule.Options) {
this.#options = options;
this.options = options;
}

abstract get originalKeyInfos(): KeyInfo[];
Expand All @@ -15,7 +15,7 @@ export abstract class SourceModule {

try {
await Promise.all(
this.#options.targets.map(async (target) => {
this.options.targets.map(async (target) => {
await target.target(keyInfos);
})
);
Expand All @@ -27,7 +27,7 @@ export abstract class SourceModule {
console.log(`Error detected, reverting to previous state...`);

await Promise.all(
this.#options.targets.map(async (target) => {
this.options.targets.map(async (target) => {
await target.revert(this.originalKeyInfos);
})
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { KeyInfo, Refreshly, SourceModule, getEnv, prefix } from '../index';

describe('@refreshly/core', () => {
describe('func(Refreshly)', () => {
it('should ...', async () => {
it('should execute all of the source modules', async () => {
class FakeModule extends SourceModule {
get originalKeyInfos(): KeyInfo[] {
return [];
Expand Down

0 comments on commit fdb56a8

Please sign in to comment.