@docupace/pipeline 1.0.24-alpha-3 → 1.0.24

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,75 +1,75 @@
1
- import axios from 'axios';
2
-
3
- import {
4
- createAlias
5
- } from '../next/alias.js';
6
-
7
- import {getAuth0AuthToken} from './configure.js';
8
-
9
- import {
10
- getVaultSecrets,
11
- } from './vault.js';
12
-
13
- import {
14
- getVaultSecretsConfigs,
15
- } from '../next/config.js';
16
-
17
- import {
18
- cloneEnvRepository,
19
- readDeployConfig,
20
- } from '../next/deploy.js';
21
-
22
- export async function getCCAlias ({application, auth0Domain, auth0AuthToken}){
23
- console.log(`Forming alias name for application ${application}...`);
24
-
25
- try {
26
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
27
- headers: {authorization: `Bearer ${auth0AuthToken}`},
28
- });
29
-
30
- const appAuth0ClientIdData = auth0Response.data.find(client => client.name === `${application}`);
31
- const appAuth0ClientId = appAuth0ClientIdData.client_id;
32
-
33
- console.log(`Client Credentials Alias: ${appAuth0ClientId}@clients`);
34
- return `${appAuth0ClientId}@clients`;
35
- } catch (err) {
36
- console.error(`Failed to form alias name for application: ${application}: ${err.message}`);
37
- }
38
- }
39
-
40
- export async function configureAlias(site, env, username, password, realm) {
41
-
42
- console.log(`Creating alias for site: ${site} in env: ${env}`);
43
-
44
- const commonSecretsPath = getVaultSecretsConfigs(site).commonSecretsPath;
45
- console.log(`commonSecretsPath => ${commonSecretsPath}`)
46
- const commonSecrets = await getVaultSecrets(commonSecretsPath);
47
-
48
- // Site Common Secrets
49
- const siteCommonSecretsPath = getVaultSecretsConfigs(site).siteCommonSecretsPath;
50
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`)
51
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
52
-
53
- const auth0Domain = `docupace-${env}-${site}.us.auth0.com`
54
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
55
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
56
- const auth0Token = await getAuth0AuthToken(auth0Domain, auth0ClientId, auth0ClientSecret);
57
-
58
- await cloneEnvRepository(env);
59
-
60
- const { deployConfig: deployGraphQLServerConfig} = await readDeployConfig('graphql-server', env, site, 'values');
61
- const coreUrl = deployGraphQLServerConfig.graphqlServer.coreUrl;
62
-
63
- const clientCredentialsAlias = await getCCAlias({
64
- application: 'docupace-graphql-client-credentials',
65
- auth0Domain: auth0Domain,
66
- auth0AuthToken: auth0Token
67
- });
68
-
69
- await createAlias(
70
- coreUrl,
71
- username,
72
- password,
73
- realm,
74
- clientCredentialsAlias);
75
- }
1
+ import axios from 'axios';
2
+
3
+ import {
4
+ createAlias
5
+ } from '../next/alias.js';
6
+
7
+ import {getAuth0AuthToken} from './configure.js';
8
+
9
+ import {
10
+ getVaultSecrets,
11
+ } from './vault.js';
12
+
13
+ import {
14
+ getVaultSecretsConfigs,
15
+ } from '../next/config.js';
16
+
17
+ import {
18
+ cloneEnvRepository,
19
+ readDeployConfig,
20
+ } from '../next/deploy.js';
21
+
22
+ export async function getCCAlias ({application, auth0Domain, auth0AuthToken}){
23
+ console.log(`Forming alias name for application ${application}...`);
24
+
25
+ try {
26
+ const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
27
+ headers: {authorization: `Bearer ${auth0AuthToken}`},
28
+ });
29
+
30
+ const appAuth0ClientIdData = auth0Response.data.find(client => client.name === `${application}`);
31
+ const appAuth0ClientId = appAuth0ClientIdData.client_id;
32
+
33
+ console.log(`Client Credentials Alias: ${appAuth0ClientId}@clients`);
34
+ return `${appAuth0ClientId}@clients`;
35
+ } catch (err) {
36
+ console.error(`Failed to form alias name for application: ${application}: ${err.message}`);
37
+ }
38
+ }
39
+
40
+ export async function configureAlias(site, env, username, password, realm) {
41
+
42
+ console.log(`Creating alias for site: ${site} in env: ${env}`);
43
+
44
+ const commonSecretsPath = getVaultSecretsConfigs(site).commonSecretsPath;
45
+ console.log(`commonSecretsPath => ${commonSecretsPath}`)
46
+ const commonSecrets = await getVaultSecrets(commonSecretsPath);
47
+
48
+ // Site Common Secrets
49
+ const siteCommonSecretsPath = getVaultSecretsConfigs(site).siteCommonSecretsPath;
50
+ console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`)
51
+ const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
52
+
53
+ const auth0Domain = `docupace-${env}-${site}.us.auth0.com`
54
+ const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
55
+ const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
56
+ const auth0Token = await getAuth0AuthToken(auth0Domain, auth0ClientId, auth0ClientSecret);
57
+
58
+ await cloneEnvRepository(env);
59
+
60
+ const { deployConfig: deployGraphQLServerConfig} = await readDeployConfig('graphql-server', env, site, 'values');
61
+ const coreUrl = deployGraphQLServerConfig.graphqlServer.coreUrl;
62
+
63
+ const clientCredentialsAlias = await getCCAlias({
64
+ application: 'docupace-graphql-client-credentials',
65
+ auth0Domain: auth0Domain,
66
+ auth0AuthToken: auth0Token
67
+ });
68
+
69
+ await createAlias(
70
+ coreUrl,
71
+ username,
72
+ password,
73
+ realm,
74
+ clientCredentialsAlias);
75
+ }
package/src/auth0/cli.js CHANGED
@@ -1,42 +1,41 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import {
5
- configureFromSite
6
- } from './configure.js';
7
- import {
8
- getVaultSecrets
9
- } from './vault.js'
10
-
11
- import dotenv from 'dotenv';
12
- import {
13
- configureAlias
14
- } from "./alias.js";
15
-
16
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
17
-
18
- const program = new Command();
19
-
20
- program
21
- .command('configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain>')
22
- .description('Configure the Auth0 tenants in env for the given site')
23
- .action(async (fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain) => {
24
- await configureFromSite(fromSite, toSite, fromEnv, toEnv, deployUI, deployGraphQLServer, useNewDomain);
25
- });
26
-
27
- program
28
- .command('getVaultSecrets <vaultPath>')
29
- .description('Get Secrets for Vault PATH')
30
- .action(async (vaultPath) => {
31
- const data = await getVaultSecrets(vaultPath);
32
- console.log(JSON.stringify(data, 'null', 2));
33
- });
34
-
35
- program
36
- .command('configureAlias <site> <env> <username> <password> <realm>')
37
- .description('Configure Core Alias for the given site')
38
- .action(async (site, env, username, password, realm) => {
39
- await configureAlias(site, env, username, password, realm);
40
- });
41
-
42
- program.parse(process.argv);
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import {
5
+ configureFromSite
6
+ } from './configure.js';
7
+ import {
8
+ getVaultSecrets
9
+ } from './vault.js'
10
+
11
+ import dotenv from 'dotenv';
12
+ import {
13
+ configureAlias
14
+ } from "./alias.js";
15
+
16
+ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
17
+
18
+ const program = new Command();
19
+
20
+ program
21
+ .command('configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain> <configureMFA>')
22
+ .description('Configure the Auth0 tenants in env for the given site')
23
+ .action(async (fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA) => {
24
+ await configureFromSite(fromSite, toSite, fromEnv, toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA);
25
+ });
26
+
27
+ program
28
+ .command('getVaultSecrets <vaultPath>')
29
+ .description('Get Secrets for Vault PATH')
30
+ .action(async (vaultPath) => {
31
+ await getVaultSecrets(vaultPath);
32
+ });
33
+
34
+ program
35
+ .command('configureAlias <site> <env> <username> <password> <realm>')
36
+ .description('Configure Core Alias for the given site')
37
+ .action(async (site, env, username, password, realm) => {
38
+ await configureAlias(site, env, username, password, realm);
39
+ });
40
+
41
+ program.parse(process.argv);
@@ -2,6 +2,7 @@ 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';
5
6
  import fl from 'fs/promises';
