Skip to content

Commit

Permalink
fix: plat-5545 reading new env var for actions (#684)
Browse files Browse the repository at this point in the history
* fix: plat-5545 reading new env var in actions layer

* fix: plat-5545 fixing unit test by reading new env var

* fix: plat-5545 fixing wrong import

* fix: plat-5545 improving var names

* fix: plat-5545 deleting changes applied to relayer no longer needed

* fix: plat-5545 fixing env var value

* fix: plat-5545 fixing env var value for testing
  • Loading branch information
NicoMolinaOZ authored Jan 21, 2025
1 parent 7652d86 commit 2bfbb0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/kvstore/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ class TestClient extends KeyValueStoreClient {
}

describe('KeyValueStoreClient', () => {
const envs = process.env;
beforeEach(() => {
process.env = { ...envs };
});

afterEach(() => {
process.env = envs;
});

describe('create', () => {
test('creates a local client', async () => {
const client = new TestClient({ path: '/tmp/foo' });
expect(client.getImplementation()).toBeInstanceOf(KeyValueStoreLocalClient);
});

test('creates an autotask client', async () => {
process.env.DEFENDER_ENV = 'DEFENDER_ACTION_ENVIRONMENT';
const credentials = JSON.stringify({
AccessKeyId: 'keyId',
SecretAccessKey: 'accessKey',
Expand Down
6 changes: 5 additions & 1 deletion packages/kvstore/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export class KeyValueStoreClient implements IKeyValueStoreClient {
protected implementation: IKeyValueStoreClient;

public constructor(params: KeyValueStoreCreateParams | LocalKeyValueStoreCreateParams) {
if (isActionCreateParams(params)) {
const defenderEnv = process.env.DEFENDER_ENV;
if (defenderEnv === 'DEFENDER_ACTION_ENVIRONMENT') {
if (!isActionCreateParams(params)) {
throw new Error('Invalid create params for KeyValueStoreClient');
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { KeyValueStoreActionClient } = require('./action');
this.implementation = new KeyValueStoreActionClient(params);
Expand Down

0 comments on commit 2bfbb0c

Please sign in to comment.