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 3 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: 3 additions & 2 deletions src/utils/amplify-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Environment, { ssrGetCurrentEnvironment } from './environment';
import getAccountId from './getAccountId';
import { getAWSRegion } from './awsConfig';

const configure = (userPoolId, identityPoolId, userPoolClientDetails) => {
const currentEnvironment = ssrGetCurrentEnvironment();
Expand All @@ -10,7 +11,7 @@ const configure = (userPoolId, identityPoolId, userPoolClientDetails) => {
Storage: {
AWSS3: {
bucket: bucketName,
region: 'eu-west-1',
region: getAWSRegion(),
dangerouslyConnectToHttpEndpointForTesting: currentEnvironment === Environment.DEVELOPMENT,
identityId: identityPoolId,
customPrefix: {
Expand All @@ -26,7 +27,7 @@ const configure = (userPoolId, identityPoolId, userPoolClientDetails) => {

const authConfig = {
Auth: {
region: 'eu-west-1',
region: getAWSRegion(),
identityPoolId,
userPoolId,
userPoolWebClientId: userPoolClientDetails.ClientId,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/apiEndpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getApiEndpoint = (location) => {
return 'http://localhost:3000';
}

return 'https://api.scp.biomage.net';
return process.env.API_ENDPOINT_PRODUCTION || 'https://api.scp.biomage.net';
StefanBabukov marked this conversation as resolved.
Show resolved Hide resolved
StefanBabukov marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
console.error('Failed to get API endpoint.');
console.error(error);
Expand Down
16 changes: 16 additions & 0 deletions src/utils/awsConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const getAccountId = (environment) => {
let accountID;
if (environment === 'development') {
accountID = '000000000000';
} else {
accountID = '242905224710';
}
StefanBabukov marked this conversation as resolved.
Show resolved Hide resolved
return accountID;
};

const getAWSRegion = () => {
const region = process.env.AWS_REGION || process.env.DEFAULT_REGION || 'eu-west-1';
return region;
};

export { getAccountId, getAWSRegion };
StefanBabukov marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 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/awsConfig';
import configure from '../amplify-config';

const getAuthenticationInfo = async () => {
Expand All @@ -33,14 +34,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 +92,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