@docupace/pipeline 1.0.12 → 1.0.15
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 +2 -1
- package/src/auth0/alias.js +75 -0
- package/src/auth0/cli.js +10 -0
- package/src/auth0/configure.js +2 -3
- package/src/next/alias.js +53 -0
- package/src/next/cli.js +3 -7
- package/src/next/deploy.js +1 -0
- package/src/next/vault.js +34 -30
- package/terraform/validate.sh +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docupace/pipeline",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@changesets/cli": "^2.27.10",
|
|
19
|
+
"@docupace/core-client": "^0.1.59",
|
|
19
20
|
"auth0-deploy-cli": "^7.24.3",
|
|
20
21
|
"axios": "^1.7.9",
|
|
21
22
|
"commander": "^12.1.0",
|
|
@@ -0,0 +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
|
+
}
|
package/src/auth0/cli.js
CHANGED
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
} from './vault.js'
|
|
10
10
|
|
|
11
11
|
import dotenv from 'dotenv';
|
|
12
|
+
import {
|
|
13
|
+
configureAlias
|
|
14
|
+
} from "./alias.js";
|
|
12
15
|
|
|
13
16
|
dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
|
|
14
17
|
|
|
@@ -28,4 +31,11 @@ program
|
|
|
28
31
|
await getVaultSecrets(vaultPath);
|
|
29
32
|
});
|
|
30
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
|
+
|
|
31
41
|
program.parse(process.argv);
|
package/src/auth0/configure.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import yaml from 'js-yaml';
|
|
4
|
-
import { $ } from 'zx';
|
|
5
3
|
import axios from 'axios';
|
|
6
4
|
import crypto from 'crypto';
|
|
7
5
|
import { deploy } from 'auth0-deploy-cli';
|
|
@@ -255,7 +253,7 @@ async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI,
|
|
|
255
253
|
}
|
|
256
254
|
}
|
|
257
255
|
|
|
258
|
-
async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
|
|
256
|
+
export async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
|
|
259
257
|
try {
|
|
260
258
|
const response = await axios.post(`https://${auth0Domain}/oauth/token`, {
|
|
261
259
|
client_id: clientId,
|
|
@@ -457,6 +455,7 @@ graphqlServer:
|
|
|
457
455
|
env:
|
|
458
456
|
AUTH0_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CLIENT_SECRET
|
|
459
457
|
STANDARD_CONFIG_REMOTE_PATH: vault:secret/data/common/config#STANDARD_CONFIG_REMOTE_PATH
|
|
458
|
+
SITE_CONFIG_REMOTE_PATH: vault:secret/data/${site}/common/config#SITE_CONFIG_REMOTE_PATH
|
|
460
459
|
AUTH0_CC_CLIENT_ID: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_ID
|
|
461
460
|
AUTH0_CC_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_SECRET
|
|
462
461
|
image:
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BasicAuth, DomainApi } from '@docupace/core-client';
|
|
2
|
+
|
|
3
|
+
const userFilter = (userId) => {
|
|
4
|
+
return {
|
|
5
|
+
orSections: [
|
|
6
|
+
{
|
|
7
|
+
andSections: [
|
|
8
|
+
{
|
|
9
|
+
attrId: 9501,
|
|
10
|
+
'@type': 'string',
|
|
11
|
+
not: false,
|
|
12
|
+
orSections: [
|
|
13
|
+
{ searchType: 'EXACT_MATCH', matchToValues: [userId] },
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
Example:
|
|
24
|
+
await createAlias(
|
|
25
|
+
'https://www.dev.docupaceinc.com/financialdev',
|
|
26
|
+
'docupace',
|
|
27
|
+
'pw',
|
|
28
|
+
'Connect',
|
|
29
|
+
'qhnospjRjwUAeKFDhucHEabPsfihrGQQ@clients',
|
|
30
|
+
);
|
|
31
|
+
*/
|
|
32
|
+
export async function createAlias(coreUrl, username, password, realm, alias) {
|
|
33
|
+
const coreInfo = {
|
|
34
|
+
url: coreUrl,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
let auth = new BasicAuth(username, password);
|
|
38
|
+
|
|
39
|
+
const domainApi = new DomainApi(coreInfo, auth);
|
|
40
|
+
|
|
41
|
+
const userResults = await domainApi.listRecords(50, {
|
|
42
|
+
filter: JSON.stringify(userFilter(username)),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const record = {
|
|
46
|
+
domainId: 302,
|
|
47
|
+
'5001': userResults.records[0].id,
|
|
48
|
+
'9102': realm,
|
|
49
|
+
'9504': alias,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
await domainApi.create(record);
|
|
53
|
+
}
|
package/src/next/cli.js
CHANGED
|
@@ -17,7 +17,6 @@ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
|
|
|
17
17
|
|
|
18
18
|
const program = new Command();
|
|
19
19
|
|
|
20
|
-
// GIT SHA computation
|
|
21
20
|
import { $ } from 'zx';
|
|
22
21
|
import {deployConnect, deployCore} from './jenkins.js';
|
|
23
22
|
import { runPipeline } from './pipline.js';
|
|
@@ -52,7 +51,6 @@ program
|
|
|
52
51
|
await connectClone();
|
|
53
52
|
});
|
|
54
53
|
|
|
55
|
-
|
|
56
54
|
program
|
|
57
55
|
.command('haproxySync')
|
|
58
56
|
.description('Sync haproxy config')
|
|
@@ -60,15 +58,14 @@ program
|
|
|
60
58
|
await haproxySync();
|
|
61
59
|
});
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
61
|
program
|
|
66
62
|
.command('vaultAddSiteData')
|
|
67
63
|
.description('Add m2m auth0 data to vault')
|
|
68
64
|
.requiredOption('-s, --site-name <siteName>', 'Site name')
|
|
65
|
+
.requiredOption('-p, --site-config-remote-path <siteConfigRemotePath>', 'Site Config Remote Path')
|
|
69
66
|
.action(async (options) => {
|
|
70
|
-
const { siteName,
|
|
71
|
-
await vaultAddSiteData(siteName);
|
|
67
|
+
const { siteName, siteConfigRemotePath } = options;
|
|
68
|
+
await vaultAddSiteData(siteName, siteConfigRemotePath);
|
|
72
69
|
});
|
|
73
70
|
|
|
74
71
|
program
|
|
@@ -130,7 +127,6 @@ program
|
|
|
130
127
|
});
|
|
131
128
|
});
|
|
132
129
|
|
|
133
|
-
|
|
134
130
|
program
|
|
135
131
|
.command('copy')
|
|
136
132
|
.description('Copy a Docker image between registries')
|
package/src/next/deploy.js
CHANGED
|
@@ -43,6 +43,7 @@ export async function cloneEnvRepository(env) {
|
|
|
43
43
|
const { repoPath, repoName } = getRepoLocalPath(env);
|
|
44
44
|
const repoUrl = getRepUrl(repoName);
|
|
45
45
|
console.log(`Cloning repository: ${repoName}`);
|
|
46
|
+
await cleanUpRepoPath(repoPath);
|
|
46
47
|
await $`git clone --depth 1 ${repoUrl}`;
|
|
47
48
|
console.log(`Repository cloned to: ${repoPath}`);
|
|
48
49
|
return repoPath;
|
package/src/next/vault.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
|
|
3
|
-
export async function vaultAddSiteData(SITE) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export async function vaultAddSiteData(SITE, SITE_CONFIG_REMOTE_PATH) {
|
|
4
|
+
const AUTH0_CLIENT_ID = process.env.AUTH0_CLIENT_ID;
|
|
5
|
+
const AUTH0_CLIENT_SECRET = process.env.AUTH0_CLIENT_SECRET;
|
|
6
|
+
const VAULT_ADDR = process.env.VAULT_ADDR; // Vault host URL from environment variables
|
|
7
|
+
const VAULT_TOKEN = process.env.VAULT_TOKEN; // Vault token from environment variables
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (!VAULT_ADDR || !VAULT_TOKEN) {
|
|
10
|
+
throw new Error('Missing VAULT_ADDR or VAULT_TOKEN environment variable.');
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const vaultApiUrl = `${VAULT_ADDR}/v1/secret/data/${SITE}/common/config`;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
const response = await axios.post(
|
|
17
|
-
vaultApiUrl,
|
|
18
|
-
{
|
|
19
|
-
data: {
|
|
20
|
-
AUTH0_CLIENT_ID: AUTH0_CLIENT_ID,
|
|
21
|
-
AUTH0_CLIENT_SECRET: AUTH0_CLIENT_SECRET,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
headers: {
|
|
26
|
-
'X-Vault-Token': VAULT_TOKEN,
|
|
27
|
-
'Content-Type': 'application/json',
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
);
|
|
15
|
+
try {
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.error('Error adding data to Vault:', error.response?.data || error.message);
|
|
35
|
-
throw error;
|
|
17
|
+
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
18
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
36
19
|
}
|
|
37
|
-
}
|
|
38
20
|
|
|
21
|
+
const response = await axios.post(
|
|
22
|
+
vaultApiUrl,
|
|
23
|
+
{
|
|
24
|
+
data: {
|
|
25
|
+
AUTH0_CLIENT_ID: AUTH0_CLIENT_ID,
|
|
26
|
+
AUTH0_CLIENT_SECRET: AUTH0_CLIENT_SECRET,
|
|
27
|
+
SITE_CONFIG_REMOTE_PATH: SITE_CONFIG_REMOTE_PATH,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
headers: {
|
|
32
|
+
'X-Vault-Token': VAULT_TOKEN,
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
);
|
|
39
37
|
|
|
38
|
+
console.log('Data added to Vault successfully:', response.data);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Error adding data to Vault:', error.response?.data || error.message);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/terraform/validate.sh
CHANGED