@docupace/pipeline 1.0.2-3.test → 1.0.2-3.test10

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,41 +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> <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);
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);
@@ -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
+ }