From 7aeb5713bb61317b4859de75d321ea08dba8addb Mon Sep 17 00:00:00 2001 From: Nicolas Molina Date: Fri, 10 Jan 2025 13:07:24 -0300 Subject: [PATCH 1/7] fix: plat-5545 reading new env var in actions layer --- packages/kvstore/src/index.ts | 6 +++++- packages/relay-signer/src/relayer.ts | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/kvstore/src/index.ts b/packages/kvstore/src/index.ts index ba406c01..316147d4 100644 --- a/packages/kvstore/src/index.ts +++ b/packages/kvstore/src/index.ts @@ -12,7 +12,11 @@ export class KeyValueStoreClient implements IKeyValueStoreClient { protected implementation: IKeyValueStoreClient; public constructor(params: KeyValueStoreCreateParams | LocalKeyValueStoreCreateParams) { - if (isActionCreateParams(params)) { + const defenderAction = process.env.DEFENDER_ENV; + if (defenderAction === 'action') { + 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); diff --git a/packages/relay-signer/src/relayer.ts b/packages/relay-signer/src/relayer.ts index a099bba1..dc03ea84 100644 --- a/packages/relay-signer/src/relayer.ts +++ b/packages/relay-signer/src/relayer.ts @@ -59,7 +59,12 @@ export class Relayer implements IRelayer { public constructor(credentials: RelayerParams) { this.credentials = credentials; - if (isActionCredentials(credentials)) { + const defenderAction = process.env.DEFENDER_ENV; + const errorMessage = `Missing credentials for creating a Relayer instance. If you are running this code in an Action, make sure you pass the "credentials" parameter from the handler to the Relayer constructor. If you are running this on your own process, then pass an object with the "apiKey" and "apiSecret" generated by the relayer.`; + if (defenderAction === 'action') { + if (!isActionCredentials(credentials)) { + throw new Error(errorMessage); + } // eslint-disable-next-line @typescript-eslint/no-var-requires const { ActionRelayer } = require('./action'); this.relayer = new ActionRelayer(credentials); @@ -69,9 +74,7 @@ export class Relayer implements IRelayer { authConfig: { ...credentials.authConfig, type: 'relay' }, }); } else { - throw new Error( - `Missing credentials for creating a Relayer instance. If you are running this code in an Action, make sure you pass the "credentials" parameter from the handler to the Relayer constructor. If you are running this on your own process, then pass an object with the "apiKey" and "apiSecret" generated by the relayer.`, - ); + throw new Error(errorMessage); } } From 28787f7f4ecf110cd99f9bbb115db7f0e3399445 Mon Sep 17 00:00:00 2001 From: Nicolas Molina Date: Fri, 10 Jan 2025 14:52:55 -0300 Subject: [PATCH 2/7] fix: plat-5545 fixing unit test by reading new env var --- packages/kvstore/src/index.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/kvstore/src/index.test.ts b/packages/kvstore/src/index.test.ts index 5a9fe3b5..0bfacea8 100644 --- a/packages/kvstore/src/index.test.ts +++ b/packages/kvstore/src/index.test.ts @@ -1,3 +1,4 @@ +import { beforeEach } from 'node:test'; import { KeyValueStoreClient, KeyValueStoreCreateParams } from '.'; import { KeyValueStoreActionClient } from './action'; import { KeyValueStoreLocalClient } from './local'; @@ -10,6 +11,15 @@ 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' }); @@ -17,6 +27,7 @@ describe('KeyValueStoreClient', () => { }); test('creates an autotask client', async () => { + process.env.DEFENDER_ENV = 'action'; const credentials = JSON.stringify({ AccessKeyId: 'keyId', SecretAccessKey: 'accessKey', From 66ea640e2f81c51e2593352caf71de6d6b3808f1 Mon Sep 17 00:00:00 2001 From: Nicolas Molina Date: Fri, 10 Jan 2025 14:57:08 -0300 Subject: [PATCH 3/7] fix: plat-5545 fixing wrong import --- packages/kvstore/src/index.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/kvstore/src/index.test.ts b/packages/kvstore/src/index.test.ts index 0bfacea8..7f5e618b 100644 --- a/packages/kvstore/src/index.test.ts +++ b/packages/kvstore/src/index.test.ts @@ -1,4 +1,3 @@ -import { beforeEach } from 'node:test'; import { KeyValueStoreClient, KeyValueStoreCreateParams } from '.'; import { KeyValueStoreActionClient } from './action'; import { KeyValueStoreLocalClient } from './local'; From cd7210b2ff3b3f4d1b57af9ad2b1753553ee3149 Mon Sep 17 00:00:00 2001 From: Nicolas Molina Date: Mon, 13 Jan 2025 09:19:39 -0300 Subject: [PATCH 4/7] fix: plat-5545 improving var names --- packages/kvstore/src/index.ts | 4 ++-- packages/relay-signer/src/relayer.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kvstore/src/index.ts b/packages/kvstore/src/index.ts index 316147d4..6a238ad2 100644 --- a/packages/kvstore/src/index.ts +++ b/packages/kvstore/src/index.ts @@ -12,8 +12,8 @@ export class KeyValueStoreClient implements IKeyValueStoreClient { protected implementation: IKeyValueStoreClient; public constructor(params: KeyValueStoreCreateParams | LocalKeyValueStoreCreateParams) { - const defenderAction = process.env.DEFENDER_ENV; - if (defenderAction === 'action') { + const defenderEnv = process.env.DEFENDER_ENV; + if (defenderEnv === 'action') { if (!isActionCreateParams(params)) { throw new Error('Invalid create params for KeyValueStoreClient'); } diff --git a/packages/relay-signer/src/relayer.ts b/packages/relay-signer/src/relayer.ts index dc03ea84..51c377df 100644 --- a/packages/relay-signer/src/relayer.ts +++ b/packages/relay-signer/src/relayer.ts @@ -59,9 +59,9 @@ export class Relayer implements IRelayer { public constructor(credentials: RelayerParams) { this.credentials = credentials; - const defenderAction = process.env.DEFENDER_ENV; + const defenderEnv = process.env.DEFENDER_ENV; const errorMessage = `Missing credentials for creating a Relayer instance. If you are running this code in an Action, make sure you pass the "credentials" parameter from the handler to the Relayer constructor. If you are running this on your own process, then pass an object with the "apiKey" and "apiSecret" generated by the relayer.`; - if (defenderAction === 'action') { + if (defenderEnv === 'action') { if (!isActionCredentials(credentials)) { throw new Error(errorMessage); } From f31ac425fe05d5d6edd19d45abd7019754afd1a9 Mon Sep 17 00:00:00 2001 From: Nicolas Molina Date: Wed, 15 Jan 2025 11:24:26 -0300 Subject: [PATCH 5/7] fix: plat-5545 deleting changes applied to relayer no longer needed --- packages/relay-signer/src/relayer.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/relay-signer/src/relayer.ts b/packages/relay-signer/src/relayer.ts index 51c377df..a099bba1 100644 --- a/packages/relay-signer/src/relayer.ts +++ b/packages/relay-signer/src/relayer.ts @@ -59,12 +59,7 @@ export class Relayer implements IRelayer { public constructor(credentials: RelayerParams) { this.credentials = credentials; - const defenderEnv = process.env.DEFENDER_ENV; - const errorMessage = `Missing credentials for creating a Relayer instance. If you are running this code in an Action, make sure you pass the "credentials" parameter from the handler to the Relayer constructor. If you are running this on your own process, then pass an object with the "apiKey" and "apiSecret" generated by the relayer.`; - if (defenderEnv === 'action') { - if (!isActionCredentials(credentials)) { - throw new Error(errorMessage); - } + if (isActionCredentials(credentials)) { // eslint-disable-next-line @typescript-eslint/no-var-requires const { ActionRelayer } = require('./action'); this.relayer = new ActionRelayer(credentials); @@ -74,7 +69,9 @@ export class Relayer implements IRelayer { authConfig: { ...credentials.authConfig, type: 'relay' }, }); } else { - throw new Error(errorMessage); + throw new Error( + `Missing credentials for creating a Relayer instance. If you are running this code in an Action, make sure you pass the "credentials" parameter from the handler to the Relayer constructor. If you are running this on your own process, then pass an object with the "apiKey" and "apiSecret" generated by the relayer.`, + ); } } From 458bad0b3fe18e83eeac6b69ed4d0b3ad5c63cc0 Mon Sep 17 00:00:00 2001 From: Nicolas Molina Date: Wed, 15 Jan 2025 11:30:23 -0300 Subject: [PATCH 6/7] fix: plat-5545 fixing env var value --- packages/kvstore/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kvstore/src/index.ts b/packages/kvstore/src/index.ts index 6a238ad2..0684a276 100644 --- a/packages/kvstore/src/index.ts +++ b/packages/kvstore/src/index.ts @@ -13,7 +13,7 @@ export class KeyValueStoreClient implements IKeyValueStoreClient { public constructor(params: KeyValueStoreCreateParams | LocalKeyValueStoreCreateParams) { const defenderEnv = process.env.DEFENDER_ENV; - if (defenderEnv === 'action') { + if (defenderEnv === 'DEFENDER_ACTION_ENVIRONMENT') { if (!isActionCreateParams(params)) { throw new Error('Invalid create params for KeyValueStoreClient'); } From a18a14e453211b6d0134a7fd55b12774db8c9b67 Mon Sep 17 00:00:00 2001 From: Nicolas Molina Date: Wed, 15 Jan 2025 11:31:17 -0300 Subject: [PATCH 7/7] fix: plat-5545 fixing env var value for testing --- packages/kvstore/src/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kvstore/src/index.test.ts b/packages/kvstore/src/index.test.ts index 7f5e618b..eb6c0cd5 100644 --- a/packages/kvstore/src/index.test.ts +++ b/packages/kvstore/src/index.test.ts @@ -26,7 +26,7 @@ describe('KeyValueStoreClient', () => { }); test('creates an autotask client', async () => { - process.env.DEFENDER_ENV = 'action'; + process.env.DEFENDER_ENV = 'DEFENDER_ACTION_ENVIRONMENT'; const credentials = JSON.stringify({ AccessKeyId: 'keyId', SecretAccessKey: 'accessKey',