Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BIOMAGE-1934] Remove account specific hardcodings in the UI code #748

Merged
merged 28 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
25f15c6
Merge branch 'master' of https://github.com/hms-dbmi-cellenics/ui
StefanBabukov Jun 13, 2022
729099d
Merge branch 'master' of https://github.com/hms-dbmi-cellenics/ui
StefanBabukov Jun 23, 2022
90d0257
remove hardcoded api endpoint and aws region
StefanBabukov Jun 23, 2022
1bcd5a3
fixes
StefanBabukov Jun 27, 2022
2bda7d7
trying to get account id dynamically
StefanBabukov Jun 27, 2022
e055a70
fix
StefanBabukov Jun 27, 2022
0677a60
fixing tests and trying
StefanBabukov Jun 28, 2022
aa7e6d2
Merge branch 'master' of https://github.com/hms-dbmi-cellenics/ui
StefanBabukov Jun 28, 2022
1de0b8e
merge confs and disabling a test temporarily
StefanBabukov Jun 28, 2022
3097bed
testing
StefanBabukov Jun 29, 2022
1f22573
Merge branch 'master' of https://github.com/hms-dbmi-cellenics/ui
StefanBabukov Jun 29, 2022
4879b2f
merge conf
StefanBabukov Jun 29, 2022
249d287
disable tests temporarily for testing
StefanBabukov Jun 29, 2022
87430a6
change
StefanBabukov Jun 29, 2022
9be6cca
change
StefanBabukov Jun 29, 2022
4068da2
testing aggain
StefanBabukov Jun 29, 2022
243f29e
dont need the storage config for amplify
StefanBabukov Jun 29, 2022
b753ceb
fix
StefanBabukov Jun 29, 2022
ec27c7f
fix
StefanBabukov Jun 29, 2022
c1be61c
Merge branch 'master' of https://github.com/hms-dbmi-cellenics/ui
StefanBabukov Jul 6, 2022
0b4455b
merge conflicts resolve
StefanBabukov Jul 6, 2022
d496ea1
testing if env variables are defined
StefanBabukov Jul 6, 2022
2ce64e1
getting region and test
StefanBabukov Jul 6, 2022
6109d2c
adding next config and testing if it works fine
StefanBabukov Jul 6, 2022
ad558fa
next config is not availablwe during tests
StefanBabukov Jul 6, 2022
9ed6140
working finally
StefanBabukov Jul 6, 2022
e15de09
export only needed public runtime config
StefanBabukov Jul 6, 2022
05eaedf
fix
StefanBabukov Jul 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ module.exports = withPlugins([
},
}],
[css],
{
publicRuntimeConfig: {
domainName: process.env.DOMAIN_NAME,
},
},
], nextConfig);
15 changes: 0 additions & 15 deletions src/__test__/utils/getAccountId.test.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/data-management/SamplesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import { arrayMoveImmutable } from 'utils/array-move';

import { metadataNameToKey, metadataKeyToName, temporaryMetadataKey } from 'utils/data-management/metadataUtils';
import integrationTestConstants from 'utils/integrationTestConstants';

import 'utils/css/data-management.css';

import { ClipLoader } from 'react-spinners';
import useConditionalEffect from 'utils/customHooks/useConditionalEffect';
import { METADATA_DEFAULT_VALUE } from 'redux/reducers/experiments/initialState';
Expand Down
24 changes: 3 additions & 21 deletions src/utils/amplify-config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
import Environment, { ssrGetCurrentEnvironment } from './environment';
import getAccountId from './getAccountId';
import getAWSRegion from './getAWSRegion';

