@docupace/pipeline 1.0.1-2.ervinsUpdate2.5 → 1.0.1

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,651 +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
-
151
- for (const [search, replace] of replacements) {
152
- const escapedSearch = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); // Escape special chars
153
- content = content.replace(new RegExp(escapedSearch, 'g'), replace);
154
- }
155
- await fs.promises.writeFile(filePath, content, 'utf8');
156
- }
157
-
158
- async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets) {
159
- try {
160
- let uiAllowedCallbacksUrls,
161
- uiAllowedLogoutUrls;
162
- let graphqlAllowedCallbacksUrls,
163
- graphqlAllowedLogoutUrls;
164
-
165
- // Configure URLs based on environment
166
- if (env === 'prd') {
167
- uiAllowedCallbacksUrls = [`${siteUrl}/api/auth/callback`];
168
- uiAllowedLogoutUrls = [`${siteUrl}`];
169
-
170
- graphqlAllowedCallbacksUrls = [`${siteUrl}/api/graphql/callback`];
171
- graphqlAllowedLogoutUrls = [`${siteUrl}/api/graphql/`];
172
-
173
- connectAllowedCallbacksUrls = [`${siteUrl}/connect/samlCallback?client_name=auth0`];
174
- connectlAllowedLogoutUrls = [ `${siteUrl}/connect`];
175
-
176
-
177
- } else {
178
- uiAllowedCallbacksUrls = [
179
- `${siteUrl}/api/auth/callback`,
180
- `http://localhost:3000/api/auth/callback`,
181
- ];
182
- uiAllowedLogoutUrls = [
183
- `${siteUrl}`,
184
- `http://localhost:3000`,
185
- ];
186
-
187
- graphqlAllowedCallbacksUrls = [
188
- `${siteUrl}/api/graphql/callback`,
189
- `http://localhost:4000/api/graphql/callback`,
190
- ];
191
- graphqlAllowedLogoutUrls = [
192
- `http://localhost:4000/api/graphql/`,
193
- `${siteUrl}/api/graphql/`,
194
- ];
195
-
196
- connectAllowedCallbacksUrls = [
197
- `${siteUrl}/connect/samlCallback?client_name=auth0`,
198
- `http://localhost:9000/connect/samlCallback?client_name=auth0`,
199
- ];
200
- connectlAllowedLogoutUrls = [
201
- `${siteUrl}/connect`
202
- ];
203
-
204
-
205
- }
206
-
207
- const configureUI = deployUI === 'true';
208
- if (configureUI) {
209
- console.log('ui_allowed_callbacks_urls ->', uiAllowedCallbacksUrls);
210
- console.log('ui_allowed_logout_urls ->', uiAllowedLogoutUrls);
211
-
212
- await updateJsonFile(filePaths.uiJson, {
213
- callbacks: uiAllowedCallbacksUrls,
214
- allowed_logout_urls: uiAllowedLogoutUrls,
215
- });
216
-
217
- //TODO: move to separate function for connect
218
- console.log('connect_allowed_callbacks_urls ->', connectAllowedCallbacksUrls);
219
- console.log('connect_allowed_logout_urls ->', connectAllowedLogoutUrls);
220
-
221
- await updateJsonFile(filePaths.connectJson, {
222
- callbacks: connectAllowedCallbacksUrls,
223
- allowed_logout_urls: connectAllowedLogoutUrls,
224
- });
225
-
226
- console.log('Updated URLs for main UI...');
227
- } else {
228
- await fs.promises.unlink(filePaths.uiJson);
229
- await updateJsonFile(filePaths.databaseJson, {
230
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-ui-main'),
231
- });
232
- console.log("Removed 'docupace-ui-main' from enabled_clients in database.json");
233
- }
234
-
235
- const configureGraphqlServer = deployGraphQLServer === 'true';
236
- if (configureGraphqlServer) {
237
- console.log('graphql_allowed_callbacks_urls ->', graphqlAllowedCallbacksUrls);
238
- console.log('graphql_allowed_logout_urls ->', graphqlAllowedLogoutUrls);
239
-
240
- await updateJsonFile(filePaths.graphqlJson, {
241
- callbacks: graphqlAllowedCallbacksUrls,
242
- allowed_logout_urls: graphqlAllowedLogoutUrls,
243
- });
244
- console.log('Updated URLs for GraphQL server...');
245
- } else {
246
- await fs.promises.unlink(filePaths.graphqlJson);
247
- await updateJsonFile(filePaths.databaseJson, {
248
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-graphql'),
249
- });
250
- console.log("Removed 'docupace-graphql' from enabled_clients in database.json");
251
- }
252
-
253
- // TWILIO configuration
254
- await replaceInFile(filePaths.twilioJson, [
255
- ['twilioauthtokenplaceholder', commonSecrets.TWILIO_AUTH_TOKEN],
256
- ['twiliosidplaceholder', commonSecrets.TWILIO_SID],
257
- ['twiliofromplaceholder', commonSecrets.TWILIO_FROM_NUMBER],
258
- ]);
259
-
260
- console.log('TWILIO configuration updated...');
261
-
262
- // Database configuration
263
- await replaceInFile(filePaths.databaseLoginJs, [
264
- ['${docupaceHost}', siteUrl],
265
- ['${docupaceContext}', coreApiContext],
266
- ]);
267
-
268
- // MFA configuration
269
- // if (process.env.AUTH0_MFA === 'ENABLE') {
270
- // console.log('AUTH0 MFA is enabled');
271
- // await execAsync('rsync -av ./auth0template/templateMFA/ ./auth0template/template/');
272
- // } else if (process.env.AUTH0_MFA === 'DISABLE') {
273
- // console.log('AUTH0 MFA is disabled');
274
- // await execAsync('rsync -av ./auth0template/templateNoMFA/ ./auth0template/template/');
275
- // }
276
-
277
- console.log('Template configuration completed.');
278
- } catch (err) {
279
- console.error('Error configuring Auth0 templates:', err);
280
- }
281
- }
282
-
283
- async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
284
- try {
285
- const response = await axios.post(`https://${auth0Domain}/oauth/token`, {
286
- client_id: clientId,
287
- client_secret: clientSecret,
288
- audience: `https://${auth0Domain}/api/v2/`,
289
- grant_type: 'client_credentials',
290
- }, {
291
- headers: {
292
- 'Content-Type': 'application/json',
293
- },
294
- });
295
-
296
- const authToken = response.data.access_token;
297
- // console.log("Auth0 Auth Token:", authToken);
298
- return authToken;
299
- } catch (error) {
300
- console.error("Error fetching Auth0 token:", error.response ? error.response.data : error.message);
301
- }
302
- }
303
-
304
- async function configureUI(siteHost, coreURL, docupaceHost, site, env, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, repoPath) {
305
- console.log(`Configuring UI for site: ${site} Host: ${siteHost} in env: ${env}`);
306
- siteHost = siteHost.replace('https://', '');
307
- coreURL = coreURL.replace('https://', '');
308
-
309
-
310
- try {
311
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
312
- headers: {authorization: `Bearer ${auth0Token}`},
313
- });
314
-
315
- const uiClient = auth0Response.data.find(client => client.name === "docupace-ui-main");
316
- const uiAuth0ClientId = uiClient.client_id;
317
- const uiAuth0ClientSecret = uiClient.client_secret;
318
-
319
- // Generate Auth0 Secret
320
- const uiAuth0Secret = crypto.randomBytes(48).toString('base64').replace(/[^a-zA-Z0-9]/g, '');
321
-
322
- // Prepare data payload
323
- console.log("Preparing Vault UI data payload...");
324
- const uiSecretData = JSON.stringify({
325
- data: {
326
- AUTH0_CLIENT_ID: uiAuth0ClientId,
327
- AUTH0_CLIENT_SECRET: uiAuth0ClientSecret,
328
- AUTH0_SECRET: uiAuth0Secret,
329
- },
330
- });
331
-
332
- await updateVaultSecrets(vaultSiteSecretsPath, uiSecretData);
333
-
334
- // Prepare ui.app.yaml
335
- const uiAppYaml = `
336
- repo: docupace-ui-main
337
- revision: master
338
- `.trim();
339
-
340
- // Prepare ui.values.yaml
341
- const uiValuesYaml = `
342
- uiMain:
343
- auth0BaseUrl: https://${siteHost}
344
- auth0IssuerBaseUrl: https://${auth0Domain}
345
- auth0ClientId: vault:secret/data/${site}/ui/config#AUTH0_CLIENT_ID
346
- graphqlClientUrl: https://${siteHost}/api/graphql
347
- graphqlServerUrl: https://${siteHost}/api/graphql
348
- connectUrl: https://${siteHost}
349
- coreUrl: https://${coreURL}
350
- env:
351
- AUTH0_CLIENT_SECRET: vault:secret/data/${site}/ui/config#AUTH0_CLIENT_SECRET
352
- AUTH0_SECRET: vault:secret/data/${site}/ui/config#AUTH0_SECRET
353
- image:
354
- repository: registry.paperout.com/docupace-ui-main-dev-docker-local/docupace-ui-main
355
- tag: ${imageTag}
356
- imagePullSecrets:
357
- - name: jf-artifactory
358
- ingress:
359
- enabled: true
360
- className: nginx
361
- annotations:
362
- external-dns.alpha.kubernetes.io/hostname: ${siteHost}
363
- external-dns.alpha.kubernetes.io/zone: public
364
- cert-manager.io/cluster-issuer: letsencrypt
365
- nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
366
- hosts:
367
- - host: ${siteHost}
368
- paths:
369
- - path: /
370
- pathType: Prefix
371
- tls:
372
- - hosts:
373
- - ${siteHost}
374
- secretName: dp-next-ui-cert
375
- externalConnectIngress:
376
- enabled: ${useNewDomain}
377
- className: nginx
378
- annotations:
379
- cert-manager.io/cluster-issuer: letsencrypt
380
- external-dns.alpha.kubernetes.io/hostname: ${siteHost}
381
- external-dns.alpha.kubernetes.io/zone: public
382
- nginx.ingress.kubernetes.io/backend-protocol: HTTPS
383
- nginx.ingress.kubernetes.io/configuration-snippet: |
384
- proxy_set_header Host ${siteHost};
385
- nginx.ingress.kubernetes.io/proxy-buffer-size: 8k
386
- hosts:
387
- - host: ${siteHost}
388
- paths:
389
- - path: /core
390
- - path: /core_b2b
391
- - path: /core_reports
392
- - path: /corerealm
393
- - path: /connect
394
- - path: /webstart
395
- - path: /core_ws
396
- - path: /core_docupload
397
- - path: /core_ariws
398
- - path: /core_restws
399
- - path: /core_webdav
400
- tls:
401
- - hosts:
402
- - ${siteHost}
403
- secretName: dp-next-ui-cert
404
- externalConnectService:
405
- enabled: ${useNewDomain}
406
- name: external-connect
407
- domain: ${docupaceHost}
408
- `.trim();
409
-
410
- // Write configuration files
411
- console.log("Writing configuration files...");
412
- await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
413
-
414
- await fs.writeFile(`${repoPath}/dp/${site}/ui.app.yaml`, uiAppYaml, (err) => {
415
- if (err) {
416
- console.error("Failed to write the file:", err);
417
- } else {
418
- console.log("File written successfully.");
419
- }
420
- });
421
-
422
- await fs.writeFile(`${repoPath}/dp/${site}/ui.values.yaml`, uiValuesYaml, (err) => {
423
- if (err) {
424
- console.error("Failed to write the file:", err);
425
- } else {
426
- console.log("File written successfully.");
427
- }
428
- });
429
- console.log("Done!");
430
- } catch (error) {
431
- console.error("Error configuring UI:", error);
432
- }
433
- }
434
-
435
- async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, standardConfigRemoteBranch, repoPath, commonSecrets) {
436
- siteHost = siteHost.replace('https://', '');
437
- coreURL = coreURL.replace('https://', '');
438
- console.log(`Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`);
439
-
440
- try {
441
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
442
- headers: {authorization: `Bearer ${auth0Token}`},
443
- });
444
-
445
- const graphQLServerClient = auth0Response.data.find(client => client.name === "docupace-graphql");
446
- const graphQLServerClientCredentials = auth0Response.data.find(client => client.name === "docupace-graphql-client-credentials");
447
-
448
- const graphQLServerAuth0ClientId = graphQLServerClient.client_id;
449
- const graphQLServerAuth0ClientSecret = graphQLServerClient.client_secret;
450
-
451
- const graphQLServerCCAuth0ClientId = graphQLServerClientCredentials.client_id;
452
- const graphQLServerCCAuth0ClientSecret = graphQLServerClientCredentials.client_secret;
453
-
454
- // Prepare data payload
455
- console.log("Preparing Vault GraphQL Server data payload...");
456
- const graphQLServerSecretData = JSON.stringify({
457
- data: {
458
- AUTH0_CLIENT_ID: graphQLServerAuth0ClientId,
459
- AUTH0_CLIENT_SECRET: graphQLServerAuth0ClientSecret,
460
- AUTH0_CC_CLIENT_ID: graphQLServerCCAuth0ClientId,
461
- AUTH0_CC_CLIENT_SECRET: graphQLServerCCAuth0ClientSecret,
462
- CORE_PASSWORD: commonSecrets.CORE_PASSWORD,
463
- REMOTE_CONFIG_PATH: commonSecrets.REMOTE_CONFIG_PATH,
464
- STANDARD_CONFIG_REMOTE_PATH: commonSecrets.STANDARD_CONFIG_REMOTE_PATH,
465
- },
466
- });
467
-
468
- await updateVaultSecrets(vaultSiteSecretsPath, graphQLServerSecretData);
469
-
470
- // Prepare ui.app.yaml
471
- const graphQLServerAppYaml = `
472
- repo: docupace-graphql-server
473
- revision: ${standardConfigRemoteBranch}
474
- `.trim();
475
-
476
- // Prepare ui.values.yaml
477
- const graphQLServerValuesYaml = `
478
- graphqlServer:
479
- auth0Domain: https://${auth0Domain}
480
- auth0ClientId: vault:secret/data/${site}/graphql-server/config#AUTH0_CLIENT_ID
481
- auth0Audience: ${commonSecrets.CORE_API_IDENTIFIER}
482
- baseUrl: https://${siteHost}/api/graphql
483
- coreUrl: https://${coreURL}
484
- integrationHubUrl: "https://${commonSecrets.INTEGRATION_HUB_URL}"
485
- standardConfigRemoteBranch: ${standardConfigRemoteBranch}
486
- apiLevel: "2"
487
- env:
488
- AUTH0_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CLIENT_SECRET
489
- STANDARD_CONFIG_REMOTE_PATH: vault:secret/data/common/config#STANDARD_CONFIG_REMOTE_PATH
490
- AUTH0_CC_CLIENT_ID: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_ID
491
- AUTH0_CC_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_SECRET
492
- image:
493
- repository: registry.paperout.com/docupace-graphql-server-dev-docker-local/docupace-graphql-server
494
- tag: ${imageTag}
495
- imagePullSecrets:
496
- - name: jf-artifactory
497
- ingress:
498
- annotations:
499
- external-dns.alpha.kubernetes.io/hostname: ${siteHost}
500
- external-dns.alpha.kubernetes.io/zone: public
501
- cert-manager.io/cluster-issuer: letsencrypt
502
- nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
503
- enabled: true
504
- className: nginx
505
- hosts:
506
- - host: ${siteHost}
507
- paths:
508
- - path: /api/graphql
509
- pathType: Prefix
510
- tls:
511
- - hosts:
512
- - ${siteHost}
513
- secretName: dp-next-ui-cert
514
- `.trim();
515
-
516
- // Write configuration files
517
- console.log("Writing ArgoCD GraphQL Server configuration files...");
518
- await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
519
-
520
- await fs.writeFile(`${repoPath}/dp/${site}/graphql-server.app.yaml`, graphQLServerAppYaml, (err) => {
521
- if (err) {
522
- console.error("Failed to write the file:", err);
523
- } else {
524
- console.log("File written successfully.");
525
- }
526
- });
527
-
528
- await fs.writeFile(`${repoPath}/dp/${site}/graphql-server.values.yaml`, graphQLServerValuesYaml, (err) => {
529
- if (err) {
530
- console.error("Failed to write the file:", err);
531
- } else {
532
- console.log("File written successfully.");
533
- }
534
- });
535
- console.log("Done!");
536
- } catch (error) {
537
- console.error("Error configuring GraphQL Server:", error);
538
- }
539
- }
540
-
541
-
542
- export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain) {
543
- console.log(`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`);
544
- // Common Secrets
545
- const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
546
- console.log(`commonSecretsPath => ${commonSecretsPath}`)
547
- const commonSecrets = await getVaultSecrets(commonSecretsPath);
548
-
549
- // Site Common Secrets
550
- const siteCommonSecretsPath = getVaultSecretsConfigs(toSite).siteCommonSecretsPath;
551
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`)
552
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
553
-
554
- const auth0Domain = `docupace-${toEnv}-${toSite}.us.auth0.com`
555
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
556
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
557
- const auth0Token = await getAuth0AuthToken(auth0Domain, auth0ClientId, auth0ClientSecret);
558
-
559
- // UI app
560
- const uiSecretsPath = getVaultSecretsConfigs(toSite).uiSecretsPath;
561
- console.log(`uiSecretsPath => ${uiSecretsPath}`)
562
-
563
- // GraphQL-Server app
564
- const graphqlSecretsPath = getVaultSecretsConfigs(toSite).graphqlServerSecretsPath;
565
- console.log(`graphqlSecretsPath => ${graphqlSecretsPath}`);
566
-
567
- let repoPathFromEnv ="";
568
- let repoPathToEnv = "";
569
- // Clone repositories
570
- if ( fromEnv == toEnv ) {
571
- repoPathFromEnv = await cloneEnvRepository(fromEnv);
572
- repoPathToEnv = repoPathFromEnv;
573
- }else {
574
- repoPathFromEnv = await cloneEnvRepository(fromEnv);
575
- repoPathToEnv = await cloneEnvRepository(toEnv);
576
- }
577
-
578
-
579
- //TODO: clone fromEnv and toEnv. replace above with this
580
-
581
- const auth0RepoPath = await cloneRepository('auth0-site-setup');
582
-
583
- // Read deploy configs
584
- const { deployConfig: deployUIConfig } = await readDeployConfig('ui', fromEnv, fromSite, 'values');
585
- const uiImageTag = deployUIConfig.image.tag;
586
-
587
- const { deployConfig: deployGraphQLServerConfig} = await readDeployConfig('graphql-server', fromEnv, fromSite, 'values');
588
- const graphqlImageTag = deployGraphQLServerConfig.image.tag;
589
- const graphqlStandardConfigRemoteBranch = deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
590
-
591
- // File paths
592
- const filePaths = {
593
- clientJson: './auth0-site-setup/template/clients/docupace-connect.json',
594
- databaseLoginJs: './auth0-site-setup/template/database-connections/docupace/login.js',
595
- loginHtml: './auth0-site-setup/template/pages/login.html',
596
- graphqlJson: './auth0-site-setup/template/clients/docupace-graphql.json',
597
- uiJson: './auth0-site-setup/template/clients/docupace-ui-main.json',
598
- connectJson: './auth0-site-setup/template/clients/docupace-connect.json',
599
- databaseJson: './auth0-site-setup/template/database-connections/docupace/database.json',
600
- twilioJson: './auth0-site-setup/template/guardian/providers/sms-twilio.json',
601
- };
602
-
603
- console.log(`Copying Latest UI Image Tag: ${deployUIConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
604
- console.log(`Copying Latest GraphQL Server Image Tag: ${deployGraphQLServerConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
605
-
606
- const envConfig = environmentConfig[toEnv];
607
-
608
- let CORE_URL,
609
- SITE_HOST,
610
- CORE_API_CONTEXT,
611
- CONNECT_URL,
612
- DOCUPACE_HOST;
613
- if (useNewDomain) {
614
- const newUrl = envConfig.newUrl(toSite);
615
- CORE_URL = `${newUrl}/core`;
616
- SITE_HOST = newUrl;
617
- CORE_API_CONTEXT = "core";
618
- CONNECT_URL = `${newUrl}/connect`;
619
- DOCUPACE_HOST = envConfig.docupaceHost();
620
- } else {
621
- const oldUrl = envConfig.oldUrl(toSite);
622
- CORE_URL = oldUrl;
623
- SITE_HOST = oldUrl;
624
- CORE_API_CONTEXT = toSite;
625
- CONNECT_URL = `${oldUrl}_ui`;
626
- }
627
-
628
- await templateAuth0(SITE_HOST, CORE_API_CONTEXT, toEnv, filePaths, deployUI, deployGraphQLServer, commonSecrets);
629
- await importAuth0Templates('./auth0-site-setup/template', auth0Domain, auth0ClientId, auth0ClientSecret);
630
-
631
- if (deployUI === 'true') {
632
- await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPathToEnv);
633
- }
634
-
635
- await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, graphqlStandardConfigRemoteBranch, repoPathToEnv, commonSecrets);
636
- await pushDeployConfig(repoPathToEnv, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
637
-
638
- await initializeAuth0Configuration({
639
- initConfiguration: "true",
640
- auth0Domain: auth0Domain,
641
- auth0AuthToken: auth0Token,
642
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER,
643
- });
644
-
645
- await addApplicationToApi({
646
- application: 'docupace-graphql-client-credentials',
647
- auth0Domain: auth0Domain,
648
- auth0AuthToken: auth0Token,
649
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER
650
- })
651
- }