@docupace/pipeline 1.0.33-matttest.2 → 1.0.33
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/package.json +3 -2
- package/src/auth0/alias.js +36 -39
- package/src/auth0/cli.js +48 -15
- package/src/auth0/configure.js +249 -451
- package/src/auth0/export.js +43 -0
- package/src/auth0/metadata.js +132 -0
- package/src/auth0/vault.js +3 -3
- package/src/next/cli.js +4 -29
- package/src/next/deploy.js +8 -16
- package/terraform/init.sh +21 -9
- package/terraform/plan.sh +12 -5
package/src/auth0/configure.js
CHANGED
|
@@ -2,27 +2,15 @@ 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
|
-
import fl from 'fs/promises';
|
|
7
5
|
|
|
8
6
|
import {
|
|
9
7
|
cloneEnvRepository,
|
|
10
|
-
cloneRepository,
|
|
11
8
|
readDeployConfig,
|
|
12
|
-
pushDeployConfig
|
|
9
|
+
pushDeployConfig,
|
|
13
10
|
} from '../next/deploy.js';
|
|
14
11
|
|
|
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';
|
|
12
|
+
import { getVaultSecrets, updateVaultSecrets } from './vault.js';
|
|
13
|
+
import { getVaultSecretsConfigs, environmentConfig } from '../next/config.js';
|
|
26
14
|
|
|
27
15
|
async function ensureDirectoryExists(dirPath) {
|
|
28
16
|
try {
|
|
@@ -33,359 +21,77 @@ async function ensureDirectoryExists(dirPath) {
|
|
|
33
21
|
}
|
|
34
22
|
}
|
|
35
23
|
|
|
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
|
-
|
|
24
|
+
export async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
|
|
60
25
|
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`,
|
|
26
|
+
const response = await axios.post(
|
|
27
|
+
`https://${auth0Domain}/oauth/token`,
|
|
70
28
|
{
|
|
71
|
-
client_id:
|
|
72
|
-
|
|
73
|
-
|
|
29
|
+
client_id: clientId,
|
|
30
|
+
client_secret: clientSecret,
|
|
31
|
+
audience: `https://${auth0Domain}/api/v2/`,
|
|
32
|
+
grant_type: 'client_credentials',
|
|
74
33
|
},
|
|
75
34
|
{
|
|
76
35
|
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: [],
|
|
36
|
+
'Content-Type': 'application/json',
|
|
110
37
|
},
|
|
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
38
|
},
|
|
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
|
-
});
|
|
39
|
+
);
|
|
360
40
|
|
|
361
41
|
const authToken = response.data.access_token;
|
|
362
42
|
// console.log("Auth0 Auth Token:", authToken);
|
|
363
43
|
return authToken;
|
|
364
44
|
} catch (error) {
|
|
365
|
-
console.error(
|
|
45
|
+
console.error(
|
|
46
|
+
'Error fetching Auth0 token:',
|
|
47
|
+
error.response ? error.response.data : error.message,
|
|
48
|
+
);
|
|
366
49
|
}
|
|
367
50
|
}
|
|
368
51
|
|
|
369
|
-
async function configureUI(
|
|
370
|
-
|
|
52
|
+
async function configureUI(
|
|
53
|
+
siteHost,
|
|
54
|
+
coreURL,
|
|
55
|
+
docupaceHost,
|
|
56
|
+
site,
|
|
57
|
+
env,
|
|
58
|
+
auth0Domain,
|
|
59
|
+
auth0ClientId,
|
|
60
|
+
auth0ClientSecret,
|
|
61
|
+
auth0Token,
|
|
62
|
+
vaultSiteSecretsPath,
|
|
63
|
+
imageTag,
|
|
64
|
+
repoPath,
|
|
65
|
+
useS3,
|
|
66
|
+
) {
|
|
67
|
+
console.log(
|
|
68
|
+
`Configuring UI for site: ${site} Host: ${siteHost} in env: ${env}`,
|
|
69
|
+
);
|
|
371
70
|
siteHost = siteHost.replace('https://', '');
|
|
372
71
|
coreURL = coreURL.replace('https://', '');
|
|
373
72
|
|
|
374
|
-
|
|
375
73
|
try {
|
|
376
|
-
const auth0Response = await axios.get(
|
|
377
|
-
|
|
378
|
-
|
|
74
|
+
const auth0Response = await axios.get(
|
|
75
|
+
`https://${auth0Domain}/api/v2/clients`,
|
|
76
|
+
{
|
|
77
|
+
headers: { authorization: `Bearer ${auth0Token}` },
|
|
78
|
+
},
|
|
79
|
+
);
|
|
379
80
|
|
|
380
|
-
const uiClient = auth0Response.data.find(
|
|
81
|
+
const uiClient = auth0Response.data.find(
|
|
82
|
+
(client) => client.name === 'docupace-ui-main',
|
|
83
|
+
);
|
|
381
84
|
const uiAuth0ClientId = uiClient.client_id;
|
|
382
85
|
const uiAuth0ClientSecret = uiClient.client_secret;
|
|
383
86
|
|
|
384
87
|
// Generate Auth0 Secret
|
|
385
|
-
const uiAuth0Secret = crypto
|
|
88
|
+
const uiAuth0Secret = crypto
|
|
89
|
+
.randomBytes(48)
|
|
90
|
+
.toString('base64')
|
|
91
|
+
.replace(/[^a-zA-Z0-9]/g, '');
|
|
386
92
|
|
|
387
93
|
// Prepare data payload
|
|
388
|
-
console.log(
|
|
94
|
+
console.log('Preparing Vault UI data payload...');
|
|
389
95
|
const uiSecretData = JSON.stringify({
|
|
390
96
|
data: {
|
|
391
97
|
AUTH0_CLIENT_ID: uiAuth0ClientId,
|
|
@@ -415,9 +121,28 @@ uiMain:
|
|
|
415
121
|
env:
|
|
416
122
|
AUTH0_CLIENT_SECRET: vault:secret/data/${site}/ui/config#AUTH0_CLIENT_SECRET
|
|
417
123
|
AUTH0_SECRET: vault:secret/data/${site}/ui/config#AUTH0_SECRET
|
|
124
|
+
${
|
|
125
|
+
useS3 === true || useS3 === 'true'
|
|
126
|
+
? `
|
|
127
|
+
AWS_ACCESS_KEY_ID: vault:secret/data/${site}/aws/config#AWS_ACCESS_KEY_ID
|
|
128
|
+
AWS_BUCKET_NAME: vault:secret/data/${site}/aws/config#AWS_BUCKET_NAME
|
|
129
|
+
AWS_SECRET_ACCESS_KEY: vault:secret/data/${site}/aws/config#AWS_SECRET_ACCESS_KEY
|
|
130
|
+
`.trim()
|
|
131
|
+
: ''
|
|
132
|
+
}
|
|
418
133
|
image:
|
|
419
134
|
repository: registry.paperout.com/docupace-ui-main-dev-docker-local/docupace-ui-main
|
|
420
135
|
tag: ${imageTag}
|
|
136
|
+
${
|
|
137
|
+
useS3 === true || useS3 === 'true'
|
|
138
|
+
? `
|
|
139
|
+
serviceAccount:
|
|
140
|
+
create: true
|
|
141
|
+
annotations:
|
|
142
|
+
eks.amazonaws.com/role-arn: arn:aws:iam::902873770924:role/eks-pod-identity-connect-next-${env}-${site}-bucket
|
|
143
|
+
`.trim()
|
|
144
|
+
: ''
|
|
145
|
+
}
|
|
421
146
|
imagePullSecrets:
|
|
422
147
|
- name: jf-artifactory
|
|
423
148
|
ingress:
|
|
@@ -438,7 +163,7 @@ ingress:
|
|
|
438
163
|
- ${siteHost}
|
|
439
164
|
secretName: dp-next-ui-cert
|
|
440
165
|
externalConnectIngress:
|
|
441
|
-
enabled:
|
|
166
|
+
enabled: true
|
|
442
167
|
className: nginx
|
|
443
168
|
annotations:
|
|
444
169
|
cert-manager.io/cluster-issuer: letsencrypt
|
|
@@ -467,57 +192,91 @@ externalConnectIngress:
|
|
|
467
192
|
- ${siteHost}
|
|
468
193
|
secretName: dp-next-ui-cert
|
|
469
194
|
externalConnectService:
|
|
470
|
-
enabled:
|
|
195
|
+
enabled: true
|
|
471
196
|
name: external-connect
|
|
472
197
|
domain: ${docupaceHost}
|
|
473
198
|
`.trim();
|
|
474
199
|
|
|
475
200
|
// Write configuration files
|
|
476
|
-
console.log(
|
|
201
|
+
console.log('Writing configuration files...');
|
|
477
202
|
await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
|
|
478
203
|
|
|
479
|
-
await fs.writeFile(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
204
|
+
await fs.writeFile(
|
|
205
|
+
`${repoPath}/dp/${site}/ui.app.yaml`,
|
|
206
|
+
uiAppYaml,
|
|
207
|
+
(err) => {
|
|
208
|
+
if (err) {
|
|
209
|
+
console.error('Failed to write the file:', err);
|
|
210
|
+
} else {
|
|
211
|
+
console.log('File written successfully.');
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
);
|
|
486
215
|
|
|
487
|
-
await fs.writeFile(
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
216
|
+
await fs.writeFile(
|
|
217
|
+
`${repoPath}/dp/${site}/ui.values.yaml`,
|
|
218
|
+
uiValuesYaml,
|
|
219
|
+
(err) => {
|
|
220
|
+
if (err) {
|
|
221
|
+
console.error('Failed to write the file:', err);
|
|
222
|
+
} else {
|
|
223
|
+
console.log('File written successfully.');
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
console.log('Done!');
|
|
495
228
|
} catch (error) {
|
|
496
|
-
console.error(
|
|
229
|
+
console.error('Error configuring UI:', error);
|
|
497
230
|
}
|
|
498
231
|
}
|
|
499
232
|
|
|
500
|
-
async function configureGraphQLServer(
|
|
233
|
+
async function configureGraphQLServer(
|
|
234
|
+
siteHost,
|
|
235
|
+
coreURL,
|
|
236
|
+
docupaceHost,
|
|
237
|
+
site,
|
|
238
|
+
env,
|
|
239
|
+
auth0Domain,
|
|
240
|
+
auth0ClientId,
|
|
241
|
+
auth0ClientSecret,
|
|
242
|
+
auth0Token,
|
|
243
|
+
vaultSiteSecretsPath,
|
|
244
|
+
imageTag,
|
|
245
|
+
standardConfigRemoteBranch,
|
|
246
|
+
repoPath,
|
|
247
|
+
commonSecrets,
|
|
248
|
+
) {
|
|
501
249
|
siteHost = siteHost.replace('https://', '');
|
|
502
250
|
coreURL = coreURL.replace('https://', '');
|
|
503
|
-
console.log(
|
|
251
|
+
console.log(
|
|
252
|
+
`Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`,
|
|
253
|
+
);
|
|
504
254
|
|
|
505
255
|
try {
|
|
506
|
-
const auth0Response = await axios.get(
|
|
507
|
-
|
|
508
|
-
|
|
256
|
+
const auth0Response = await axios.get(
|
|
257
|
+
`https://${auth0Domain}/api/v2/clients`,
|
|
258
|
+
{
|
|
259
|
+
headers: { authorization: `Bearer ${auth0Token}` },
|
|
260
|
+
},
|
|
261
|
+
);
|
|
509
262
|
|
|
510
|
-
const graphQLServerClient = auth0Response.data.find(
|
|
511
|
-
|
|
263
|
+
const graphQLServerClient = auth0Response.data.find(
|
|
264
|
+
(client) => client.name === 'docupace-graphql',
|
|
265
|
+
);
|
|
266
|
+
const graphQLServerClientCredentials = auth0Response.data.find(
|
|
267
|
+
(client) => client.name === 'docupace-graphql-client-credentials',
|
|
268
|
+
);
|
|
512
269
|
|
|
513
270
|
const graphQLServerAuth0ClientId = graphQLServerClient.client_id;
|
|
514
271
|
const graphQLServerAuth0ClientSecret = graphQLServerClient.client_secret;
|
|
515
272
|
|
|
516
|
-
const graphQLServerCCAuth0ClientId =
|
|
517
|
-
|
|
273
|
+
const graphQLServerCCAuth0ClientId =
|
|
274
|
+
graphQLServerClientCredentials.client_id;
|
|
275
|
+
const graphQLServerCCAuth0ClientSecret =
|
|
276
|
+
graphQLServerClientCredentials.client_secret;
|
|
518
277
|
|
|
519
278
|
// Prepare data payload
|
|
520
|
-
console.log(
|
|
279
|
+
console.log('Preparing Vault GraphQL Server data payload...');
|
|
521
280
|
const graphQLServerSecretData = JSON.stringify({
|
|
522
281
|
data: {
|
|
523
282
|
AUTH0_CLIENT_ID: graphQLServerAuth0ClientId,
|
|
@@ -580,105 +339,129 @@ ingress:
|
|
|
580
339
|
`.trim();
|
|
581
340
|
|
|
582
341
|
// Write configuration files
|
|
583
|
-
console.log(
|
|
342
|
+
console.log('Writing ArgoCD GraphQL Server configuration files...');
|
|
584
343
|
await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
|
|
585
344
|
|
|
586
|
-
await fs.writeFile(
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
345
|
+
await fs.writeFile(
|
|
346
|
+
`${repoPath}/dp/${site}/graphql-server.app.yaml`,
|
|
347
|
+
graphQLServerAppYaml,
|
|
348
|
+
(err) => {
|
|
349
|
+
if (err) {
|
|
350
|
+
console.error('Failed to write the file:', err);
|
|
351
|
+
} else {
|
|
352
|
+
console.log('File written successfully.');
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
);
|
|
593
356
|
|
|
594
|
-
await fs.writeFile(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
357
|
+
await fs.writeFile(
|
|
358
|
+
`${repoPath}/dp/${site}/graphql-server.values.yaml`,
|
|
359
|
+
graphQLServerValuesYaml,
|
|
360
|
+
(err) => {
|
|
361
|
+
if (err) {
|
|
362
|
+
console.error('Failed to write the file:', err);
|
|
363
|
+
} else {
|
|
364
|
+
console.log('File written successfully.');
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
);
|
|
368
|
+
console.log('Done!');
|
|
602
369
|
} catch (error) {
|
|
603
|
-
console.error(
|
|
370
|
+
console.error('Error configuring GraphQL Server:', error);
|
|
604
371
|
}
|
|
605
372
|
}
|
|
606
373
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
374
|
+
export async function configureFromSite(
|
|
375
|
+
fromSite,
|
|
376
|
+
toSite,
|
|
377
|
+
fromEnv,
|
|
378
|
+
toEnv,
|
|
379
|
+
deployUI,
|
|
380
|
+
deployGraphQLServer,
|
|
381
|
+
useNewDomain,
|
|
382
|
+
useS3,
|
|
383
|
+
) {
|
|
384
|
+
console.log(
|
|
385
|
+
`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`,
|
|
386
|
+
);
|
|
610
387
|
// Common Secrets
|
|
611
388
|
const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
|
|
612
|
-
console.log(`commonSecretsPath => ${commonSecretsPath}`)
|
|
389
|
+
console.log(`commonSecretsPath => ${commonSecretsPath}`);
|
|
613
390
|
const commonSecrets = await getVaultSecrets(commonSecretsPath);
|
|
614
391
|
|
|
615
392
|
// Site Common Secrets
|
|
616
|
-
const siteCommonSecretsPath =
|
|
617
|
-
|
|
393
|
+
const siteCommonSecretsPath =
|
|
394
|
+
getVaultSecretsConfigs(toSite).siteCommonSecretsPath;
|
|
395
|
+
console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
|
|
618
396
|
const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
|
|
619
397
|
|
|
620
|
-
const auth0Domain = `docupace-${toEnv}-${toSite}.us.auth0.com
|
|
398
|
+
const auth0Domain = `docupace-${toEnv}-${toSite}.us.auth0.com`;
|
|
621
399
|
const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
|
|
622
400
|
const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
|
|
623
|
-
const auth0Token = await getAuth0AuthToken(
|
|
401
|
+
const auth0Token = await getAuth0AuthToken(
|
|
402
|
+
auth0Domain,
|
|
403
|
+
auth0ClientId,
|
|
404
|
+
auth0ClientSecret,
|
|
405
|
+
);
|
|
624
406
|
|
|
625
407
|
// UI app
|
|
626
408
|
const uiSecretsPath = getVaultSecretsConfigs(toSite).uiSecretsPath;
|
|
627
|
-
console.log(`uiSecretsPath => ${uiSecretsPath}`)
|
|
409
|
+
console.log(`uiSecretsPath => ${uiSecretsPath}`);
|
|
628
410
|
|
|
629
411
|
// GraphQL-Server app
|
|
630
|
-
const graphqlSecretsPath =
|
|
412
|
+
const graphqlSecretsPath =
|
|
413
|
+
getVaultSecretsConfigs(toSite).graphqlServerSecretsPath;
|
|
631
414
|
console.log(`graphqlSecretsPath => ${graphqlSecretsPath}`);
|
|
632
415
|
|
|
633
|
-
let repoPathFromEnv =
|
|
634
|
-
let repoPathToEnv =
|
|
416
|
+
let repoPathFromEnv = '';
|
|
417
|
+
let repoPathToEnv = '';
|
|
635
418
|
// Clone repositories
|
|
636
|
-
if (
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}else {
|
|
640
|
-
|
|
641
|
-
|
|
419
|
+
if (fromEnv === toEnv) {
|
|
420
|
+
repoPathFromEnv = await cloneEnvRepository(fromEnv);
|
|
421
|
+
repoPathToEnv = repoPathFromEnv;
|
|
422
|
+
} else {
|
|
423
|
+
repoPathFromEnv = await cloneEnvRepository(fromEnv);
|
|
424
|
+
repoPathToEnv = await cloneEnvRepository(toEnv);
|
|
642
425
|
}
|
|
643
426
|
|
|
644
427
|
//TODO: clone fromEnv and toEnv. replace above with this
|
|
645
428
|
|
|
646
|
-
const auth0RepoPath = await cloneRepository('auth0-site-setup');
|
|
429
|
+
// const auth0RepoPath = await cloneRepository('auth0-site-setup');
|
|
647
430
|
|
|
648
431
|
// Read deploy configs
|
|
649
|
-
const { deployConfig: deployUIConfig } = await readDeployConfig(
|
|
432
|
+
const { deployConfig: deployUIConfig } = await readDeployConfig(
|
|
433
|
+
'ui',
|
|
434
|
+
fromEnv,
|
|
435
|
+
fromSite,
|
|
436
|
+
'values',
|
|
437
|
+
);
|
|
650
438
|
const uiImageTag = deployUIConfig.image.tag;
|
|
651
439
|
|
|
652
|
-
const { deployConfig: deployGraphQLServerConfig } = await readDeployConfig(
|
|
440
|
+
const { deployConfig: deployGraphQLServerConfig } = await readDeployConfig(
|
|
441
|
+
'graphql-server',
|
|
442
|
+
fromEnv,
|
|
443
|
+
fromSite,
|
|
444
|
+
'values',
|
|
445
|
+
);
|
|
653
446
|
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}`);
|
|
447
|
+
const graphqlStandardConfigRemoteBranch =
|
|
448
|
+
deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
|
|
449
|
+
|
|
450
|
+
console.log(
|
|
451
|
+
`Copying Latest UI Image Tag: ${deployUIConfig.image.tag} from site: ${fromSite} to site: ${toSite}`,
|
|
452
|
+
);
|
|
453
|
+
console.log(
|
|
454
|
+
`Copying Latest GraphQL Server Image Tag: ${deployGraphQLServerConfig.image.tag} from site: ${fromSite} to site: ${toSite}`,
|
|
455
|
+
);
|
|
669
456
|
|
|
670
457
|
const envConfig = environmentConfig[toEnv];
|
|
671
458
|
|
|
672
|
-
let CORE_URL,
|
|
673
|
-
SITE_HOST,
|
|
674
|
-
CORE_API_CONTEXT,
|
|
675
|
-
CONNECT_URL,
|
|
676
|
-
DOCUPACE_HOST;
|
|
459
|
+
let CORE_URL, SITE_HOST, CORE_API_CONTEXT, CONNECT_URL, DOCUPACE_HOST;
|
|
677
460
|
if (useNewDomain) {
|
|
678
461
|
const newUrl = envConfig.newUrl(toSite);
|
|
679
462
|
CORE_URL = `${newUrl}/core`;
|
|
680
463
|
SITE_HOST = newUrl;
|
|
681
|
-
CORE_API_CONTEXT =
|
|
464
|
+
CORE_API_CONTEXT = 'core';
|
|
682
465
|
CONNECT_URL = `${newUrl}/connect`;
|
|
683
466
|
DOCUPACE_HOST = envConfig.docupaceHost();
|
|
684
467
|
} else {
|
|
@@ -689,27 +472,42 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
|
|
|
689
472
|
CONNECT_URL = `${oldUrl}_ui`;
|
|
690
473
|
}
|
|
691
474
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
475
|
+
if (deployUI === true || deployUI === 'true') {
|
|
476
|
+
await configureUI(
|
|
477
|
+
SITE_HOST,
|
|
478
|
+
CORE_URL,
|
|
479
|
+
DOCUPACE_HOST,
|
|
480
|
+
toSite,
|
|
481
|
+
toEnv,
|
|
482
|
+
auth0Domain,
|
|
483
|
+
auth0ClientId,
|
|
484
|
+
auth0ClientSecret,
|
|
485
|
+
auth0Token,
|
|
486
|
+
uiSecretsPath,
|
|
487
|
+
uiImageTag,
|
|
488
|
+
repoPathToEnv,
|
|
489
|
+
useS3,
|
|
490
|
+
);
|
|
697
491
|
}
|
|
698
492
|
|
|
699
|
-
await configureGraphQLServer(
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
493
|
+
await configureGraphQLServer(
|
|
494
|
+
SITE_HOST,
|
|
495
|
+
CORE_URL,
|
|
496
|
+
DOCUPACE_HOST,
|
|
497
|
+
toSite,
|
|
498
|
+
toEnv,
|
|
499
|
+
auth0Domain,
|
|
500
|
+
auth0ClientId,
|
|
501
|
+
auth0ClientSecret,
|
|
502
|
+
auth0Token,
|
|
503
|
+
graphqlSecretsPath,
|
|
504
|
+
graphqlImageTag,
|
|
505
|
+
graphqlStandardConfigRemoteBranch,
|
|
506
|
+
repoPathToEnv,
|
|
507
|
+
commonSecrets,
|
|
508
|
+
);
|
|
509
|
+
await pushDeployConfig(
|
|
510
|
+
repoPathToEnv,
|
|
511
|
+
`Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`,
|
|
512
|
+
);
|
|
715
513
|
}
|