const configure = (userPoolId, identityPoolId, userPoolClientDetails) => {
const currentEnvironment = ssrGetCurrentEnvironment();
const accountId = getAccountId(currentEnvironment);
const bucketName = `biomage-originals-${currentEnvironment}-${accountId}`;

const storageConfig = {
Storage: {
AWSS3: {
bucket: bucketName,
region: 'eu-west-1',
dangerouslyConnectToHttpEndpointForTesting: currentEnvironment === Environment.DEVELOPMENT,
identityId: identityPoolId,
customPrefix: {
public: '',
},
},
},
};
const redirectProtocol = (process.env.NODE_ENV === 'development') ? 'http:' : 'https:';
const usingProtocol = (url) => url.startsWith(redirectProtocol);
const signInRedirect = userPoolClientDetails.CallbackURLs.filter(usingProtocol)[0];
const signOutRedirect = userPoolClientDetails.LogoutURLs.filter(usingProtocol)[0];

const authConfig = {
Auth: {
region: 'eu-west-1',
region: getAWSRegion(),
identityPoolId,
userPoolId,
userPoolWebClientId: userPoolClientDetails.ClientId,
Expand All @@ -45,7 +27,7 @@ const configure = (userPoolId, identityPoolId, userPoolClientDetails) => {
};

return (
{ ...authConfig, ...storageConfig }
{ ...authConfig }
);
};

Expand Down
6 changes: 4 additions & 2 deletions src/utils/apiEndpoint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import nextConfig from 'next/config';

const getApiEndpoint = (location) => {
try {
const url = new URL(location || window.location.href);
Expand All @@ -9,8 +11,8 @@ const getApiEndpoint = (location) => {
if (url.hostname.includes('localhost') || url.hostname.includes('127.0.0.1')) {
return 'http://localhost:3000';
}

return 'https://api.scp.biomage.net';
const domainName = nextConfig()?.publicRuntimeConfig?.domainName;
return `https://api.${domainName}`;
} catch (error) {
console.error('Failed to get API endpoint.');
console.error(error);
Expand Down
17 changes: 17 additions & 0 deletions src/utils/getAWSRegion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const getAWSRegion = () => {
StefanBabukov marked this conversation as resolved.
Show resolved Hide resolved
// only works in ssr, where process.env is available

if (process.env.NODE_ENV === 'development') {
return 'eu-west-1';
}

const { AWS_REGION, AWS_DEFAULT_REGION } = process.env;

if (!AWS_REGION && !AWS_DEFAULT_REGION) {
throw new Error('AWS_REGION or DEFAULT_REGION must be set in the environment.');
}

return AWS_REGION || AWS_DEFAULT_REGION;
};

export default getAWSRegion;
11 changes: 0 additions & 11 deletions src/utils/getAccountId.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/utils/ssr/getAuthenticationInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@aws-sdk/client-cognito-identity-provider';
import { getDefaultRoleAssumerWithWebIdentity } from '@aws-sdk/client-sts';
import { fromTokenFile } from '@aws-sdk/credential-provider-web-identity';
import getAWSRegion from 'utils/getAWSRegion';
import configure from '../amplify-config';

const getAuthenticationInfo = async () => {
Expand All @@ -19,7 +20,6 @@ const getAuthenticationInfo = async () => {
if (global.cachedAuthenticationInfo) {
return global.cachedAuthenticationInfo;
}

let additionalClientParams = {};

if (process.env.NODE_ENV !== 'development') {
Expand All @@ -33,14 +33,14 @@ const getAuthenticationInfo = async () => {

const identityPoolClient = new CognitoIdentityClient(
{
region: 'eu-west-1',
region: getAWSRegion(),
...additionalClientParams,
},
);

const userPoolClient = new CognitoIdentityProviderClient(
{
region: 'eu-west-1',
region: getAWSRegion(),
...additionalClientParams,
},
);
Expand Down Expand Up @@ -91,7 +91,7 @@ const getAuthenticationInfo = async () => {
const amplifyConfig = configure(
userPoolId,
identityPoolId,
{ ...userPoolClientDetails, Domain: `${Domain}.auth.eu-west-1.amazoncognito.com` },
{ ...userPoolClientDetails, Domain: `${Domain}.auth.${getAWSRegion()}.amazoncognito.com` },
);

const result = {
Expand Down