@docupace/pipeline 1.0.7-alpha.ervins1.9 → 1.0.7-beta.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.
@@ -1,622 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import yaml from 'js-yaml';
4
- import { $ } from 'zx';
5
- import axios from 'axios';
6
- import crypto from 'crypto';
7
- import { deploy } from 'auth0-deploy-cli';
8
-
9
- import {
10
- cloneEnvRepository,
11
- cloneRepository,
12
- readDeployConfig,
13
- pushDeployConfig
14
- } from '../next/deploy.js';
15
-
16
- import {
17
- getVaultSecrets,
18
- updateVaultSecrets
19
- } from './vault.js';
20
-
21
- import {
22
- getVaultSecretsConfigs,
23
- environmentConfig
24
- } from '../next/config.js';
25
-
26
- async function ensureDirectoryExists(dirPath) {
27
- try {
28
- await fs.promises.mkdir(dirPath, { recursive: true });
29
- console.log(`Directory created or already exists: ${dirPath}`);
30
- } catch (err) {
31
- console.error(`Failed to create directory: ${err.message}`);
32
- }
33
- }
34
-
35
- async function addApplicationToApi ({application, auth0Domain, auth0AuthToken, coreApiIdentifier}){
36
- console.log("Adding application to API authorized applications...");
37
-
38
- try {
39
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
40
- headers: {authorization: `Bearer ${auth0AuthToken}`},
41
- });
42
-
43
- const appAuth0ClientIdData = auth0Response.data.find(client => client.name === `${application}`);
44
- const appAuth0ClientId = appAuth0ClientIdData.client_id;
45
-
46
- await axios.post(
47
- `https://${auth0Domain}/api/v2/client-grants`,
48
- {
49
- client_id: appAuth0ClientId,
50
- audience: `${coreApiIdentifier}`,
51
- scope: [],
52
- },
53
- {
54
- headers: {
55
- Authorization: `Bearer ${auth0AuthToken}`,
56
- "Content-Type": "application/json",
57
- },
58
- }
59
- );
60
- console.log(`Application (${appAuth0ClientId}) authorized for API: ${coreApiIdentifier}`);
61
- } catch (err) {
62
- console.error(`Failed to add application: ${application}: ${err.message}`);
63
- }
64
-
65
- }
66
-
67
- async function initializeAuth0Configuration({
68
- initConfiguration,
69
- auth0Domain,
70
- auth0AuthToken,
71
- coreApiIdentifier,
72
- }) {
73
- if (initConfiguration === "true") {
74
- try {
75
- // Create a new resource server in Auth0
76
- console.log("Creating resource server in Auth0...");
77
-
78
- const resourceServerResponse = await axios.post(
79
- `https://${auth0Domain}/api/v2/resource-servers`,
80
- {
81
- name: "docupace-core",
82
- identifier: `${coreApiIdentifier}`,
83
- token_lifetime: 86400,
84
- allow_offline_access: false,
85
- signing_alg: "RS256",
86
- skip_consent_for_verifiable_first_party_clients: true,
87
- scopes: [],
88
- },
89
- {
90
- headers: {
91
- Authorization: `Bearer ${auth0AuthToken}`,
92
- "Content-Type": "application/json",
93
- },
94
- }
95
- );
96
-
97
- const apiId = resourceServerResponse.data.id;
98
-
99
- // Update tenant settings with the default audience
100
- console.log("Updating tenant settings...");
101
- await axios.patch(
102
- `https://${auth0Domain}/api/v2/tenants/settings`,
103
- {
104
- default_audience: `${coreApiIdentifier}`,
105
- },
106
- {
107
- headers: {
108
- Authorization: `Bearer ${auth0AuthToken}`,
109
- "Content-Type": "application/json",
110
- },
111
- }
112
- );
113
- console.log("Tenant settings updated successfully.");
114
- } catch (error) {
115
- console.error("Error during Auth0 configuration:", error.response?.data || error.message);
116
- }
117
- }
118
- }
119
-
120
- async function importAuth0Templates(directoryPath, auth0Domain, auth0ClientID, auth0ClientSecret) {
121
- try {
122
- const config = {
123
- input_file: directoryPath,
124
- config: {
125
- AUTH0_DOMAIN: auth0Domain,
126
- AUTH0_CLIENT_ID: auth0ClientID,
127
- AUTH0_CLIENT_SECRET: auth0ClientSecret,
128
- },
129
- debug: true,
130
- };
131
-
132
- console.log('Starting Auth0 template import...');
133
- await deploy(config);
134
- console.log('Auth0 template import completed successfully!');
135
- } catch (error) {
136
- console.error('Error during Auth0 template import:', error.message);
137
- process.exit(1); // Exit with an error code
138
- }
139
- }
140
-
141
- async function updateJsonFile(filePath, updates) {
142
- const content = await fs.promises.readFile(filePath, 'utf8');
143
- const jsonContent = JSON.parse(content);
144
- const updatedContent = JSON.stringify({...jsonContent, ...updates}, null, 2);
145
- await fs.promises.writeFile(filePath, updatedContent);
146
- }
147
-
148
- async function replaceInFile(filePath, replacements) {
149
- let content = await fs.promises.readFile(filePath, 'utf8');
150
- for (const [search, replace] of replacements) {
151
- content = content.replace(new RegExp(search, 'g'), replace);
152
- }
153
- await fs.promises.writeFile(filePath, content);
154
- }
155
-
156
- async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets) {
157
- try {
158
- let uiAllowedCallbacksUrls,
159
- uiAllowedLogoutUrls;
160
- let graphqlAllowedCallbacksUrls,
161
- graphqlAllowedLogoutUrls;
162
-
163
- // Configure URLs based on environment
164
- if (env === 'prd') {
165
- uiAllowedCallbacksUrls = [`https://${siteUrl}/api/auth/callback`];
166
- uiAllowedLogoutUrls = [`https://${siteUrl}`];
167
-
168
- graphqlAllowedCallbacksUrls = [`https://${siteUrl}/api/graphql/callback`];
169
- graphqlAllowedLogoutUrls = [`https://${siteUrl}/api/graphql/`];
170
- } else {
171
- uiAllowedCallbacksUrls = [
172
- `https://${siteUrl}/api/auth/callback`,
173
- `http://localhost:3000/api/auth/callback`,
174
- ];
175
- uiAllowedLogoutUrls = [
176
- `https://${siteUrl}`,
177
- `http://localhost:3000`,
178
- ];
179
-
180
- graphqlAllowedCallbacksUrls = [
181
- `https://${siteUrl}/api/graphql/callback`,
182
- `http://localhost:4000/api/graphql/callback`,
183
- ];
184
- graphqlAllowedLogoutUrls = [
185
- `http://localhost:4000/api/graphql/`,
186
- `https://${siteUrl}/api/graphql/`,
187
- ];
188
- }
189
-
190
- const configureUI = deployUI === 'true';
191
- if (configureUI) {
192
- console.log('ui_allowed_callbacks_urls ->', uiAllowedCallbacksUrls);
193
- console.log('ui_allowed_logout_urls ->', uiAllowedLogoutUrls);
194
-
195
- await updateJsonFile(filePaths.uiJson, {
196
- callbacks: uiAllowedCallbacksUrls,
197
- allowed_logout_urls: uiAllowedLogoutUrls,
198
- });
199
- console.log('Updated URLs for main UI...');
200
- } else {
201
- await fs.promises.unlink(filePaths.uiJson);
202
- await updateJsonFile(filePaths.databaseJson, {
203
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-ui-main'),
204
- });
205
- console.log("Removed 'docupace-ui-main' from enabled_clients in database.json");
206
- }
207
-
208
- const configureGraphqlServer = deployGraphQLServer === 'true';
209
- if (configureGraphqlServer) {
210
- console.log('graphql_allowed_callbacks_urls ->', graphqlAllowedCallbacksUrls);
211
- console.log('graphql_allowed_logout_urls ->', graphqlAllowedLogoutUrls);
212
-
213
- await updateJsonFile(filePaths.graphqlJson, {
214
- callbacks: graphqlAllowedCallbacksUrls,
215
- allowed_logout_urls: graphqlAllowedLogoutUrls,
216
- });
217
- console.log('Updated URLs for GraphQL server...');
218
- } else {
219
- await fs.promises.unlink(filePaths.graphqlJson);
220
- await updateJsonFile(filePaths.databaseJson, {
221
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-graphql'),
222
- });
223
- console.log("Removed 'docupace-graphql' from enabled_clients in database.json");
224
- }
225
-
226
- // TWILIO configuration
227
- await replaceInFile(filePaths.twilioJson, [
228
- ['twilioauthtokenplaceholder', commonSecrets.TWILIO_AUTH_TOKEN],
229
- ['twiliosidplaceholder', commonSecrets.TWILIO_SID],
230
- ['twiliofromplaceholder', commonSecrets.TWILIO_FROM_NUMBER],
231
- ]);
232
-
233
- console.log('TWILIO configuration updated...');
234
-
235
- // Database configuration
236
- await replaceInFile(filePaths.databaseLoginJs, [
237
- ['"${docupaceHost}"', `"${siteUrl}"`],
238
- ['"${docupaceContext}"', `"${coreApiContext}"`],
239
- ]);
240
-
241
- // MFA configuration
242
- // if (process.env.AUTH0_MFA === 'ENABLE') {
243
- // console.log('AUTH0 MFA is enabled');
244
- // await execAsync('rsync -av ./auth0template/templateMFA/ ./auth0template/template/');
245
- // } else if (process.env.AUTH0_MFA === 'DISABLE') {
246
- // console.log('AUTH0 MFA is disabled');
247
- // await execAsync('rsync -av ./auth0template/templateNoMFA/ ./auth0template/template/');
248
- // }
249
-
250
- console.log('Template configuration completed.');
251
- } catch (err) {
252
- console.error('Error configuring Auth0 templates:', err);
253
- }
254
- }
255
-
256
- async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
257
- try {
258
- const response = await axios.post(`https://${auth0Domain}/oauth/token`, {
259
- client_id: clientId,
260
- client_secret: clientSecret,
261
- audience: `https://${auth0Domain}/api/v2/`,
262
- grant_type: 'client_credentials',
263
- }, {
264
- headers: {
265
- 'Content-Type': 'application/json',
266
- },
267
- });
268
-
269
- const authToken = response.data.access_token;
270
- // console.log("Auth0 Auth Token:", authToken);
271
- return authToken;
272
- } catch (error) {
273
- console.error("Error fetching Auth0 token:", error.response ? error.response.data : error.message);
274
- }
275
- }
276
-
277
- async function configureUI(siteHost, coreURL, docupaceHost, site, env, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, repoPath) {
278
- console.log(`Configuring UI for site: ${site} Host: ${siteHost} in env: ${env}`);
279
-
280
- try {
281
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
282
- headers: {authorization: `Bearer ${auth0Token}`},
283
- });
284
-
285
- const uiClient = auth0Response.data.find(client => client.name === "docupace-ui-main");
286
- const uiAuth0ClientId = uiClient.client_id;
287
- const uiAuth0ClientSecret = uiClient.client_secret;
288
-
289
- // Generate Auth0 Secret
290
- const uiAuth0Secret = crypto.randomBytes(48).toString('base64').replace(/[^a-zA-Z0-9]/g, '');
291
-
292
- // Prepare data payload
293
- console.log("Preparing Vault UI data payload...");
294
- const uiSecretData = JSON.stringify({
295
- data: {
296
- AUTH0_CLIENT_ID: uiAuth0ClientId,
297
- AUTH0_CLIENT_SECRET: uiAuth0ClientSecret,
298
- AUTH0_SECRET: uiAuth0Secret,
299
- },
300
- });
301
-
302
- await updateVaultSecrets(vaultSiteSecretsPath, uiSecretData);
303
-
304
- // Prepare ui.app.yaml
305
- const uiAppYaml = `
306
- repo: docupace-ui-main
307
- revision: master
308
- `.trim();
309
-
310
- // Prepare ui.values.yaml
311
- const uiValuesYaml = `
312
- uiMain:
313
- auth0BaseUrl: https://${siteHost}
314
- auth0IssuerBaseUrl: https://${auth0Domain}
315
- auth0ClientId: vault:secret/data/${site}/ui/config#AUTH0_CLIENT_ID
316
- graphqlClientUrl: https://${siteHost}/api/graphql
317
- graphqlServerUrl: https://${siteHost}/api/graphql
318
- connectUrl: https://${siteHost}
319
- coreUrl: https://${coreURL}
320
- env:
321
- AUTH0_CLIENT_SECRET: vault:secret/data/${site}/ui/config#AUTH0_CLIENT_SECRET
322
- AUTH0_SECRET: vault:secret/data/${site}/ui/config#AUTH0_SECRET
323
- image:
324
- repository: registry.paperout.com/docupace-ui-main-dev-docker-local/docupace-ui-main
325
- tag: ${imageTag}
326
- imagePullSecrets:
327
- - name: jf-artifactory
328
- ingress:
329
- enabled: true
330
- className: nginx
331
- annotations:
332
- external-dns.alpha.kubernetes.io/hostname: ${siteHost}
333
- external-dns.alpha.kubernetes.io/zone: public
334
- cert-manager.io/cluster-issuer: letsencrypt
335
- nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
336
- hosts:
337
- - host: ${siteHost}
338
- paths:
339
- - path: /
340
- pathType: Prefix
341
- tls:
342
- - hosts:
343
- - ${siteHost}
344
- secretName: dp-next-ui-cert
345
- externalConnectIngress:
346
- enabled: ${useNewDomain}
347
- className: nginx
348
- annotations:
349
- cert-manager.io/cluster-issuer: letsencrypt
350
- external-dns.alpha.kubernetes.io/hostname: ${siteHost}
351
- external-dns.alpha.kubernetes.io/zone: public
352
- nginx.ingress.kubernetes.io/backend-protocol: HTTPS
353
- nginx.ingress.kubernetes.io/configuration-snippet: |
354
- proxy_set_header Host ${siteHost};
355
- nginx.ingress.kubernetes.io/proxy-buffer-size: 8k
356
- hosts:
357
- - host: ${siteHost}
358
- paths:
359
- - path: /core
360
- - path: /core_b2b
361
- - path: /core_reports
362
- - path: /corerealm
363
- - path: /connect
364
- - path: /webstart
365
- - path: /core_ws
366
- - path: /core_docupload
367
- - path: /core_ariws
368
- - path: /core_restws
369
- - path: /core_webdav
370
- tls:
371
- - hosts:
372
- - ${siteHost}
373
- secretName: dp-next-ui-cert
374
- externalConnectService:
375
- enabled: ${useNewDomain}
376
- name: external-connect
377
- domain: ${docupaceHost}
378
- `.trim();
379
-
380
- // Write configuration files
381
- console.log("Writing configuration files...");
382
- await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
383
-
384
- await fs.writeFile(`${repoPath}/dp/${site}/ui.app.yaml`, uiAppYaml, (err) => {
385
- if (err) {
386
- console.error("Failed to write the file:", err);
387
- } else {
388
- console.log("File written successfully.");
389
- }
390
- });
391
-
392
- await fs.writeFile(`${repoPath}/dp/${site}/ui.values.yaml`, uiValuesYaml, (err) => {
393
- if (err) {
394
- console.error("Failed to write the file:", err);
395
- } else {
396
- console.log("File written successfully.");
397
- }
398
- });
399
- console.log("Done!");
400
- } catch (error) {
401
- console.error("Error configuring UI:", error);
402
- }
403
- }
404
-
405
- async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, standardConfigRemoteBranch, repoPath, commonSecrets) {
406
- console.log(`Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`);
407
-
408
- try {
409
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
410
- headers: {authorization: `Bearer ${auth0Token}`},
411
- });
412
-
413
- const graphQLServerClient = auth0Response.data.find(client => client.name === "docupace-graphql");
414
- const graphQLServerClientCredentials = auth0Response.data.find(client => client.name === "docupace-graphql-client-credentials");
415
-
416
- const graphQLServerAuth0ClientId = graphQLServerClient.client_id;
417
- const graphQLServerAuth0ClientSecret = graphQLServerClient.client_secret;
418
-
419
- const graphQLServerCCAuth0ClientId = graphQLServerClientCredentials.client_id;
420
- const graphQLServerCCAuth0ClientSecret = graphQLServerClientCredentials.client_secret;
421
-
422
- // Prepare data payload
423
- console.log("Preparing Vault GraphQL Server data payload...");
424
- const graphQLServerSecretData = JSON.stringify({
425
- data: {
426
- AUTH0_CLIENT_ID: graphQLServerAuth0ClientId,
427
- AUTH0_CLIENT_SECRET: graphQLServerAuth0ClientSecret,
428
- AUTH0_CC_CLIENT_ID: graphQLServerCCAuth0ClientId,
429
- AUTH0_CC_CLIENT_SECRET: graphQLServerCCAuth0ClientSecret,
430
- CORE_PASSWORD: commonSecrets.CORE_PASSWORD,
431
- REMOTE_CONFIG_PATH: commonSecrets.REMOTE_CONFIG_PATH,
432
- STANDARD_CONFIG_REMOTE_PATH: commonSecrets.STANDARD_CONFIG_REMOTE_PATH,
433
- },
434
- });
435
-
436
- await updateVaultSecrets(vaultSiteSecretsPath, graphQLServerSecretData);
437
-
438
- // Prepare ui.app.yaml
439
- const graphQLServerAppYaml = `
440
- repo: docupace-graphql-server
441
- revision: ${standardConfigRemoteBranch}
442
- `.trim();
443
-
444
- // Prepare ui.values.yaml
445
- const graphQLServerValuesYaml = `
446
- graphqlServer:
447
- auth0Domain: https://${auth0Domain}
448
- auth0ClientId: vault:secret/data/${site}/graphql-server/config#AUTH0_CLIENT_ID
449
- auth0Audience: ${commonSecrets.CORE_API_IDENTIFIER}
450
- baseUrl: https://${siteHost}/api/graphql
451
- coreUrl: https://${coreURL}
452
- integrationHubUrl: "https://${commonSecrets.INTEGRATION_HUB_URL}"
453
- standardConfigRemoteBranch: ${standardConfigRemoteBranch}
454
- apiLevel: "2"
455
- env:
456
- AUTH0_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CLIENT_SECRET
457
- STANDARD_CONFIG_REMOTE_PATH: vault:secret/data/common/config#STANDARD_CONFIG_REMOTE_PATH
458
- AUTH0_CC_CLIENT_ID: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_ID
459
- AUTH0_CC_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_SECRET
460
- image:
461
- repository: registry.paperout.com/docupace-graphql-server-dev-docker-local/docupace-graphql-server
462
- tag: ${imageTag}
463
- imagePullSecrets:
464
- - name: jf-artifactory
465
- ingress:
466
- annotations:
467
- external-dns.alpha.kubernetes.io/hostname: ${siteHost}
468
- external-dns.alpha.kubernetes.io/zone: public
469
- cert-manager.io/cluster-issuer: letsencrypt
470
- nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
471
- enabled: true
472
- className: nginx
473
- hosts:
474
- - host: ${siteHost}
475
- paths:
476
- - path: /api/graphql
477
- pathType: Prefix
478
- tls:
479
- - hosts:
480
- - ${siteHost}
481
- secretName: dp-next-ui-cert
482
- `.trim();
483
-
484
- // Write configuration files
485
- console.log("Writing ArgoCD GraphQL Server configuration files...");
486
- await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
487
-
488
- await fs.writeFile(`${repoPath}/dp/${site}/graphql-server.app.yaml`, graphQLServerAppYaml, (err) => {
489
- if (err) {
490
- console.error("Failed to write the file:", err);
491
- } else {
492
- console.log("File written successfully.");
493
- }
494
- });
495
-
496
- await fs.writeFile(`${repoPath}/dp/${site}/graphql-server.values.yaml`, graphQLServerValuesYaml, (err) => {
497
- if (err) {
498
- console.error("Failed to write the file:", err);
499
- } else {
500
- console.log("File written successfully.");
501
- }
502
- });
503
- console.log("Done!");
504
- } catch (error) {
505
- console.error("Error configuring GraphQL Server:", error);
506
- }
507
- }
508
-
509
- export async function configureFromSite(fromSite, toSite, env, deployUI, deployGraphQLServer, useNewDomain) {
510
- console.log(`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${env} from site: ${fromSite}`);
511
- // Common Secrets
512
- const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
513
- console.log(`commonSecretsPath => ${commonSecretsPath}`)
514
- const commonSecrets = await getVaultSecrets(commonSecretsPath);
515
-
516
- // Site Common Secrets
517
- const siteCommonSecretsPath = getVaultSecretsConfigs(toSite).siteCommonSecretsPath;
518
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`)
519
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
520
-
521
- const auth0Domain = `docupace-${env}-${toSite}.us.auth0.com`
522
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
523
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
524
- const auth0Token = await getAuth0AuthToken(auth0Domain, auth0ClientId, auth0ClientSecret);
525
-
526
- // UI app
527
- const uiSecretsPath = getVaultSecretsConfigs(toSite).uiSecretsPath;
528
- console.log(`uiSecretsPath => ${uiSecretsPath}`)
529
-
530
- // GraphQL-Server app
531
- const graphqlSecretsPath = getVaultSecretsConfigs(toSite).graphqlServerSecretsPath;
532
- console.log(`graphqlSecretsPath => ${graphqlSecretsPath}`)
533
-
534
- // Clone repositories
535
- const repoPath = await cloneEnvRepository(env);
536
- const templateRepoPath = await cloneRepository('template');
537
- const auth0RepoPath = await cloneRepository('auth0-site-setup');
538
-
539
- // Read deploy configs
540
- const { deployConfig: deployUIConfig } = await readDeployConfig('ui', env, fromSite);
541
- const uiImageTag = deployUIConfig.image.tag;
542
-
543
- const { deployConfig: deployGraphQLServerConfig} = await readDeployConfig('graphql-server', env, fromSite);
544
- const graphqlImageTag = deployGraphQLServerConfig.image.tag;
545
- const graphqlStandardConfigRemoteBranch = deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
546
-
547
- // File paths
548
- const filePaths = {
549
- clientJson: './auth0-site-setup/template/clients/docupace-connect.json',
550
- databaseLoginJs: './auth0-site-setup/template/database-connections/docupace/login.js',
551
- loginHtml: './auth0-site-setup/template/pages/login.html',
552
- graphqlJson: './auth0-site-setup/template/clients/docupace-graphql.json',
553
- uiJson: './auth0-site-setup/template/clients/docupace-ui-main.json',
554
- databaseJson: './auth0-site-setup/template/database-connections/docupace/database.json',
555
- twilioJson: './auth0-site-setup/template/guardian/providers/sms-twilio.json',
556
- };
557
-
558
- console.log(`Copying Latest UI Image Tag: ${deployUIConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
559
- console.log(`Copying Latest GraphQL Server Image Tag: ${deployGraphQLServerConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
560
-
561
- // Get latest commit ID from TEMPLATE_DIR
562
- let shortCommitId;
563
- try {
564
- process.chdir(templateRepoPath);
565
- shortCommitId = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
566
-
567
- if (!shortCommitId) {
568
- console.error("Error: Latest Template commit ID is empty or not set");
569
- }
570
-
571
- console.log(`Latest Template commit ID: ${shortCommitId}`);
572
- process.chdir('..'); // Return to the parent directory
573
- } catch (error) {
574
- console.error("Error retrieving the latest template commit ID:", error.message);
575
- }
576
-
577
- const envConfig = environmentConfig[env];
578
-
579
- let CORE_URL,
580
- SITE_HOST,
581
- CORE_API_CONTEXT,
582
- CONNECT_URL,
583
- DOCUPACE_HOST;
584
- if (useNewDomain) {
585
- const newUrl = envConfig.newUrl(toSite);
586
- CORE_URL = `${newUrl}/core`;
587
- SITE_HOST = newUrl;
588
- CORE_API_CONTEXT = "core";
589
- CONNECT_URL = `${newUrl}/connect`;
590
- DOCUPACE_HOST = envConfig.docupaceHost();
591
- } else {
592
- const oldUrl = envConfig.oldUrl(toSite);
593
- CORE_URL = oldUrl;
594
- SITE_HOST = oldUrl;
595
- CORE_API_CONTEXT = toSite;
596
- CONNECT_URL = `${oldUrl}_ui`;
597
- }
598
-
599
- await templateAuth0(SITE_HOST, CORE_API_CONTEXT, env, filePaths, deployUI, deployGraphQLServer, commonSecrets);
600
- await importAuth0Templates('./auth0-site-setup/template', auth0Domain, auth0ClientId, auth0ClientSecret);
601
-
602
- if (deployUI === 'true') {
603
- await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPath);
604
- }
605
-
606
- await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, graphqlStandardConfigRemoteBranch, repoPath, commonSecrets);
607
- await pushDeployConfig(repoPath, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
608
-
609
- await initializeAuth0Configuration({
610
- initConfiguration: "true",
611
- auth0Domain: auth0Domain,
612
- auth0AuthToken: auth0Token,
613
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER,
614
- });
615
-
616
- await addApplicationToApi({
617
- application: 'docupace-graphql-client-credentials',
618
- auth0Domain: auth0Domain,
619
- auth0AuthToken: auth0Token,
620
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER
621
- })
622
- }