@docupace/pipeline 1.0.24 → 1.0.26-alpha-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.cjs +12 -12
- package/bin/next-changeset-validate.sh +8 -8
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +117 -117
- package/next/sonar.sh +23 -23
- package/package.json +1 -2
- package/src/auth0/alias.js +72 -75
- package/src/auth0/cli.js +56 -41
- package/src/auth0/configure.js +227 -448
- package/src/auth0/vault.js +3 -3
- package/src/changeset/cli.js +281 -281
- package/src/changeset/validate.js +47 -47
- package/src/jenkins/setParams.groovy +59 -59
- package/src/next/alias.js +53 -53
- package/src/next/apache.js +40 -40
- package/src/next/cli.js +21 -33
- package/src/next/connect.js +162 -155
- package/src/next/copy.js +0 -22
- package/src/next/deploy.js +43 -204
- package/src/next/jenkins.js +0 -1
- package/src/next/pipline.js +1 -0
- package/src/next/publish.js +48 -48
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/src/next/vault.js +43 -43
- package/terraform/apply.sh +26 -26
- package/terraform/init.sh +60 -48
- package/terraform/plan.sh +61 -54
- package/terraform/validate.sh +17 -17
package/src/auth0/configure.js
CHANGED
|
@@ -2,27 +2,16 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
|
-
import { deploy } from 'auth0-deploy-cli';
|
|
6
5
|
import fl from 'fs/promises';
|
|
7
6
|
|
|
8
7
|
import {
|
|
9
8
|
cloneEnvRepository,
|
|
10
|
-
cloneRepository,
|
|
11
9
|
readDeployConfig,
|
|
12
|
-
pushDeployConfig
|
|
10
|
+
pushDeployConfig,
|
|
13
11
|
} from '../next/deploy.js';
|
|
14
12
|
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
updateVaultSecrets
|
|
18
|
-
} from './vault.js';
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
getVaultSecretsConfigs,
|
|
22
|
-
environmentConfig
|
|
23
|
-
} from '../next/config.js';
|
|
24
|
-
import { connect } from 'http2';
|
|
25
|
-
import { promise } from 'zod';
|
|
13
|
+
import { getVaultSecrets, updateVaultSecrets } from './vault.js';
|
|
14
|
+
import { getVaultSecretsConfigs, environmentConfig } from '../next/config.js';
|
|
26
15
|
|
|
27
16
|
async function ensureDirectoryExists(dirPath) {
|
|
28
17
|
try {
|
|
@@ -33,359 +22,77 @@ async function ensureDirectoryExists(dirPath) {
|
|
|
33
22
|
}
|
|
34
23
|
}
|
|
35
24
|
|
|
36
|
-
async function
|
|
37
|
-
try {
|
|
38
|
-
await fl.mkdir(destination, { recursive: true });
|
|
39
|
-
const items = await fl.readdir(source, { withFileTypes: true });
|
|
40
|
-
|
|
41
|
-
for (const item of items) {
|
|
42
|
-
const sourcePath = path.join(source, item.name);
|
|
43
|
-
const destinationPath = path.join(destination, item.name);
|
|
44
|
-
|
|
45
|
-
if (item.isDirectory()) {
|
|
46
|
-
await copyDirectory(sourcePath, destinationPath);
|
|
47
|
-
} else {
|
|
48
|
-
await fl.copyFile(sourcePath, destinationPath);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
console.error(`Error copying directory: ${err.message}`);
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function addApplicationToApi ({application, auth0Domain, auth0AuthToken, coreApiIdentifier}){
|
|
58
|
-
console.log("Adding application to API authorized applications...");
|
|
59
|
-
|
|
25
|
+
export async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
|
|
60
26
|
try {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const appAuth0ClientIdData = auth0Response.data.find(client => client.name === `${application}`);
|
|
66
|
-
const appAuth0ClientId = appAuth0ClientIdData.client_id;
|
|
67
|
-
|
|
68
|
-
await axios.post(
|
|
69
|
-
`https://${auth0Domain}/api/v2/client-grants`,
|
|
27
|
+
const response = await axios.post(
|
|
28
|
+
`https://${auth0Domain}/oauth/token`,
|
|
70
29
|
{
|
|
71
|
-
client_id:
|
|
72
|
-
|
|
73
|
-
|
|
30
|
+
client_id: clientId,
|
|
31
|
+
client_secret: clientSecret,
|
|
32
|
+
audience: `https://${auth0Domain}/api/v2/`,
|
|
33
|
+
grant_type: 'client_credentials',
|
|
74
34
|
},
|
|
75
35
|
{
|
|
76
36
|
headers: {
|
|
77
|
-
|
|
78
|
-
"Content-Type": "application/json",
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
console.log(`Application (${appAuth0ClientId}) authorized for API: ${coreApiIdentifier}`);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
console.error(`Failed to add application: ${application}: ${err.message}`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function initializeAuth0Configuration({
|
|
90
|
-
initConfiguration,
|
|
91
|
-
auth0Domain,
|
|
92
|
-
auth0AuthToken,
|
|
93
|
-
coreApiIdentifier,
|
|
94
|
-
}) {
|
|
95
|
-
if (initConfiguration === "true") {
|
|
96
|
-
try {
|
|
97
|
-
// Create a new resource server in Auth0
|
|
98
|
-
console.log("Creating resource server in Auth0...");
|
|
99
|
-
|
|
100
|
-
const resourceServerResponse = await axios.post(
|
|
101
|
-
`https://${auth0Domain}/api/v2/resource-servers`,
|
|
102
|
-
{
|
|
103
|
-
name: "docupace-core",
|
|
104
|
-
identifier: `${coreApiIdentifier}`,
|
|
105
|
-
token_lifetime: 86400,
|
|
106
|
-
allow_offline_access: false,
|
|
107
|
-
signing_alg: "RS256",
|
|
108
|
-
skip_consent_for_verifiable_first_party_clients: true,
|
|
109
|
-
scopes: [],
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
headers: {
|
|
113
|
-
Authorization: `Bearer ${auth0AuthToken}`,
|
|
114
|
-
"Content-Type": "application/json",
|
|
115
|
-
},
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const apiId = resourceServerResponse.data.id;
|
|
120
|
-
|
|
121
|
-
// Update tenant settings with the default audience
|
|
122
|
-
console.log("Updating tenant settings...");
|
|
123
|
-
await axios.patch(
|
|
124
|
-
`https://${auth0Domain}/api/v2/tenants/settings`,
|
|
125
|
-
{
|
|
126
|
-
default_audience: `${coreApiIdentifier}`,
|
|
37
|
+
'Content-Type': 'application/json',
|
|
127
38
|
},
|
|
128
|
-
{
|
|
129
|
-
headers: {
|
|
130
|
-
Authorization: `Bearer ${auth0AuthToken}`,
|
|
131
|
-
"Content-Type": "application/json",
|
|
132
|
-
},
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
console.log("Tenant settings updated successfully.");
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.error("Error during Auth0 configuration:", error.response?.data || error.message);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async function importAuth0Templates(directoryPath, auth0Domain, auth0ClientID, auth0ClientSecret) {
|
|
143
|
-
try {
|
|
144
|
-
const config = {
|
|
145
|
-
input_file: directoryPath,
|
|
146
|
-
config: {
|
|
147
|
-
AUTH0_DOMAIN: auth0Domain,
|
|
148
|
-
AUTH0_CLIENT_ID: auth0ClientID,
|
|
149
|
-
AUTH0_CLIENT_SECRET: auth0ClientSecret,
|
|
150
39
|
},
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
console.log('Starting Auth0 template import...');
|
|
155
|
-
await deploy(config);
|
|
156
|
-
console.log('Auth0 template import completed successfully!');
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error('Error during Auth0 template import:', error.message);
|
|
159
|
-
process.exit(1); // Exit with an error code
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async function updateJsonFile(filePath, updates) {
|
|
164
|
-
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
165
|
-
const jsonContent = JSON.parse(content);
|
|
166
|
-
const updatedContent = JSON.stringify({...jsonContent, ...updates}, null, 2);
|
|
167
|
-
await fs.promises.writeFile(filePath, updatedContent);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function replaceInFile(filePath, replacements) {
|
|
171
|
-
let content = await fs.promises.readFile(filePath, 'utf8');
|
|
172
|
-
|
|
173
|
-
for (const [search, replace] of replacements) {
|
|
174
|
-
const escapedSearch = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); // Escape special chars
|
|
175
|
-
content = content.replace(new RegExp(escapedSearch, 'g'), replace);
|
|
176
|
-
}
|
|
177
|
-
await fs.promises.writeFile(filePath, content, 'utf8');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA) {
|
|
181
|
-
try {
|
|
182
|
-
let uiAllowedCallbacksUrls,
|
|
183
|
-
uiAllowedLogoutUrls;
|
|
184
|
-
let graphqlAllowedCallbacksUrls,
|
|
185
|
-
graphqlAllowedLogoutUrls;
|
|
186
|
-
let connectAllowedCallbacksUrls,
|
|
187
|
-
connectlAllowedLogoutUrls;
|
|
188
|
-
|
|
189
|
-
let connectClientMetadata,
|
|
190
|
-
connectCallbacks,
|
|
191
|
-
connectAddons;
|
|
192
|
-
// Configure URLs based on environment
|
|
193
|
-
if (env === 'prd') {
|
|
194
|
-
uiAllowedCallbacksUrls = [`${siteUrl}/api/auth/callback`];
|
|
195
|
-
uiAllowedLogoutUrls = [`${siteUrl}`];
|
|
196
|
-
|
|
197
|
-
graphqlAllowedCallbacksUrls = [`${siteUrl}/api/graphql/callback`];
|
|
198
|
-
graphqlAllowedLogoutUrls = [`${siteUrl}/api/graphql/`];
|
|
199
|
-
|
|
200
|
-
connectAllowedCallbacksUrls = [`${siteUrl}/connect/samlCallback?client_name=auth0`];
|
|
201
|
-
connectlAllowedLogoutUrls = [ `${siteUrl}/connect`];
|
|
202
|
-
} else {
|
|
203
|
-
uiAllowedCallbacksUrls = [
|
|
204
|
-
`${siteUrl}/api/auth/callback`,
|
|
205
|
-
`http://localhost:3000/api/auth/callback`,
|
|
206
|
-
];
|
|
207
|
-
uiAllowedLogoutUrls = [
|
|
208
|
-
`${siteUrl}`,
|
|
209
|
-
`http://localhost:3000`,
|
|
210
|
-
];
|
|
211
|
-
graphqlAllowedCallbacksUrls = [
|
|
212
|
-
`${siteUrl}/api/graphql/callback`,
|
|
213
|
-
`http://localhost:4000/api/graphql/callback`,
|
|
214
|
-
];
|
|
215
|
-
graphqlAllowedLogoutUrls = [
|
|
216
|
-
`http://localhost:4000/api/graphql/`,
|
|
217
|
-
`${siteUrl}/api/graphql/`,
|
|
218
|
-
];
|
|
219
|
-
connectAllowedCallbacksUrls = [
|
|
220
|
-
`${siteUrl}/connect/samlCallback?client_name=auth0`,
|
|
221
|
-
`http://localhost:9000/connect/samlCallback?client_name=auth0`,
|
|
222
|
-
];
|
|
223
|
-
connectlAllowedLogoutUrls = [
|
|
224
|
-
`${siteUrl}/connect`
|
|
225
|
-
];
|
|
226
|
-
|
|
227
|
-
const siteUrlNoPrefix=siteUrl.replace(/^https?:\/\//, '');
|
|
228
|
-
connectClientMetadata ={
|
|
229
|
-
"docupaceContext" : "core",
|
|
230
|
-
"docupaceHost" : `${siteUrlNoPrefix}`,
|
|
231
|
-
"docupace_context" : "core",
|
|
232
|
-
"docupace_host" : `${siteUrlNoPrefix} `
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
connectCallbacks = [
|
|
236
|
-
`${siteUrl}/connect/samlCallback?client_name=auth0`
|
|
237
|
-
];
|
|
238
|
-
|
|
239
|
-
connectAddons = {
|
|
240
|
-
"samlp": {
|
|
241
|
-
"audience": `${siteUrl}/connect`,
|
|
242
|
-
"recipient": `${siteUrl}/connect/samlCallback?client_name=auth0`,
|
|
243
|
-
"destination": `${siteUrl}/connect/samlCallback?client_name=auth0`,
|
|
244
|
-
"nameIdentifierFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
|
|
245
|
-
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
|
|
246
|
-
"nameIdentifierProbes": [
|
|
247
|
-
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/docupace-username"
|
|
248
|
-
],
|
|
249
|
-
"mappings": {
|
|
250
|
-
"proposalHandle": "ProposalHandle"
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const configureUI = deployUI === 'true';
|
|
259
|
-
if (configureUI) {
|
|
260
|
-
console.log('ui_allowed_callbacks_urls ->', uiAllowedCallbacksUrls);
|
|
261
|
-
console.log('ui_allowed_logout_urls ->', uiAllowedLogoutUrls);
|
|
262
|
-
|
|
263
|
-
await updateJsonFile(filePaths.uiJson, {
|
|
264
|
-
callbacks: uiAllowedCallbacksUrls,
|
|
265
|
-
allowed_logout_urls: uiAllowedLogoutUrls,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
//TODO: move to separate function for connect
|
|
270
|
-
console.log('connect_allowed_callbacks_urls ->', connectAllowedCallbacksUrls);
|
|
271
|
-
console.log('connect_allowed_logout_urls ->', connectlAllowedLogoutUrls);
|
|
272
|
-
|
|
273
|
-
// update allowed callback url
|
|
274
|
-
await updateJsonFile(filePaths.connectJson, {
|
|
275
|
-
callbacks: connectAllowedCallbacksUrls,
|
|
276
|
-
allowed_logout_urls: connectlAllowedLogoutUrls,
|
|
277
|
-
client_metadata: connectClientMetadata,
|
|
278
|
-
addons: connectAddons
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
console.log('Updated URLs for main UI...');
|
|
284
|
-
} else {
|
|
285
|
-
await fs.promises.unlink(filePaths.uiJson);
|
|
286
|
-
await updateJsonFile(filePaths.databaseJson, {
|
|
287
|
-
enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-ui-main'),
|
|
288
|
-
});
|
|
289
|
-
console.log("Removed 'docupace-ui-main' from enabled_clients in database.json");
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const configureGraphqlServer = deployGraphQLServer === 'true';
|
|
293
|
-
if (configureGraphqlServer) {
|
|
294
|
-
console.log('graphql_allowed_callbacks_urls ->', graphqlAllowedCallbacksUrls);
|
|
295
|
-
console.log('graphql_allowed_logout_urls ->', graphqlAllowedLogoutUrls);
|
|
296
|
-
|
|
297
|
-
await updateJsonFile(filePaths.graphqlJson, {
|
|
298
|
-
callbacks: graphqlAllowedCallbacksUrls,
|
|
299
|
-
allowed_logout_urls: graphqlAllowedLogoutUrls,
|
|
300
|
-
});
|
|
301
|
-
console.log('Updated URLs for GraphQL server...');
|
|
302
|
-
} else {
|
|
303
|
-
await fs.promises.unlink(filePaths.graphqlJson);
|
|
304
|
-
await updateJsonFile(filePaths.databaseJson, {
|
|
305
|
-
enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-graphql'),
|
|
306
|
-
});
|
|
307
|
-
console.log("Removed 'docupace-graphql' from enabled_clients in database.json");
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// TWILIO configuration
|
|
311
|
-
await replaceInFile(filePaths.twilioJson, [
|
|
312
|
-
['twilioauthtokenplaceholder', commonSecrets.TWILIO_AUTH_TOKEN],
|
|
313
|
-
['twiliosidplaceholder', commonSecrets.TWILIO_SID],
|
|
314
|
-
['twiliofromplaceholder', commonSecrets.TWILIO_FROM_NUMBER],
|
|
315
|
-
]);
|
|
316
|
-
|
|
317
|
-
console.log('TWILIO configuration updated...');
|
|
318
|
-
|
|
319
|
-
const tmpSiteUrl = siteUrl.replace(/^https?:\/\//, '');
|
|
320
|
-
// Database configuration
|
|
321
|
-
await replaceInFile(filePaths.databaseLoginJs, [
|
|
322
|
-
['${docupaceHost}', tmpSiteUrl],
|
|
323
|
-
['${docupaceContext}', coreApiContext],
|
|
324
|
-
]);
|
|
325
|
-
|
|
326
|
-
console.log('MFA Template configuration started...');
|
|
327
|
-
|
|
328
|
-
try {
|
|
329
|
-
const sourceDir = configureMFA === 'DISABLED' ? 'auth0-site-setup/templateNoMFA/' : 'auth0-site-setup/templateMFA/';
|
|
330
|
-
const destinationDir = 'auth0-site-setup/template/';
|
|
331
|
-
|
|
332
|
-
console.log(`AUTH0 MFA is ${configureMFA === 'DISABLED' ? 'disabled' : 'enabled'}`);
|
|
333
|
-
await copyDirectory(sourceDir, destinationDir);
|
|
334
|
-
|
|
335
|
-
console.log('MFA configuration completed.');
|
|
336
|
-
} catch (err) {
|
|
337
|
-
console.error('Error configuring MFA:', err);
|
|
338
|
-
throw err;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
console.log('Template configuration completed.');
|
|
342
|
-
} catch (err) {
|
|
343
|
-
// console.error('Error configuring Auth0 templates:', err);
|
|
344
|
-
throw err;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
|
|
349
|
-
try {
|
|
350
|
-
const response = await axios.post(`https://${auth0Domain}/oauth/token`, {
|
|
351
|
-
client_id: clientId,
|
|
352
|
-
client_secret: clientSecret,
|
|
353
|
-
audience: `https://${auth0Domain}/api/v2/`,
|
|
354
|
-
grant_type: 'client_credentials',
|
|
355
|
-
}, {
|
|
356
|
-
headers: {
|
|
357
|
-
'Content-Type': 'application/json',
|
|
358
|
-
},
|
|
359
|
-
});
|
|
40
|
+
);
|
|
360
41
|
|
|
361
42
|
const authToken = response.data.access_token;
|
|
362
43
|
// console.log("Auth0 Auth Token:", authToken);
|
|
363
44
|
return authToken;
|
|
364
45
|
} catch (error) {
|
|
365
|
-
console.error(
|
|
46
|
+
console.error(
|
|
47
|
+
'Error fetching Auth0 token:',
|
|
48
|
+
error.response ? error.response.data : error.message,
|
|
49
|
+
);
|
|
366
50
|
}
|
|
367
51
|
}
|
|
368
52
|
|
|
369
|
-
async function configureUI(
|
|
370
|
-
|
|
53
|
+
async function configureUI(
|
|
54
|
+
siteHost,
|
|
55
|
+
coreURL,
|
|
56
|
+
docupaceHost,
|
|
57
|
+
site,
|
|
58
|
+
env,
|
|
59
|
+
useNewDomain,
|
|
60
|
+
auth0Domain,
|
|
61
|
+
auth0ClientId,
|
|
62
|
+
auth0ClientSecret,
|
|
63
|
+
auth0Token,
|
|
64
|
+
vaultSiteSecretsPath,
|
|
65
|
+
imageTag,
|
|
66
|
+
repoPath,
|
|
67
|
+
) {
|
|
68
|
+
console.log(
|
|
69
|
+
`Configuring UI for site: ${site} Host: ${siteHost} in env: ${env}`,
|
|
70
|
+
);
|
|
371
71
|
siteHost = siteHost.replace('https://', '');
|
|
372
72
|
coreURL = coreURL.replace('https://', '');
|
|
373
73
|
|
|
374
|
-
|
|
375
74
|
try {
|
|
376
|
-
const auth0Response = await axios.get(
|
|
377
|
-
|
|
378
|
-
|
|
75
|
+
const auth0Response = await axios.get(
|
|
76
|
+
`https://${auth0Domain}/api/v2/clients`,
|
|
77
|
+
{
|
|
78
|
+
headers: { authorization: `Bearer ${auth0Token}` },
|
|
79
|
+
},
|
|
80
|
+
);
|
|
379
81
|
|
|
380
|
-
const uiClient = auth0Response.data.find(
|
|
82
|
+
const uiClient = auth0Response.data.find(
|
|
83
|
+
(client) => client.name === 'docupace-ui-main',
|
|
84
|
+
);
|
|
381
85
|
const uiAuth0ClientId = uiClient.client_id;
|
|
382
86
|
const uiAuth0ClientSecret = uiClient.client_secret;
|
|
383
87
|
|
|
384
88
|
// Generate Auth0 Secret
|
|
385
|
-
const uiAuth0Secret = crypto
|
|
89
|
+
const uiAuth0Secret = crypto
|
|
90
|
+
.randomBytes(48)
|
|
91
|
+
.toString('base64')
|
|
92
|
+
.replace(/[^a-zA-Z0-9]/g, '');
|
|
386
93
|
|
|
387
94
|
// Prepare data payload
|
|
388
|
-
console.log(
|
|
95
|
+
console.log('Preparing Vault UI data payload...');
|
|
389
96
|
const uiSecretData = JSON.stringify({
|
|
390
97
|
data: {
|
|
391
98
|
AUTH0_CLIENT_ID: uiAuth0ClientId,
|
|
@@ -473,51 +180,85 @@ externalConnectService:
|
|
|
473
180
|
`.trim();
|
|
474
181
|
|
|
475
182
|
// Write configuration files
|
|
476
|
-
console.log(
|
|
183
|
+
console.log('Writing configuration files...');
|
|
477
184
|
await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
|
|
478
185
|
|
|
479
|
-
await fs.writeFile(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
186
|
+
await fs.writeFile(
|
|
187
|
+
`${repoPath}/dp/${site}/ui.app.yaml`,
|
|
188
|
+
uiAppYaml,
|
|
189
|
+
(err) => {
|
|
190
|
+
if (err) {
|
|
191
|
+
console.error('Failed to write the file:', err);
|
|
192
|
+
} else {
|
|
193
|
+
console.log('File written successfully.');
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
);
|
|
486
197
|
|
|
487
|
-
await fs.writeFile(
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
198
|
+
await fs.writeFile(
|
|
199
|
+
`${repoPath}/dp/${site}/ui.values.yaml`,
|
|
200
|
+
uiValuesYaml,
|
|
201
|
+
(err) => {
|
|
202
|
+
if (err) {
|
|
203
|
+
console.error('Failed to write the file:', err);
|
|
204
|
+
} else {
|
|
205
|
+
console.log('File written successfully.');
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
console.log('Done!');
|
|
495
210
|
} catch (error) {
|
|
496
|
-
console.error(
|
|
211
|
+
console.error('Error configuring UI:', error);
|
|
497
212
|
}
|
|
498
213
|
}
|
|
499
214
|
|
|
500
|
-
async function configureGraphQLServer(
|
|
215
|
+
async function configureGraphQLServer(
|
|
216
|
+
siteHost,
|
|
217
|
+
coreURL,
|
|
218
|
+
docupaceHost,
|
|
219
|
+
site,
|
|
220
|
+
env,
|
|
221
|
+
auth0Domain,
|
|
222
|
+
auth0ClientId,
|
|
223
|
+
auth0ClientSecret,
|
|
224
|
+
auth0Token,
|
|
225
|
+
vaultSiteSecretsPath,
|
|
226
|
+
imageTag,
|
|
227
|
+
standardConfigRemoteBranch,
|
|
228
|
+
repoPath,
|
|
229
|
+
commonSecrets,
|
|
230
|
+
) {
|
|
501
231
|
siteHost = siteHost.replace('https://', '');
|
|
502
232
|
coreURL = coreURL.replace('https://', '');
|
|
503
|
-
console.log(
|
|
233
|
+
console.log(
|
|
234
|
+
`Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`,
|
|
235
|
+
);
|
|
504
236
|
|
|
505
237
|
try {
|
|
506
|
-
const auth0Response = await axios.get(
|
|
507
|
-
|
|
508
|
-
|
|
238
|
+
const auth0Response = await axios.get(
|
|
239
|
+
`https://${auth0Domain}/api/v2/clients`,
|
|
240
|
+
{
|
|
241
|
+
headers: { authorization: `Bearer ${auth0Token}` },
|
|
242
|
+
},
|
|
243
|
+
);
|
|
509
244
|
|
|
510
|
-
const graphQLServerClient = auth0Response.data.find(
|
|
511
|
-
|
|
245
|
+
const graphQLServerClient = auth0Response.data.find(
|
|
246
|
+
(client) => client.name === 'docupace-graphql',
|
|
247
|
+
);
|
|
248
|
+
const graphQLServerClientCredentials = auth0Response.data.find(
|
|
249
|
+
(client) => client.name === 'docupace-graphql-client-credentials',
|
|
250
|
+
);
|
|
512
251
|
|
|
513
252
|
const graphQLServerAuth0ClientId = graphQLServerClient.client_id;
|
|
514
253
|
const graphQLServerAuth0ClientSecret = graphQLServerClient.client_secret;
|
|
515
254
|
|
|
516
|
-
const graphQLServerCCAuth0ClientId =
|
|
517
|
-
|
|
255
|
+
const graphQLServerCCAuth0ClientId =
|
|
256
|
+
graphQLServerClientCredentials.client_id;
|
|
257
|
+
const graphQLServerCCAuth0ClientSecret =
|
|
258
|
+
graphQLServerClientCredentials.client_secret;
|
|
518
259
|
|
|
519
260
|
// Prepare data payload
|
|
520
|
-
console.log(
|
|
261
|
+
console.log('Preparing Vault GraphQL Server data payload...');
|
|
521
262
|
const graphQLServerSecretData = JSON.stringify({
|
|
522
263
|
data: {
|
|
523
264
|
AUTH0_CLIENT_ID: graphQLServerAuth0ClientId,
|
|
@@ -580,105 +321,128 @@ ingress:
|
|
|
580
321
|
`.trim();
|
|
581
322
|
|
|
582
323
|
// Write configuration files
|
|
583
|
-
console.log(
|
|
324
|
+
console.log('Writing ArgoCD GraphQL Server configuration files...');
|
|
584
325
|
await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
|
|
585
326
|
|
|
586
|
-
await fs.writeFile(
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
327
|
+
await fs.writeFile(
|
|
328
|
+
`${repoPath}/dp/${site}/graphql-server.app.yaml`,
|
|
329
|
+
graphQLServerAppYaml,
|
|
330
|
+
(err) => {
|
|
331
|
+
if (err) {
|
|
332
|
+
console.error('Failed to write the file:', err);
|
|
333
|
+
} else {
|
|
334
|
+
console.log('File written successfully.');
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
);
|
|
593
338
|
|
|
594
|
-
await fs.writeFile(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
339
|
+
await fs.writeFile(
|
|
340
|
+
`${repoPath}/dp/${site}/graphql-server.values.yaml`,
|
|
341
|
+
graphQLServerValuesYaml,
|
|
342
|
+
(err) => {
|
|
343
|
+
if (err) {
|
|
344
|
+
console.error('Failed to write the file:', err);
|
|
345
|
+
} else {
|
|
346
|
+
console.log('File written successfully.');
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
);
|
|
350
|
+
console.log('Done!');
|
|
602
351
|
} catch (error) {
|
|
603
|
-
console.error(
|
|
352
|
+
console.error('Error configuring GraphQL Server:', error);
|
|
604
353
|
}
|
|
605
354
|
}
|
|
606
355
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
356
|
+
export async function configureFromSite(
|
|
357
|
+
fromSite,
|
|
358
|
+
toSite,
|
|
359
|
+
fromEnv,
|
|
360
|
+
toEnv,
|
|
361
|
+
deployUI,
|
|
362
|
+
deployGraphQLServer,
|
|
363
|
+
useNewDomain,
|
|
364
|
+
) {
|
|
365
|
+
console.log(
|
|
366
|
+
`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`,
|
|
367
|
+
);
|
|
610
368
|
// Common Secrets
|
|
611
369
|
const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
|
|
612
|
-
console.log(`commonSecretsPath => ${commonSecretsPath}`)
|
|
370
|
+
console.log(`commonSecretsPath => ${commonSecretsPath}`);
|
|
613
371
|
const commonSecrets = await getVaultSecrets(commonSecretsPath);
|
|
614
372
|
|
|
615
373
|
// Site Common Secrets
|
|
616
|
-
const siteCommonSecretsPath =
|
|
617
|
-
|
|
374
|
+
const siteCommonSecretsPath =
|
|
375
|
+
getVaultSecretsConfigs(toSite).siteCommonSecretsPath;
|
|
376
|
+
console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
|
|
618
377
|
const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
|
|
619
378
|
|
|
620
|
-
const auth0Domain = `docupace-${toEnv}-${toSite}.us.auth0.com
|
|
379
|
+
const auth0Domain = `docupace-${toEnv}-${toSite}.us.auth0.com`;
|
|
621
380
|
const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
|
|
622
381
|
const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
|
|
623
|
-
const auth0Token = await getAuth0AuthToken(
|
|
382
|
+
const auth0Token = await getAuth0AuthToken(
|
|
383
|
+
auth0Domain,
|
|
384
|
+
auth0ClientId,
|
|
385
|
+
auth0ClientSecret,
|
|
386
|
+
);
|
|
624
387
|
|
|
625
388
|
// UI app
|
|
626
389
|
const uiSecretsPath = getVaultSecretsConfigs(toSite).uiSecretsPath;
|
|
627
|
-
console.log(`uiSecretsPath => ${uiSecretsPath}`)
|
|
390
|
+
console.log(`uiSecretsPath => ${uiSecretsPath}`);
|
|
628
391
|
|
|
629
392
|
// GraphQL-Server app
|
|
630
|
-
const graphqlSecretsPath =
|
|
393
|
+
const graphqlSecretsPath =
|
|
394
|
+
getVaultSecretsConfigs(toSite).graphqlServerSecretsPath;
|
|
631
395
|
console.log(`graphqlSecretsPath => ${graphqlSecretsPath}`);
|
|
632
396
|
|
|
633
|
-
let repoPathFromEnv =
|
|
634
|
-
let repoPathToEnv =
|
|
397
|
+
let repoPathFromEnv = '';
|
|
398
|
+
let repoPathToEnv = '';
|
|
635
399
|
// Clone repositories
|
|
636
|
-
if (
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}else {
|
|
640
|
-
|
|
641
|
-
|
|
400
|
+
if (fromEnv === toEnv) {
|
|
401
|
+
repoPathFromEnv = await cloneEnvRepository(fromEnv);
|
|
402
|
+
repoPathToEnv = repoPathFromEnv;
|
|
403
|
+
} else {
|
|
404
|
+
repoPathFromEnv = await cloneEnvRepository(fromEnv);
|
|
405
|
+
repoPathToEnv = await cloneEnvRepository(toEnv);
|
|
642
406
|
}
|
|
643
407
|
|
|
644
408
|
//TODO: clone fromEnv and toEnv. replace above with this
|
|
645
409
|
|
|
646
|
-
const auth0RepoPath = await cloneRepository('auth0-site-setup');
|
|
410
|
+
// const auth0RepoPath = await cloneRepository('auth0-site-setup');
|
|
647
411
|
|
|
648
412
|
// Read deploy configs
|
|
649
|
-
const { deployConfig: deployUIConfig } = await readDeployConfig(
|
|
413
|
+
const { deployConfig: deployUIConfig } = await readDeployConfig(
|
|
414
|
+
'ui',
|
|
415
|
+
fromEnv,
|
|
416
|
+
fromSite,
|
|
417
|
+
'values',
|
|
418
|
+
);
|
|
650
419
|
const uiImageTag = deployUIConfig.image.tag;
|
|
651
420
|
|
|
652
|
-
const { deployConfig: deployGraphQLServerConfig } = await readDeployConfig(
|
|
421
|
+
const { deployConfig: deployGraphQLServerConfig } = await readDeployConfig(
|
|
422
|
+
'graphql-server',
|
|
423
|
+
fromEnv,
|
|
424
|
+
fromSite,
|
|
425
|
+
'values',
|
|
426
|
+
);
|
|
653
427
|
const graphqlImageTag = deployGraphQLServerConfig.image.tag;
|
|
654
|
-
const graphqlStandardConfigRemoteBranch =
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
databaseJson: './auth0-site-setup/template/database-connections/docupace/database.json',
|
|
664
|
-
twilioJson: './auth0-site-setup/template/guardian/providers/sms-twilio.json',
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
console.log(`Copying Latest UI Image Tag: ${deployUIConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
|
|
668
|
-
console.log(`Copying Latest GraphQL Server Image Tag: ${deployGraphQLServerConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
|
|
428
|
+
const graphqlStandardConfigRemoteBranch =
|
|
429
|
+
deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
|
|
430
|
+
|
|
431
|
+
console.log(
|
|
432
|
+
`Copying Latest UI Image Tag: ${deployUIConfig.image.tag} from site: ${fromSite} to site: ${toSite}`,
|
|
433
|
+
);
|
|
434
|
+
console.log(
|
|
435
|
+
`Copying Latest GraphQL Server Image Tag: ${deployGraphQLServerConfig.image.tag} from site: ${fromSite} to site: ${toSite}`,
|
|
436
|
+
);
|
|
669
437
|
|
|
670
438
|
const envConfig = environmentConfig[toEnv];
|
|
671
439
|
|
|
672
|
-
let CORE_URL,
|
|
673
|
-
SITE_HOST,
|
|
674
|
-
CORE_API_CONTEXT,
|
|
675
|
-
CONNECT_URL,
|
|
676
|
-
DOCUPACE_HOST;
|
|
440
|
+
let CORE_URL, SITE_HOST, CORE_API_CONTEXT, CONNECT_URL, DOCUPACE_HOST;
|
|
677
441
|
if (useNewDomain) {
|
|
678
442
|
const newUrl = envConfig.newUrl(toSite);
|
|
679
443
|
CORE_URL = `${newUrl}/core`;
|
|
680
444
|
SITE_HOST = newUrl;
|
|
681
|
-
CORE_API_CONTEXT =
|
|
445
|
+
CORE_API_CONTEXT = 'core';
|
|
682
446
|
CONNECT_URL = `${newUrl}/connect`;
|
|
683
447
|
DOCUPACE_HOST = envConfig.docupaceHost();
|
|
684
448
|
} else {
|
|
@@ -689,27 +453,42 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
|
|
|
689
453
|
CONNECT_URL = `${oldUrl}_ui`;
|
|
690
454
|
}
|
|
691
455
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
456
|
+
if (deployUI === true || deployUI === 'true') {
|
|
457
|
+
await configureUI(
|
|
458
|
+
SITE_HOST,
|
|
459
|
+
CORE_URL,
|
|
460
|
+
DOCUPACE_HOST,
|
|
461
|
+
toSite,
|
|
462
|
+
toEnv,
|
|
463
|
+
useNewDomain,
|
|
464
|
+
auth0Domain,
|
|
465
|
+
auth0ClientId,
|
|
466
|
+
auth0ClientSecret,
|
|
467
|
+
auth0Token,
|
|
468
|
+
uiSecretsPath,
|
|
469
|
+
uiImageTag,
|
|
470
|
+
repoPathToEnv,
|
|
471
|
+
);
|
|
697
472
|
}
|
|
698
473
|
|
|
699
|
-
await configureGraphQLServer(
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
474
|
+
await configureGraphQLServer(
|
|
475
|
+
SITE_HOST,
|
|
476
|
+
CORE_URL,
|
|
477
|
+
DOCUPACE_HOST,
|
|
478
|
+
toSite,
|
|
479
|
+
toEnv,
|
|
480
|
+
auth0Domain,
|
|
481
|
+
auth0ClientId,
|
|
482
|
+
auth0ClientSecret,
|
|
483
|
+
auth0Token,
|
|
484
|
+
graphqlSecretsPath,
|
|
485
|
+
graphqlImageTag,
|
|
486
|
+
graphqlStandardConfigRemoteBranch,
|
|
487
|
+
repoPathToEnv,
|
|
488
|
+
commonSecrets,
|
|
489
|
+
);
|
|
490
|
+
await pushDeployConfig(
|
|
491
|
+
repoPathToEnv,
|
|
492
|
+
`Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`,
|
|
493
|
+
);
|
|
715
494
|
}
|