6
7
 
7
8
  import {
@@ -53,6 +54,297 @@ async function copyDirectory(source, destination) {
53
54
  }
54
55
  }
55
56
 
57
+ async function addApplicationToApi ({application, auth0Domain, auth0AuthToken, coreApiIdentifier}){
58
+ console.log("Adding application to API authorized applications...");
59
+
60
+ try {
61
+ const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
62
+ headers: {authorization: `Bearer ${auth0AuthToken}`},
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`,
70
+ {
71
+ client_id: appAuth0ClientId,
72
+ audience: `${coreApiIdentifier}`,
73
+ scope: [],
74
+ },
75
+ {
76
+ headers: {
77
+ Authorization: `Bearer ${auth0AuthToken}`,
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}`,
127
+ },
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
+ },
151
+ debug: true,
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
+
56
348
  export async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
57
349
  try {
58
350
  const response = await axios.post(`https://${auth0Domain}/oauth/token`, {
@@ -312,7 +604,8 @@ ingress:
312
604
  }
313
605
  }
314
606
 
315
- export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain) {
607
+
608
+ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA) {
316
609
  console.log(`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`);
317
610
  // Common Secrets
318
611
  const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
@@ -340,17 +633,17 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
340
633
  let repoPathFromEnv ="";
341
634
  let repoPathToEnv = "";
342
635
  // Clone repositories
343
- if ( fromEnv === toEnv ) {
636
+ if ( fromEnv == toEnv ) {
344
637
  repoPathFromEnv = await cloneEnvRepository(fromEnv);
345
638
  repoPathToEnv = repoPathFromEnv;
346
- } else {
639
+ }else {
347
640
  repoPathFromEnv = await cloneEnvRepository(fromEnv);
348
641
  repoPathToEnv = await cloneEnvRepository(toEnv);
349
642
  }
350
643
 
351
644
  //TODO: clone fromEnv and toEnv. replace above with this
352
645
 
353
- // const auth0RepoPath = await cloneRepository('auth0-site-setup');
646
+ const auth0RepoPath = await cloneRepository('auth0-site-setup');
354
647
 
355
648
  // Read deploy configs
356
649
  const { deployConfig: deployUIConfig } = await readDeployConfig('ui', fromEnv, fromSite, 'values');
@@ -396,6 +689,9 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
396
689
  CONNECT_URL = `${oldUrl}_ui`;
397
690
  }
398
691
 
692
+ await templateAuth0(SITE_HOST, CORE_API_CONTEXT, toEnv, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA);
693
+ await importAuth0Templates('./auth0-site-setup/template', auth0Domain, auth0ClientId, auth0ClientSecret);
694
+
399
695
  if (deployUI === 'true') {
400
696
  await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPathToEnv);
401
697
  }
