This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
forked from aws-samples/iam-identity-center-team
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameters.js
132 lines (105 loc) · 4.07 KB
/
parameters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// © 2021 Amazon Web Services, Inc. or its affiliates. All Rights Reserved.
// This AWS Content is provided subject to the terms of the AWS Customer Agreement available at
// http://aws.amazon.com/agreement or other written agreement between Customer and either
// Amazon Web Services, Inc. or Amazon Web Services EMEA SARL or both.
const fs = require("fs");
const path = require("path");
const { AWS_APP_ID, AWS_BRANCH, EMAIL_SOURCE, SSO_LOGIN, TEAM_ADMIN_GROUP, TEAM_AUDITOR_GROUP, TAGS, CLOUDTRAIL_AUDIT_LOGS } = process.env;
async function update_auth_parameters() {
console.log(`updating amplify config for branch "${AWS_BRANCH}"...`);
// update callback/logout redirect urls for build url
const backendConfig = require(path.resolve(
"./amplify/backend/backend-config.json"
));
const authResourceName = Object.keys(backendConfig.auth)[0];
const authParametersJsonPath = path.resolve(
`./amplify/backend/auth/${authResourceName}/cli-inputs.json`
);
const authParametersJson = require(authParametersJsonPath);
const oAuthMetadata = JSON.parse(
authParametersJson.cognitoConfig.oAuthMetadata
);
oAuthMetadata.CallbackURLs.pop();
oAuthMetadata.LogoutURLs.pop();
oAuthMetadata.CallbackURLs.push(
`https://${AWS_BRANCH}.${AWS_APP_ID}.amplifyapp.com/`
);
oAuthMetadata.LogoutURLs.push(
`https://${AWS_BRANCH}.${AWS_APP_ID}.amplifyapp.com/`
);
authParametersJson.cognitoConfig.oAuthMetadata =
JSON.stringify(oAuthMetadata);
authParametersJson.cognitoConfig.hostedUIDomainName = AWS_APP_ID;
fs.writeFileSync(
authParametersJsonPath,
JSON.stringify(authParametersJson, null, 4)
);
}
async function update_react_parameters() {
console.log(`updating react parameters"...`);
const reactParametersJsonPath = path.resolve(`./src/parameters.json`);
const reactParametersJson = require(reactParametersJsonPath);
reactParametersJson.Login = SSO_LOGIN;
fs.writeFileSync(
reactParametersJsonPath,
JSON.stringify(reactParametersJson, null, 4)
);
}
async function update_custom_parameters() {
console.log(`updating stepfunctions custom parameters"...`);
const customParametersJsonPath = path.resolve(
`./amplify/backend/custom/stepfunctions/parameters.json`
);
const customParametersJson = require(customParametersJsonPath);
customParametersJson.Source = EMAIL_SOURCE;
customParametersJson.Login = SSO_LOGIN;
fs.writeFileSync(
customParametersJsonPath,
JSON.stringify(customParametersJson, null, 4)
);
}
async function update_groups_parameters() {
console.log(`updating teamgetgroups lambda parameters"...`);
const groupsParametersJsonPath = path.resolve(
`./amplify/backend/function/teamgetGroups/parameters.json`
);
const groupsParametersJson = require(groupsParametersJsonPath);
groupsParametersJson.teamAdminGroup = TEAM_ADMIN_GROUP;
groupsParametersJson.teamAuditorGroup = TEAM_AUDITOR_GROUP;
fs.writeFileSync(
groupsParametersJsonPath,
JSON.stringify(groupsParametersJson, null, 4)
);
}
async function update_tag_parameters() {
console.log(`updating amplify/backend/tags.json"...`);
const tagsParametersJsonPath = path.resolve(
`./amplify/backend/tags.json`
);
const tagsArray = TAGS ? TAGS.split(' ').map((tag) => {
const [key, value] = tag.split('=');
return {
Key: key,
Value: value,
};
}) : [];
fs.writeFileSync(tagsParametersJsonPath, JSON.stringify(tagsArray, null, 2));
}
async function update_cloudtrail_parameters() {
console.log(`updating amplify/backend/custom/cloudtrailLake/parameters.json"...`);
const cloudtrailParametersJsonPath = path.resolve(
`./amplify/backend/custom/cloudtrailLake/parameters.json`
);
const cloudtrailParametersJson = require(cloudtrailParametersJsonPath);
cloudtrailParametersJson.CloudTrailAuditLogs = CLOUDTRAIL_AUDIT_LOGS;
fs.writeFileSync(
cloudtrailParametersJsonPath,
JSON.stringify(cloudtrailParametersJson, null, 4)
);
}
update_custom_parameters();
update_auth_parameters();
update_react_parameters();
update_groups_parameters();
update_tag_parameters();
update_cloudtrail_parameters();