diff --git a/src/api.v2/constants.js b/src/api.v2/constants.js index 66fcde157..caa1f5881 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 = { + [ACCOUNT_ID.BIOMAGE]: '032abd44-0cd3-4d58-af21-850ca0b95ac7', + [ACCOUNT_ID.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..a207f5f71 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 { ADMIN_SUB } = require('../api.v2/constants'); const githubOrganisationName = 'hms-dbmi-cellenics'; @@ -78,10 +79,9 @@ 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: 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';