@docupace/pipeline 1.0.43 → 1.0.44

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,43 +1,43 @@
1
- import { getVaultSecrets } from './vault.js';
2
- import { getVaultSecretsConfigs } from '../next/config.js';
3
- import { dump } from 'auth0-deploy-cli';
4
-
5
- export async function exportConf(site, env) {
6
- try {
7
- console.log(
8
- `Exporting Auth0 configuration for site: ${site} and env: ${env}`,
9
- );
10
-
11
- const siteCommonSecretsPath =
12
- getVaultSecretsConfigs(site).siteCommonSecretsPath;
13
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
14
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
15
-
16
- const auth0Domain = `docupace-${env}-${site}.us.auth0.com`;
17
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
18
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
19
-
20
- const config = {
21
- config: {
22
- AUTH0_DOMAIN: auth0Domain,
23
- AUTH0_CLIENT_ID: auth0ClientId,
24
- AUTH0_CLIENT_SECRET: auth0ClientSecret,
25
- },
26
- format: 'directory',
27
- output_folder: `./auth0-${site}-export`,
28
- export_ids: false,
29
- env: false,
30
- debug: true,
31
- };
32
-
33
- console.log(`Starting Auth0 ${site} configuration export...`);
34
- await dump(config);
35
- console.log(`Auth0 ${site} configuration export completed successfully!`);
36
- } catch (error) {
37
- console.error(
38
- `Error during Auth0 ${site} configuration export:`,
39
- error.message,
40
- );
41
- process.exit(1);
42
- }
43
- }
1
+ import { getVaultSecrets } from './vault.js';
2
+ import { getVaultSecretsConfigs } from '../next/config.js';
3
+ import { dump } from 'auth0-deploy-cli';
4
+
5
+ export async function exportConf(site, env) {
6
+ try {
7
+ console.log(
8
+ `Exporting Auth0 configuration for site: ${site} and env: ${env}`,
9
+ );
10
+
11
+ const siteCommonSecretsPath =
12
+ getVaultSecretsConfigs(site).siteCommonSecretsPath;
13
+ console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
14
+ const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
15
+
16
+ const auth0Domain = `docupace-${env}-${site}.us.auth0.com`;
17
+ const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
18
+ const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
19
+
20
+ const config = {
21
+ config: {
22
+ AUTH0_DOMAIN: auth0Domain,
23
+ AUTH0_CLIENT_ID: auth0ClientId,
24
+ AUTH0_CLIENT_SECRET: auth0ClientSecret,
25
+ },
26
+ format: 'directory',
27
+ output_folder: `./auth0-${site}-export`,
28
+ export_ids: false,
29
+ env: false,
30
+ debug: true,
31
+ };
32
+
33
+ console.log(`Starting Auth0 ${site} configuration export...`);
34
+ await dump(config);
35
+ console.log(`Auth0 ${site} configuration export completed successfully!`);
36
+ } catch (error) {
37
+ console.error(
38
+ `Error during Auth0 ${site} configuration export:`,
39
+ error.message,
40
+ );
41
+ process.exit(1);
42
+ }
43
+ }
@@ -1,132 +1,132 @@
1
- import fs from 'fs-extra';
2
- import axios from 'axios';
3
- import path from 'path';
4
- import { cloneRepository } from '../next/deploy.js';
5
- import { getAuth0AuthToken } from './configure.js';
6
- import { getVaultSecrets } from './vault.js';
7
- import { getVaultSecretsConfigs } from '../next/config.js';
8
- import { pushDeployConfig } from '../next/deploy.js';
9
-
10
- export async function getAuth0Metadata(site, env) {
11
- try {
12
- const connectDeployRepoPath = await cloneRepository('connect-deploy');
13
-
14
- if (env === 'qa') {
15
- console.log(
16
- `The environment is: (${env}), but connect-deploy has preprod instead`,
17
- );
18
- process.chdir(`${connectDeployRepoPath}/envs/preprod/${site}`);
19
- } else {
20
- process.chdir(`${connectDeployRepoPath}/envs/${env}/${site}`);
21
- }
22
-
23
- const configPath = path.join('conf', 'application.conf');
24
- const appConf = await fs.readFile(configPath, 'utf-8');
25
- const connectContext = appConf.match(
26
- /application\.context\s*=\s*"(.*?)"/,
27
- )?.[1];
28
-
29
- if (!connectContext) {
30
- console.error('connectContext not found in application.conf. Exiting...');
31
- process.exit(1);
32
- }
33
-
34
- const siteHost = appConf.match(
35
- /docupace\.baseUrlClient\s*=\s*"?https?:\/\/([^/]+)"?/,
36
- )?.[1];
37
-
38
- if (!siteHost) {
39
- console.error('siteHost not found in application.conf. Exiting...');
40
- process.exit(1);
41
- }
42
-
43
- const connectEndpoint = `https://${siteHost}${connectContext}`;
44
- console.log('CONNECT_ENDPOINT:', connectEndpoint);
45
-
46
- console.log('Requesting token from Auth0...');
47
- const siteCommonSecretsPath =
48
- getVaultSecretsConfigs(site).siteCommonSecretsPath;
49
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
50
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
51
- const auth0Domain = `docupace-${env}-${site}.us.auth0.com`;
52
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
53
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
54
- const auth0Token = await getAuth0AuthToken(
55
- auth0Domain,
56
- auth0ClientId,
57
- auth0ClientSecret,
58
- );
59
-
60
- const auth0Response = await axios.get(
61
- `https://${auth0Domain}/api/v2/clients`,
62
- {
63
- headers: { authorization: `Bearer ${auth0Token}` },
64
- },
65
- );
66
-
67
- const connectClient = auth0Response.data.find(
68
- (client) => client.name === 'docupace-connect',
69
- );
70
-
71
- if (!connectClient) {
72
- console.error('Client "docupace-connect" not found.');
73
- process.exit(1);
74
- }
75
-
76
- const clientId = connectClient.client_id;
77
- console.log('Found client_id:', clientId);
78
-
79
- const metadataRes = await axios.get(
80
- `https://${auth0Domain}/samlp/metadata/${clientId}`,
81
- {
82
- responseType: 'text',
83
- },
84
- );
85
-
86
- const metadata = metadataRes.data;
87
-
88
- if (metadata.length < 2000) {
89
- console.error(
90
- 'Downloaded metadata looks incorrect (too small). Exiting...',
91
- );
92
- process.exit(1);
93
- }
94
- await fs.ensureDir('conf/saml');
95
- await fs.writeFile('conf/saml/auth0.xml', metadata);
96
- console.log('SAML metadata written to conf/saml/auth0.xml');
97
-
98
- let newConfig = appConf;
99
-
100
- if (/useSAML\s*=/.test(appConf)) {
101
- newConfig = newConfig.replace(/useSAML\s*=.*/, 'useSAML=true');
102
- } else {
103
- newConfig += '\nuseSAML=true';
104
- }
105
-
106
- const replacements = {
107
- 'saml.clients.auth0.idpMetadataPath': '${samlEnvPath}"/auth0.xml"',
108
- 'saml.clients.auth0.spEntityId': `"${connectEndpoint}"`,
109
- 'saml.clients.auth0.redirectFormInput': '"RelayState"',
110
- 'saml.clients.auth0.idpLoginUrl': `"https://${auth0Domain}/v2/logout?client_id=${clientId}&returnTo=${connectEndpoint}"`,
111
- };
112
-
113
- for (const [key, value] of Object.entries(replacements)) {
114
- const pattern = new RegExp(`${key}\\s*=.*`, 'g');
115
- if (pattern.test(newConfig)) {
116
- newConfig = newConfig.replace(pattern, `${key}=${value}`);
117
- } else {
118
- newConfig += `\n${key}=${value}`;
119
- }
120
- }
121
-
122
- await fs.writeFile(configPath, newConfig);
123
- console.log('The application.conf has been updated.');
124
- await pushDeployConfig(
125
- connectDeployRepoPath,
126
- `Auth0 SAML metadata update for site: (${site}) in env: (${env})`,
127
- );
128
- } catch (error) {
129
- console.error('Error:', error.message);
130
- process.exit(1);
131
- }
132
- }
1
+ import fs from 'fs-extra';
2
+ import axios from 'axios';
3
+ import path from 'path';
4
+ import { cloneRepository } from '../next/deploy.js';
5
+ import { getAuth0AuthToken } from './configure.js';
6
+ import { getVaultSecrets } from './vault.js';
7
+ import { getVaultSecretsConfigs } from '../next/config.js';
8
+ import { pushDeployConfig } from '../next/deploy.js';
9
+
10
+ export async function getAuth0Metadata(site, env) {
11
+ try {
12
+ const connectDeployRepoPath = await cloneRepository('connect-deploy');
13
+
14
+ if (env === 'qa') {
15
+ console.log(
16
+ `The environment is: (${env}), but connect-deploy has preprod instead`,
17
+ );
18
+ process.chdir(`${connectDeployRepoPath}/envs/preprod/${site}`);
19
+ } else {
20
+ process.chdir(`${connectDeployRepoPath}/envs/${env}/${site}`);
21
+ }
22
+
23
+ const configPath = path.join('conf', 'application.conf');
24
+ const appConf = await fs.readFile(configPath, 'utf-8');
25
+ const connectContext = appConf.match(
26
+ /application\.context\s*=\s*"(.*?)"/,
27
+ )?.[1];
28
+
29
+ if (!connectContext) {
30
+ console.error('connectContext not found in application.conf. Exiting...');
31
+ process.exit(1);
32
+ }
33
+
34
+ const siteHost = appConf.match(
35
+ /docupace\.baseUrlClient\s*=\s*"?https?:\/\/([^/]+)"?/,
36
+ )?.[1];
37
+
38
+ if (!siteHost) {
39
+ console.error('siteHost not found in application.conf. Exiting...');
40
+ process.exit(1);
41
+ }
42
+
43
+ const connectEndpoint = `https://${siteHost}${connectContext}`;
44
+ console.log('CONNECT_ENDPOINT:', connectEndpoint);
45
+
46
+ console.log('Requesting token from Auth0...');
47
+ const siteCommonSecretsPath =
48
+ getVaultSecretsConfigs(site).siteCommonSecretsPath;
49
+ console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
50
+ const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
51
+ const auth0Domain = `docupace-${env}-${site}.us.auth0.com`;
52
+ const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
53
+ const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
54
+ const auth0Token = await getAuth0AuthToken(
55
+ auth0Domain,
56
+ auth0ClientId,
57
+ auth0ClientSecret,
58
+ );
59
+
60
+ const auth0Response = await axios.get(
61
+ `https://${auth0Domain}/api/v2/clients`,
62
+ {
63
+ headers: { authorization: `Bearer ${auth0Token}` },
64
+ },
65
+ );
66
+
67
+ const connectClient = auth0Response.data.find(
68
+ (client) => client.name === 'docupace-connect',
69
+ );
70
+
71
+ if (!connectClient) {
72
+ console.error('Client "docupace-connect" not found.');
73
+ process.exit(1);
74
+ }
75
+
76
+ const clientId = connectClient.client_id;
77
+ console.log('Found client_id:', clientId);
78
+
79
+ const metadataRes = await axios.get(
80
+ `https://${auth0Domain}/samlp/metadata/${clientId}`,
81
+ {
82
+ responseType: 'text',
83
+ },
84
+ );
85
+
86
+ const metadata = metadataRes.data;
87
+
88
+ if (metadata.length < 2000) {
89
+ console.error(
90
+ 'Downloaded metadata looks incorrect (too small). Exiting...',
91
+ );
92
+ process.exit(1);
93
+ }
94
+ await fs.ensureDir('conf/saml');
95
+ await fs.writeFile('conf/saml/auth0.xml', metadata);
96
+ console.log('SAML metadata written to conf/saml/auth0.xml');
97
+
98
+ let newConfig = appConf;
99
+
100
+ if (/useSAML\s*=/.test(appConf)) {
101
+ newConfig = newConfig.replace(/useSAML\s*=.*/, 'useSAML=true');
102
+ } else {
103
+ newConfig += '\nuseSAML=true';
104
+ }
105
+
106
+ const replacements = {
107
+ 'saml.clients.auth0.idpMetadataPath': '${samlEnvPath}"/auth0.xml"',
108
+ 'saml.clients.auth0.spEntityId': `"${connectEndpoint}"`,
109
+ 'saml.clients.auth0.redirectFormInput': '"RelayState"',
110
+ 'saml.clients.auth0.idpLoginUrl': `"https://${auth0Domain}/v2/logout?client_id=${clientId}&returnTo=${connectEndpoint}"`,
111
+ };
112
+
113
+ for (const [key, value] of Object.entries(replacements)) {
114
+ const pattern = new RegExp(`${key}\\s*=.*`, 'g');
115
+ if (pattern.test(newConfig)) {
116
+ newConfig = newConfig.replace(pattern, `${key}=${value}`);
117
+ } else {
118
+ newConfig += `\n${key}=${value}`;
119
+ }
120
+ }
121
+
122
+ await fs.writeFile(configPath, newConfig);
123
+ console.log('The application.conf has been updated.');
124
+ await pushDeployConfig(
125
+ connectDeployRepoPath,
126
+ `Auth0 SAML metadata update for site: (${site}) in env: (${env})`,
127
+ );
128
+ } catch (error) {
129
+ console.error('Error:', error.message);
130
+ process.exit(1);
131
+ }
132
+ }
@@ -1,107 +1,107 @@
1
- import axios from 'axios';
2
-
3
- /**
4
- * Fetch secrets from Vault.
5
- * @param {string} vaultPath - The path in Vault to fetch secrets from.
6
- * @returns {Promise<Object>} - The secret data as a JSON object.
7
- */
8
- export async function getVaultSecrets(vaultPath) {
9
- if (!vaultPath) {
10
- console.error('Error: VAULT_PATH is required.');
11
- throw new Error('VAULT_PATH is required.');
12
- }
13
-
14
- const vaultToken = process.env.VAULT_TOKEN;
15
- const vaultAddr = process.env.VAULT_ADDR;
16
-
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.');
20
- }
21
-
22
- try {
23
- // Disable SSL verification globally by setting environment variable
24
- if (process.env.VAULT_SKIP_VERIFY === 'true') {
25
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
26
- }
27
-
28
- // Fetch the secret from Vault
29
- const response = await axios.get(`${vaultAddr}/v1/${vaultPath}`, {
30
- headers: {
31
- 'X-Vault-Token': vaultToken,
32
- },
33
- });
34
-
35
- // Validate the response contains JSON data
36
- const data = response.data;
37
- if (data && typeof data === 'object') {
38
- // console.log(`Secrets fetched successfully from Vault at ${JSON.stringify(data.data.data)})`);
39
- return data.data.data;
40
- } else {
41
- console.error('Error: Invalid JSON received from Vault.');
42
- throw new Error('Invalid JSON received from Vault.');
43
- }
44
- } catch (error) {
45
- if (error.response) {
46
- console.error(
47
- `Error: Failed to connect to Vault server at ${vaultAddr}. Response: ${error.response.status} ${error.response.statusText}`,
48
- );
49
- } else {
50
- console.error(`Error: ${error.message}`);
51
- }
52
- // throw error;
53
- }
54
- }
55
-
56
- /**
57
- * Update a secret in Vault.
58
- * @param {string} vaultPath - The path in Vault where the secret should be updated.
59
- * @param {Object} secretData - The secret data to be stored (as a JSON object).
60
- * @returns {Promise<Object>} - The response from Vault as a JSON object.
61
- */
62
- export async function updateVaultSecrets(vaultPath, secretData) {
63
- if (!vaultPath || !secretData) {
64
- console.error('Usage: updateVaultSecret(vaultPath, secretData)');
65
- throw new Error('Both vaultPath and secretData are required.');
66
- }
67
-
68
- const vaultToken = process.env.VAULT_TOKEN;
69
- const vaultAddr = process.env.VAULT_ADDR;
70
-
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.');
74
- }
75
-
76
- try {
77
- // Disable SSL verification globally if VAULT_SKIP_VERIFY is set
78
- if (process.env.VAULT_SKIP_VERIFY === 'true') {
79
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
80
- }
81
-
82
- // Make the POST request to update the Vault secret
83
- const response = await axios.post(
84
- `${vaultAddr}/v1/${vaultPath}`,
85
- secretData,
86
- {
87
- headers: {
88
- 'X-Vault-Token': vaultToken,
89
- 'Content-Type': 'application/json',
90
- },
91
- },
92
- );
93
-
94
- // Return the response from Vault
95
- console.log(response.data);
96
- return response.data;
97
- } catch (error) {
98
- if (error.response) {
99
- console.error(
100
- `Error: Failed to update secret at ${vaultPath}. Response: ${error.response.status} ${error.response.statusText}`,
101
- );
102
- } else {
103
- console.error(`Error: ${error.message}`);
104
- }
105
- // throw error;
106
- }
107
- }
1
+ import axios from 'axios';
2
+
3
+ /**
4
+ * Fetch secrets from Vault.
5
+ * @param {string} vaultPath - The path in Vault to fetch secrets from.
6
+ * @returns {Promise<Object>} - The secret data as a JSON object.
7
+ */
8
+ export async function getVaultSecrets(vaultPath) {
9
+ if (!vaultPath) {
10
+ console.error('Error: VAULT_PATH is required.');
11
+ throw new Error('VAULT_PATH is required.');
12
+ }
13
+
14
+ const vaultToken = process.env.VAULT_TOKEN;
15
+ const vaultAddr = process.env.VAULT_ADDR;
16
+
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.');
20
+ }
21
+
22
+ try {
23
+ // Disable SSL verification globally by setting environment variable
24
+ if (process.env.VAULT_SKIP_VERIFY === 'true') {
25
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
26
+ }
27
+
28
+ // Fetch the secret from Vault
29
+ const response = await axios.get(`${vaultAddr}/v1/${vaultPath}`, {
30
+ headers: {
31
+ 'X-Vault-Token': vaultToken,
32
+ },
33
+ });
34
+
35
+ // Validate the response contains JSON data
36
+ const data = response.data;
37
+ if (data && typeof data === 'object') {
38
+ // console.log(`Secrets fetched successfully from Vault at ${JSON.stringify(data.data.data)})`);
39
+ return data.data.data;
40
+ } else {
41
+ console.error('Error: Invalid JSON received from Vault.');
42
+ throw new Error('Invalid JSON received from Vault.');
43
+ }
44
+ } catch (error) {
45
+ if (error.response) {
46
+ console.error(
47
+ `Error: Failed to connect to Vault server at ${vaultAddr}. Response: ${error.response.status} ${error.response.statusText}`,
48
+ );
49
+ } else {
50
+ console.error(`Error: ${error.message}`);
51
+ }
52
+ // throw error;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Update a secret in Vault.
58
+ * @param {string} vaultPath - The path in Vault where the secret should be updated.
59
+ * @param {Object} secretData - The secret data to be stored (as a JSON object).
60
+ * @returns {Promise<Object>} - The response from Vault as a JSON object.
61
+ */
62
+ export async function updateVaultSecrets(vaultPath, secretData) {
63
+ if (!vaultPath || !secretData) {
64
+ console.error('Usage: updateVaultSecret(vaultPath, secretData)');
65
+ throw new Error('Both vaultPath and secretData are required.');
66
+ }
67
+
68
+ const vaultToken = process.env.VAULT_TOKEN;
69
+ const vaultAddr = process.env.VAULT_ADDR;
70
+
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.');
74
+ }
75
+
76
+ try {
77
+ // Disable SSL verification globally if VAULT_SKIP_VERIFY is set
78
+ if (process.env.VAULT_SKIP_VERIFY === 'true') {
79
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
80
+ }
81
+
82
+ // Make the POST request to update the Vault secret
83
+ const response = await axios.post(
84
+ `${vaultAddr}/v1/${vaultPath}`,
85
+ secretData,
86
+ {
87
+ headers: {
88
+ 'X-Vault-Token': vaultToken,
89
+ 'Content-Type': 'application/json',
90
+ },
91
+ },
92
+ );
93
+
94
+ // Return the response from Vault
95
+ console.log(response.data);
96
+ return response.data;
97
+ } catch (error) {
98
+ if (error.response) {
99
+ console.error(
100
+ `Error: Failed to update secret at ${vaultPath}. Response: ${error.response.status} ${error.response.statusText}`,
101
+ );
102
+ } else {
103
+ console.error(`Error: ${error.message}`);
104
+ }
105
+ // throw error;
106
+ }
107
+ }