Skip to content

Commit

Permalink
fix: added support for prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-sanare committed Aug 8, 2023
1 parent 214ee97 commit cb91dc1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/aws/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccessKey, CreateAccessKeyCommand, DeleteAccessKeyCommand, IAMClient } from '@aws-sdk/client-iam';
import { SourceModule, KeyInfo, getEnv } from '@refreshly/core';
import { SourceModule, KeyInfo, getEnv, prefix } from '@refreshly/core';
import * as assert from 'assert';

class AWSSourceModule extends SourceModule {
Expand Down Expand Up @@ -48,11 +48,11 @@ class AWSSourceModule extends SourceModule {

return [
{
name: 'AWS_ACCESS_KEY_ID',
name: prefix(this.#options.prefix, 'AWS_ACCESS_KEY_ID'),
value: this.#accessKey.AccessKeyId,
},
{
name: 'AWS_SECRET_ACCESS_KEY',
name: prefix(this.#options.prefix, 'AWS_SECRET_ACCESS_KEY'),
value: this.#accessKey.SecretAccessKey,
},
];
Expand Down Expand Up @@ -101,6 +101,7 @@ namespace AWSSourceModule {
export type Options = {
key?: string;
secretKey?: string;
prefix?: string;
user: string;
};

Expand Down
4 changes: 4 additions & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ export function getEnv<T>(configKey: string, configValue?: T, ...keys: string[])
throw new Error(`Expected ${configKey} to be provided via... (${keys.join(', ')})`);
}

export function prefix(...values: string[]): string {
return values.filter(Boolean).join('');
}

export * from './@types';
5 changes: 3 additions & 2 deletions packages/github/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from 'octokit';
import * as sodium from 'libsodium-wrappers';
import { KeyInfo, ITargetModule, getEnv } from '@refreshly/core';
import { KeyInfo, ITargetModule, getEnv, prefix } from '@refreshly/core';

class GitHubTargetModule implements ITargetModule {
#options: GitHubTargetModule.Options;
Expand Down Expand Up @@ -57,7 +57,7 @@ class GitHubTargetModule implements ITargetModule {
await this.#octokit.rest.actions.createOrUpdateOrgSecret({
key_id,
org: this.#options.org,
secret_name: keyInfo.name,
secret_name: prefix(this.#options.prefix, keyInfo.name),
visibility: 'all',
encrypted_value: sodium.to_base64(encBytes, sodium.base64_variants.ORIGINAL),
});
Expand All @@ -72,6 +72,7 @@ class GitHubTargetModule implements ITargetModule {
namespace GitHubTargetModule {
export interface Options {
token?: string;
prefix?: string;
org: string;
}
}
Expand Down

0 comments on commit cb91dc1

Please sign in to comment.