@docupace/pipeline 1.0.12 → 1.0.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
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);
@@ -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,
@@ -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
+ }
@@ -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;