From 5056c23292652d13c401eec3652c178096b85cc3 Mon Sep 17 00:00:00 2001 From: Alex Pickering Date: Wed, 24 Aug 2022 14:11:19 -0700 Subject: [PATCH 1/6] make admin sub account agnostic --- src/api.v2/constants.js | 7 +++++++ src/config/default-config.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api.v2/constants.js b/src/api.v2/constants.js index 66fcde157..2bf76b243 100644 --- a/src/api.v2/constants.js +++ b/src/api.v2/constants.js @@ -32,6 +32,12 @@ const ACCOUNT_ID = { HMS: '160782110667', }; +const ADMIN_SUB = { + BIOMAGE: '032abd44-0cd3-4d58-af21-850ca0b95ac7', + HMS: 'a01e8bcc-c9a2-4c56-bd66-39de93764be8', + +}; + module.exports = { QC_PROCESS_NAME, GEM2S_PROCESS_NAME, @@ -47,4 +53,5 @@ module.exports = { ASSIGN_POD_TO_PIPELINE, EXPIRED_EXECUTION_DATE, ACCOUNT_ID, + ADMIN_SUB, }; diff --git a/src/config/default-config.js b/src/config/default-config.js index f5659c7d4..cd5089b22 100644 --- a/src/config/default-config.js +++ b/src/config/default-config.js @@ -2,6 +2,7 @@ const AWS = require('aws-sdk'); const getLogger = require('../utils/getLogger'); const logger = getLogger(); +const { ACCOUNT_ID, ADMIN_SUB } = require('../api.v2/constants'); const githubOrganisationName = 'hms-dbmi-cellenics'; @@ -78,7 +79,7 @@ const config = { pipelineInstanceConfigUrl: `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/production/pipeline.yaml`, cachingEnabled: true, corsOriginUrl: `https://${domainName}`, - adminSub: '032abd44-0cd3-4d58-af21-850ca0b95ac7', + adminSub: process.env.AWS_ACCOUNT_ID === ACCOUNT_ID.HMS ? ADMIN_SUB.HMS : ADMIN_SUB.BIOMAGE, }; From 0a6202b54d69b38439d02fbb64ad5e4363a94bdc Mon Sep 17 00:00:00 2001 From: Alex Pickering Date: Wed, 24 Aug 2022 14:18:55 -0700 Subject: [PATCH 2/6] make more pithy --- src/api.v2/constants.js | 4 ++-- src/config/default-config.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api.v2/constants.js b/src/api.v2/constants.js index 2bf76b243..b5aebbbdc 100644 --- a/src/api.v2/constants.js +++ b/src/api.v2/constants.js @@ -33,8 +33,8 @@ const ACCOUNT_ID = { }; const ADMIN_SUB = { - BIOMAGE: '032abd44-0cd3-4d58-af21-850ca0b95ac7', - HMS: 'a01e8bcc-c9a2-4c56-bd66-39de93764be8', + [ACCOUNT_ID.Biomage]: '032abd44-0cd3-4d58-af21-850ca0b95ac7', + [ACCOUNT_ID.HMS]: 'a01e8bcc-c9a2-4c56-bd66-39de93764be8', }; diff --git a/src/config/default-config.js b/src/config/default-config.js index cd5089b22..ec36e9df0 100644 --- a/src/config/default-config.js +++ b/src/config/default-config.js @@ -2,7 +2,7 @@ const AWS = require('aws-sdk'); const getLogger = require('../utils/getLogger'); const logger = getLogger(); -const { ACCOUNT_ID, ADMIN_SUB } = require('../api.v2/constants'); +const { ADMIN_SUB } = require('../api.v2/constants'); const githubOrganisationName = 'hms-dbmi-cellenics'; @@ -79,7 +79,7 @@ const config = { pipelineInstanceConfigUrl: `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/production/pipeline.yaml`, cachingEnabled: true, corsOriginUrl: `https://${domainName}`, - adminSub: process.env.AWS_ACCOUNT_ID === ACCOUNT_ID.HMS ? ADMIN_SUB.HMS : ADMIN_SUB.BIOMAGE, + adminSub: ADMIN_SUB[process.env.AWS_ACCOUNT_ID], }; From 1f6e55f5987c940d8877abcc5da86cef98561097 Mon Sep 17 00:00:00 2001 From: Alex Pickering Date: Wed, 24 Aug 2022 16:05:48 -0700 Subject: [PATCH 3/6] reduce repetitiveness --- src/config/default-config.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/config/default-config.js b/src/config/default-config.js index ec36e9df0..e50767e99 100644 --- a/src/config/default-config.js +++ b/src/config/default-config.js @@ -79,7 +79,7 @@ const config = { pipelineInstanceConfigUrl: `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/production/pipeline.yaml`, cachingEnabled: true, corsOriginUrl: `https://${domainName}`, - adminSub: ADMIN_SUB[process.env.AWS_ACCOUNT_ID], + adminSub: ADMIN_SUB[process.env.AWS_ACCOUNT_ID] || '0b17683f-363b-4466-b2e2-5bf11c38a76e', }; @@ -89,7 +89,6 @@ if (config.clusterEnv === 'staging' && config.sandboxId === 'default') { config.pipelineInstanceConfigUrl = `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/staging/pipeline.yaml`; config.cachingEnabled = false; config.corsOriginUrl = `https://ui-default.${domainName}`; - config.adminSub = '0b17683f-363b-4466-b2e2-5bf11c38a76e'; } // We are in user staging environments @@ -98,7 +97,6 @@ if (config.clusterEnv === 'staging' && config.sandboxId !== 'default') { config.pipelineInstanceConfigUrl = `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/staging/${config.sandboxId}.yaml`; config.cachingEnabled = false; config.corsOriginUrl = `https://ui-${config.sandboxId}.${domainName}`; - config.adminSub = '0b17683f-363b-4466-b2e2-5bf11c38a76e'; } @@ -116,7 +114,6 @@ if (config.clusterEnv === 'development') { }); config.corsOriginUrl = 'http://localhost:5000'; - config.adminSub = '0b17683f-363b-4466-b2e2-5bf11c38a76e'; } module.exports = config; From 45d382bcf025a28a1bab75113847cf0b4109e222 Mon Sep 17 00:00:00 2001 From: Alex Pickering Date: Wed, 24 Aug 2022 16:07:28 -0700 Subject: [PATCH 4/6] revert --- src/config/default-config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config/default-config.js b/src/config/default-config.js index e50767e99..ec36e9df0 100644 --- a/src/config/default-config.js +++ b/src/config/default-config.js @@ -79,7 +79,7 @@ const config = { pipelineInstanceConfigUrl: `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/production/pipeline.yaml`, cachingEnabled: true, corsOriginUrl: `https://${domainName}`, - adminSub: ADMIN_SUB[process.env.AWS_ACCOUNT_ID] || '0b17683f-363b-4466-b2e2-5bf11c38a76e', + adminSub: ADMIN_SUB[process.env.AWS_ACCOUNT_ID], }; @@ -89,6 +89,7 @@ if (config.clusterEnv === 'staging' && config.sandboxId === 'default') { config.pipelineInstanceConfigUrl = `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/staging/pipeline.yaml`; config.cachingEnabled = false; config.corsOriginUrl = `https://ui-default.${domainName}`; + config.adminSub = '0b17683f-363b-4466-b2e2-5bf11c38a76e'; } // We are in user staging environments @@ -97,6 +98,7 @@ if (config.clusterEnv === 'staging' && config.sandboxId !== 'default') { config.pipelineInstanceConfigUrl = `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/staging/${config.sandboxId}.yaml`; config.cachingEnabled = false; config.corsOriginUrl = `https://ui-${config.sandboxId}.${domainName}`; + config.adminSub = '0b17683f-363b-4466-b2e2-5bf11c38a76e'; } @@ -114,6 +116,7 @@ if (config.clusterEnv === 'development') { }); config.corsOriginUrl = 'http://localhost:5000'; + config.adminSub = '0b17683f-363b-4466-b2e2-5bf11c38a76e'; } module.exports = config; From b330985b4baa4374bdaf1ea82a1cec8fa64db7ab Mon Sep 17 00:00:00 2001 From: Alex Pickering Date: Mon, 29 Aug 2022 09:36:28 -0700 Subject: [PATCH 5/6] fix caps --- src/api.v2/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api.v2/constants.js b/src/api.v2/constants.js index b5aebbbdc..caa1f5881 100644 --- a/src/api.v2/constants.js +++ b/src/api.v2/constants.js @@ -33,7 +33,7 @@ const ACCOUNT_ID = { }; const ADMIN_SUB = { - [ACCOUNT_ID.Biomage]: '032abd44-0cd3-4d58-af21-850ca0b95ac7', + [ACCOUNT_ID.BIOMAGE]: '032abd44-0cd3-4d58-af21-850ca0b95ac7', [ACCOUNT_ID.HMS]: 'a01e8bcc-c9a2-4c56-bd66-39de93764be8', }; From 094de2953666f7296eb4339691ef7251630a9ecb Mon Sep 17 00:00:00 2001 From: Alex Pickering Date: Mon, 29 Aug 2022 10:10:04 -0700 Subject: [PATCH 6/6] update tests --- src/config/default-config.js | 1 - .../default-config-production.test.js.snap | 32 ++++++++++++++- .../config/default-config-production.test.js | 39 ++++++++++++++++++- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/config/default-config.js b/src/config/default-config.js index ec36e9df0..a207f5f71 100644 --- a/src/config/default-config.js +++ b/src/config/default-config.js @@ -82,7 +82,6 @@ const config = { adminSub: ADMIN_SUB[process.env.AWS_ACCOUNT_ID], }; - // We are in permanent develop staging environment if (config.clusterEnv === 'staging' && config.sandboxId === 'default') { config.workerInstanceConfigUrl = `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/staging/worker.yaml`; diff --git a/tests/config/__snapshots__/default-config-production.test.js.snap b/tests/config/__snapshots__/default-config-production.test.js.snap index bb4b53d7d..1cbe725cd 100644 --- a/tests/config/__snapshots__/default-config-production.test.js.snap +++ b/tests/config/__snapshots__/default-config-production.test.js.snap @@ -1,12 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`default-config Returns correct values for production 1`] = ` +exports[`default-config Returns correct values for BIOMAGE production 1`] = ` Object { "adminSub": "032abd44-0cd3-4d58-af21-850ca0b95ac7", "api": Object { "prefix": "/", }, - "awsAccountId": "000000000000", + "awsAccountId": "242905224710", "awsRegion": "eu-west-1", "cachingEnabled": true, "clusterEnv": "production", @@ -28,3 +28,31 @@ Object { "workerNamespace": "worker-default", } `; + +exports[`default-config Returns correct values for HMS production 1`] = ` +Object { + "adminSub": "a01e8bcc-c9a2-4c56-bd66-39de93764be8", + "api": Object { + "prefix": "/", + }, + "awsAccountId": "160782110667", + "awsRegion": "eu-west-1", + "cachingEnabled": true, + "clusterEnv": "production", + "cognitoISP": mockConstructor { + "CALL_EVENTS_BUBBLE": [MockFunction], + "MONITOR_EVENTS_BUBBLE": [MockFunction], + }, + "corsOriginUrl": "https://localhost:5000", + "domainName": "localhost:5000", + "githubToken": undefined, + "pipelineInstanceConfigUrl": "https://raw.githubusercontent.com/hms-dbmi-cellenics/iac/master/releases/production/pipeline.yaml", + "pipelineNamespace": "pipeline-default", + "podName": "local", + "port": 3000, + "rdsSandboxId": "default", + "sandboxId": "default", + "workerInstanceConfigUrl": "https://raw.githubusercontent.com/hms-dbmi-cellenics/iac/master/releases/production/worker.yaml", + "workerNamespace": "worker-default", +} +`; diff --git a/tests/config/default-config-production.test.js b/tests/config/default-config-production.test.js index 812795e66..45ca2af2c 100644 --- a/tests/config/default-config-production.test.js +++ b/tests/config/default-config-production.test.js @@ -20,11 +20,48 @@ describe('default-config', () => { process.env = OLD_ENV; }); - it('Returns correct values for production', () => { + it('Returns correct values for BIOMAGE production', () => { const prodEnvironment = 'production'; process.env.K8S_ENV = prodEnvironment; process.env.CLUSTER_ENV = prodEnvironment; process.env.AWS_DEFAULT_REGION = 'eu-west-1'; + process.env.AWS_ACCOUNT_ID = '242905224710'; + + const userPoolId = 'mockUserPoolId'; + const accountId = 'mockAccountId'; + + AWS.CognitoIdentityServiceProvider = jest.fn(() => ({ + listUserPools: { + promise: jest.fn(() => Promise.resolve( + { UserPools: [{ id: userPoolId, Name: `biomage-user-pool-case-insensitive-${prodEnvironment}` }] }, + )), + }, + })); + + AWS.STS = jest.fn(() => ({ + getCallerIdentity: { + promise: jest.fn(() => Promise.resolve({ Account: accountId })), + }, + })); + + const defaultConfig = jest.requireActual('../../src/config/default-config'); + + const defaultConfigEntries = Object.entries(defaultConfig); + const filteredEntries = defaultConfigEntries.filter(([, value]) => !isPromise(value)); + const defaultConfigFiltered = Object.fromEntries(filteredEntries); + + expect(defaultConfigFiltered).toMatchSnapshot(); + }); + + it('Returns correct values for HMS production', () => { + jest.unmock('../../src/config/default-config'); + jest.resetModules(); + + const prodEnvironment = 'production'; + process.env.K8S_ENV = prodEnvironment; + process.env.CLUSTER_ENV = prodEnvironment; + process.env.AWS_DEFAULT_REGION = 'eu-west-1'; + process.env.AWS_ACCOUNT_ID = '160782110667'; const userPoolId = 'mockUserPoolId'; const accountId = 'mockAccountId';