Skip to content

Commit

Permalink
Merge pull request #409 from hms-dbmi-cellenics/change-admin-sub
Browse files Browse the repository at this point in the history
make admin sub account agnostic
  • Loading branch information
alexvpickering authored Aug 29, 2022
2 parents 8a11ae7 + 094de29 commit 6b84c0f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/api.v2/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -47,4 +53,5 @@ module.exports = {
ASSIGN_POD_TO_PIPELINE,
EXPIRED_EXECUTION_DATE,
ACCOUNT_ID,
ADMIN_SUB,
};
4 changes: 2 additions & 2 deletions src/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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`;
Expand Down
32 changes: 30 additions & 2 deletions tests/config/__snapshots__/default-config-production.test.js.snap
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
}
`;
39 changes: 38 additions & 1 deletion tests/config/default-config-production.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 6b84c0f

Please sign in to comment.