@@ -403,4 +699,17 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
403
699
  await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, graphqlStandardConfigRemoteBranch, repoPathToEnv, commonSecrets);
404
700
  await pushDeployConfig(repoPathToEnv, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
405
701
 
702
+ await initializeAuth0Configuration({
703
+ initConfiguration: "true",
704
+ auth0Domain: auth0Domain,
705
+ auth0AuthToken: auth0Token,
706
+ coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER,
707
+ });
708
+
709
+ await addApplicationToApi({
710
+ application: 'docupace-graphql-client-credentials',
711
+ auth0Domain: auth0Domain,
712
+ auth0AuthToken: auth0Token,
713
+ coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER
714
+ })
406
715
  }
@@ -7,16 +7,16 @@ import axios from 'axios';
7
7
  */
8
8
  export async function getVaultSecrets(vaultPath) {
9
9
  if (!vaultPath) {
10
- console.error("Error: VAULT_PATH is required.");
11
- throw new Error("VAULT_PATH is required.");
10
+ console.error('Error: VAULT_PATH is required.');
11
+ throw new Error('VAULT_PATH is required.');
12
12
  }
13
13
 
14
14
  const vaultToken = process.env.VAULT_TOKEN;
15
15
  const vaultAddr = process.env.VAULT_ADDR;
16
16
 
17
17
  if (!vaultToken || !vaultAddr) {
18
- console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
19
- throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
18
+ console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
19
+ throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
20
20
  }
21
21
 
22
22
  try {
@@ -38,8 +38,8 @@ export async function getVaultSecrets(vaultPath) {
38
38
  // console.log(`Secrets fetched successfully from Vault at ${JSON.stringify(data.data.data)})`);
39
39
  return data.data.data;
40
40
  } else {
41
- console.error("Error: Invalid JSON received from Vault.");
42
- throw new Error("Invalid JSON received from Vault.");
41
+ console.error('Error: Invalid JSON received from Vault.');
42
+ throw new Error('Invalid JSON received from Vault.');
43
43
  }
44
44
  } catch (error) {
45
45
  if (error.response) {
@@ -61,16 +61,16 @@ export async function getVaultSecrets(vaultPath) {
61
61
  */
62
62
  export async function updateVaultSecrets(vaultPath, secretData) {
63
63
  if (!vaultPath || !secretData) {
64
- console.error("Usage: updateVaultSecret(vaultPath, secretData)");
65
- throw new Error("Both vaultPath and secretData are required.");
64
+ console.error('Usage: updateVaultSecret(vaultPath, secretData)');
65
+ throw new Error('Both vaultPath and secretData are required.');
66
66
  }
67
67
 
68
68
  const vaultToken = process.env.VAULT_TOKEN;
69
69
  const vaultAddr = process.env.VAULT_ADDR;
70
70
 
71
71
  if (!vaultToken || !vaultAddr) {
72
- console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
73
- throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
72
+ console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
73
+ throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
74
74
  }
75
75
 
76
76
  try {