forked from aws-samples/iam-identity-center-team
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameters.js
158 lines (123 loc) · 5.01 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// © 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, SSO_LOGIN, TEAM_ADMIN_GROUP, TEAM_AUDITOR_GROUP, TAGS, CLOUDTRAIL_AUDIT_LOGS, TEAM_ACCOUNT, AMPLIFY_CUSTOM_DOMAIN } = 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();
const amplifyDomain = AMPLIFY_CUSTOM_DOMAIN ? `https://${AMPLIFY_CUSTOM_DOMAIN}/` :`https://${AWS_BRANCH}.${AWS_APP_ID}.amplifyapp.com/`
console.log("domain",amplifyDomain)
oAuthMetadata.CallbackURLs.push(amplifyDomain);
oAuthMetadata.LogoutURLs.push(amplifyDomain);
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;
console.log("Team Account param:");
console.log(TEAM_ACCOUNT);
if (TEAM_ACCOUNT === undefined) {
reactParametersJson.DeploymentType = "management"
} else {
reactParametersJson.DeploymentType = "delegated"
};
reactParametersJson.teamAdminGroup = TEAM_ADMIN_GROUP;
reactParametersJson.teamAuditorGroup = TEAM_AUDITOR_GROUP;
fs.writeFileSync(
reactParametersJsonPath,
JSON.stringify(reactParametersJson, null, 4)
);
}
async function update_groups_parameters() {
console.log(`updating team06dbb7fcPreTokenGeneration lambda parameters"...`);
const groupsParametersJsonPath = path.resolve(
`./amplify/backend/function/team06dbb7fcPreTokenGeneration/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_router_parameters() {
console.log(`updating teamRouter lambda parameters"...`);
const routerParametersJsonPath = path.resolve(
`./amplify/backend/function/teamRouter/parameters.json`
);
const routerParametersJson = require(routerParametersJsonPath);
routerParametersJson.SSOLoginUrl = SSO_LOGIN;
fs.writeFileSync(
routerParametersJsonPath,
JSON.stringify(routerParametersJson, 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)
);
}
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_auth_parameters();
update_react_parameters();
update_groups_parameters();
update_router_parameters()
update_tag_parameters();
update_cloudtrail_parameters();