@docupace/pipeline 1.0.2-5.1 → 1.0.2

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,107 +0,0 @@
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,59 +0,0 @@
1
- import groovy.json.JsonSlurper
2
-
3
- import hudson.model.*;
4
-
5
- def build = Thread.currentThread().executable
6
- def params = build.getEnvironment(listener)
7
-
8
- def site = params.get('site')
9
- def server = "jboss7"
10
- def environment = params.get('environment')
11
-
12
- def buildFile=new File("D:\\Docupace\\CustomFolders\\" + environment + "\\" + site + "\\" + server + "\\buildApp.properties")
13
-
14
- List<String> jboss7controllerResult = []
15
-
16
- def controllersReport = new File("D:\\Docupace\\controllers_report.json")
17
- def inputJSON = new JsonSlurper().parseText(controllersReport.text)
18
- def props = new Properties()
19
- buildFile.withInputStream { stream -> props.load(stream) }
20
- def webRootContext = props["web.root.context"]
21
- if (webRootContext == null || webRootContext =="core") webRootContext = props["docupace.config.client.id"].toLowerCase()
22
-
23
- webRootContext = webRootContext.replaceFirst('_sso','')
24
- def map = inputJSON.'content'
25
-
26
- def Boolean enabled
27
-
28
- map.each {k,v ->
29
- v.each{vk, vv -> if (vk == webRootContext ) {
30
- enabled = false
31
- if(vv.deploymentsProperty.size()>0) enabled = vv.deploymentsProperty[0].isEnabled
32
- if (enabled) jboss7controllerResult.push(k)
33
- else jboss7controllerResult << k
34
- }
35
- }
36
- }
37
-
38
- if (jboss7controllerResult.size()>0) {
39
- if (environment == 'preprod') {
40
- jboss7controllerResult.remove("dev-corjbdc10.corp.docupace.com")
41
- jboss7controllerResult.remove("usdoc-s-jbdc1.corp.docupace.com")
42
- }
43
- if (environment == 'dev') {
44
- jboss7controllerResult.remove("qa-corjbdc10.corp.docupace.com")
45
- jboss7controllerResult.remove("qa-corjbdc20.corp.docupace.com")
46
- jboss7controllerResult.remove("usdoc-s-jbdc2.corp.docupace.com")
47
- }
48
- }
49
-
50
- println jboss7controllerResult[0]
51
-
52
- env.jboss7controller = jboss7controllerResult[0]
53
-
54
- def serverGroup = inputJSON.'content'."${jboss7controller}"."${webRootContext}".'serverGroup'
55
-
56
- println serverGroup
57
-
58
- params.put("serverGroup", serverGroup)
59
-
package/src/next/alias.js DELETED
@@ -1,53 +0,0 @@
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
- }
@@ -1,40 +0,0 @@
1
- import { $ } from 'zx';
2
-
3
- export async function addApacheSite() {
4
- if (
5
- !process.env.ENVIRONMENT ||
6
- (process.env.ENVIRONMENT !== 'dev' && process.env.ENVIRONMENT !== 'qa')
7
- ) {
8
- log("Error: ENVIRONMENT must be either 'dev' or 'qa'.");
9
- process.exit(1);
10
- }
11
- if (!process.env.SITE) {
12
- log('Error: SITE cannot be empty.');
13
- process.exit(1);
14
- }
15
-
16
- // Save private key from base64
17
- const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
18
- if (!haproxyPrivateKey) {
19
- log('Error: HAPROXY_PRIVATE_KEY not set.');
20
- process.exit(1);
21
- }
22
-
23
- await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
24
- await fs.chmod('private.key', 0o600);
25
-
26
-
27
- console.log("Running command");
28
- const sshCmd = (server,script) =>
29
- $`ssh -i private.key -o StrictHostKeyChecking=no root@${server} ${script}`;
30
-
31
- let server = `${process.env.ENVIRONMENT}-apalb01a.corp.docupace.com`;
32
- // The script is run twice in the Bash version
33
- await sshCmd(server, `/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`);
34
-
35
- server = `${process.env.ENVIRONMENT}-apalb01b.corp.docupace.com`;
36
-
37
- await sshCmd(server,`/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`);
38
- }
39
-
40
-
@@ -1,84 +0,0 @@
1
- export const environments = ['dev', 'qa', 'uat', 'stage', 'prod'];
2
-
3
- export const environmentConfig = {
4
- dev: {
5
- newUrl: (site) => `https://${site}.dev.dpai.tech`,
6
- oldUrl: (site) => `https://www.dev.docupaceinc.com/${site}`,
7
- docupaceHost: () => 'www.dev.docupaceinc.com',
8
- },
9
- qa: {
10
- newUrl: (site) => `https://${site}.qa.dpai.tech`,
11
- oldUrl: (site) => `https://www.preprod.docupaceinc.com/${site}`,
12
- docupaceHost: () => 'www.preprod.docupaceinc.com',
13
- },
14
- uat: {
15
- newUrl: (site) => `https://${site}.qa.dpai.tech`,
16
- oldUrl: (site) => `https://www2.paperout.com/${site}_uat`,
17
- docupaceHost: () => 'www2.paperout.com',
18
- },
19
- stage: {
20
- newUrl: (site) => `https://${site}.stage.dpai.tech`,
21
- oldUrl: (site) => `https://www2.paperout.com/${site}_staging`,
22
- docupaceHost: () => 'www2.paperout.com',
23
- },
24
- prod: {
25
- newUrl: (site) => `https://${site}.dpai.tech`,
26
- oldUrl: (site) => `https://www2.paperout.com/${site}`,
27
- docupaceHost: () => 'www2.paperout.com',
28
- },
29
- };
30
-
31
- export const appInfo = {
32
- 'graphql-server': {
33
- repositoryName: 'docupace-graphql-server',
34
- deployAttributes: [
35
- 'image.tag',
36
- 'graphqlServer.siteConfigRemoteBranch',
37
- 'graphqlServer.standardConfigRemoteBranch',
38
- ],
39
- },
40
- ui: {
41
- repositoryName: 'docupace-ui-main',
42
- deployAttributes: ['image.tag'],
43
- },
44
- };
45
-
46
- export const getEnvInfo = () => {
47
- const envInfo = Object.fromEntries(
48
- environments.map((env) => [
49
- env,
50
- {
51
- jfrog: {
52
- username: process.env[`JF_REGISTRY_${env.toUpperCase()}_USERNAME`],
53
- password: process.env[`JF_REGISTRY_${env.toUpperCase()}_PASSWORD`],
54
- },
55
- },
56
- ]),
57
- );
58
-
59
- return envInfo;
60
- };
61
-
62
- export const getBitbucketInfo = () => {
63
- return {
64
- username: process.env.BITBUCKET_USERNAME,
65
- password: process.env.BITBUCKET_APP_PASSWORD,
66
- workspace: 'dp-cloud',
67
- };
68
- };
69
-
70
- export const getRepUrl = (repoName) => {
71
- const { username, password, workspace } = getBitbucketInfo();
72
- return `https://${username}:${password}@bitbucket.org/${workspace}/${repoName}.git`;
73
- };
74
-
75
- export const jfRegistryUrl = 'registry.paperout.com';
76
-
77
- export const getVaultSecretsConfigs = (site) => {
78
- return {
79
- commonSecretsPath: 'secret/data/common/config',
80
- siteCommonSecretsPath: `secret/data/${site}/common/config`,
81
- graphqlServerSecretsPath: `secret/data/${site}/graphql-server/config`,
82
- uiSecretsPath: `secret/data/${site}/ui/config`,
83
- };
84
- };
@@ -1,189 +0,0 @@
1
- import 'zx/globals'; // npm i zx
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { $ } from 'zx';
5
-
6
- import { getVaultSecrets } from '../auth0/vault.js';
7
-
8
- process.env.COMMON_VAULT_PATH =
9
- process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
10
- process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
11
- process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
12
- const vaultToken = process.env.VAULT_TOKEN;
13
- const vaultAddr = process.env.VAULT_ADDR;
14
-
15
- const connectUIEnvMap = {
16
- dev: 'dev',
17
- qa: 'preprod',
18
- stg: 'stg',
19
- uat: 'uat',
20
- prd: 'prod-las',
21
- };
22
-
23
- function log(msg) {
24
- console.log(`[*] ${msg}`);
25
- }
26
-
27
- /* --------------------------------
28
- * 1. GIT CHECKOUT
29
- * -------------------------------- */
30
- async function gitCheckout(repository, destDir, branch = 'master') {
31
- if (!(await fs.pathExists(destDir))) {
32
- log(`Directory ${destDir} does not exist. Cloning repository...`);
33
- } else {
34
- log(`Directory ${destDir} exists. Removing it...`);
35
- await fs.remove(destDir);
36
- log(`Cloning ${destDir} repository...`);
37
- }
38
-
39
- const username = process.env.BITBUCKET_USERNAME;
40
- const password = process.env.BITBUCKET_APP_PASSWORD;
41
-
42
- // Construct clone command
43
- const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
44
-
45
- log(`Perform cloning`);
46
- await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
47
- }
48
-
49
- export async function connectClone() {
50
- const connectFromEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
51
- const connectToEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
52
- if (!vaultToken || !vaultAddr) {
53
- console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
54
- throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
55
- }
56
-
57
- const site = process.env.BUILD_SITE;
58
- if (!site) {
59
- log('Error: BUILD_SITE is not set');
60
- process.exit(1);
61
- }
62
- const siteCommonVaultPath = `secret/data/${site}/common/config`;
63
-
64
- // 2) getVaultSecrets
65
- const secretsJson = await getVaultSecrets(siteCommonVaultPath);
66
- if (!secretsJson.AUTH0_CLIENT_ID) {
67
- log('Failed to retrieve secret data.');
68
- process.exit(1);
69
- }
70
- const siteCommonSecrets = secretsJson;
71
-
72
- // 3) Export secrets as environment variables
73
- process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
74
- process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
75
-
76
- process.env.AUTH0_REGION_DOMAIN = 'us.auth0.com';
77
-
78
- log(`BUILD_ENVIRONMENT: ${connectToEnv}`);
79
- log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
80
- log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
81
- log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
82
- log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
83
-
84
- process.env.AUTH0_DOMAIN = `docupace-${process.env.BUILD_ENVIRONMENT}-${process.env.BUILD_SITE}.${process.env.AUTH0_REGION_DOMAIN}`;
85
-
86
- const projectRoot = process.cwd();
87
- // 4) Clone 'connect-deploy' into CONNECT_DIR
88
-
89
- await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
90
-
91
- await gitCheckout(
92
- `${connectToEnv}-site-settings`,
93
- `${process.env.CONNECT_DIR}/${connectToEnv}-site-settings`,
94
- );
95
-
96
- // 5) Create site clone (emulating the dock.sh call)
97
- const cloneFrom = path.join(
98
- projectRoot,
99
- process.env.CONNECT_DIR,
100
- `envs`,
101
- `${connectFromEnv}/${process.env.FROM_BUILD_SITE}`,
102
- );
103
- const cloneTo = path.join(
104
- projectRoot,
105
- process.env.CONNECT_DIR,
106
- `envs`,
107
- `${connectToEnv}/${process.env.BUILD_SITE}`,
108
- );
109
-
110
- if (!(await fs.pathExists(cloneFrom))) {
111
- log('Clone template directory not found:');
112
- process.exit(1);
113
- }
114
-
115
- if (!(await fs.pathExists(cloneTo))) {
116
- log('New site does not exist. Performing cloning...');
117
-
118
- process.env.IMAGE_VERSION =
119
- await $`cd ${cloneFrom} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`;
120
- log(`Image version: ${process.env.IMAGE_VERSION}`);
121
- //await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
122
- await (async () => {
123
- try {
124
- // Execute the shell command
125
- const result =
126
- await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
127
- await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
128
- await $`cd ${cloneTo} && git remote -v`;
129
- await $`cd ${cloneTo} && git branch`;
130
- await $`cd ${cloneTo} && git status`;
131
- await $`cd ${cloneTo} && git add . ../sites.sh`;
132
-
133
- console.log('Command succeeded:');
134
- console.log('stdout:', result.stdout); // Standard output
135
- console.log('stderr:', result.stderr); // Standard error
136
- } catch (error) {
137
- console.error('Command failed:');
138
- console.error('Exit Code:', error._code); // Exit code of the command
139
- console.error('Signal:', error._signal); // Signal that caused termination (if any)
140
- console.error('stdout:', error._stdout); // Standard output
141
- console.error('stderr:', error._stderr); // Standard error
142
- }
143
- })();
144
- } else {
145
- log('Site already exists. Continuing Auth0 setup...');
146
- }
147
-
148
- await (async () => {
149
- try {
150
- // Execute the shell command
151
- const result = await $`cd ${cloneTo} && bash dock.sh getAuth0Metadata`;
152
- console.log('Command succeeded:');
153
- console.log('stdout:', result.stdout); // Standard output
154
- console.log('stderr:', result.stderr); // Standard error
155
- } catch (error) {
156
- console.error('Command failed:');
157
- console.error('Exit Code:', error._code); // Exit code of the command
158
- console.error('Signal:', error._signal); // Signal that caused termination (if any)
159
- console.error('stdout:', error._stdout); // Standard output
160
- console.error('stderr:', error._stderr); // Standard error
161
- }
162
- })();
163
-
164
- // 7) Check conf files, print logs
165
- await $`grep "auth0" ${path.join(cloneTo, 'conf/application.conf')}`;
166
- await $`ls -all ${path.join(cloneTo, 'conf')}`;
167
- await $`ls -all ${path.join(cloneTo, 'conf/saml')}`;
168
- await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
169
-
170
- // 8) Git add, commit, push
171
- await $`cd ${cloneTo} && git add ./conf/application.conf ./conf/saml/auth0.xml`;
172
- await $`cd ${cloneTo} && git status`;
173
-
174
- const numChanges = (await $`cd ${cloneTo} && git diff-index HEAD`).stdout
175
- .split('\n')
176
- .filter(Boolean).length;
177
-
178
- if (numChanges > 0) {
179
- const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
180
- const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${connectToEnv}/${process.env.BUILD_SITE}`;
181
- log('About to commit changes to git');
182
- await $`cd ${cloneTo} && git commit -m ${message}`;
183
- await $`cd ${cloneTo} && git push -u origin master`;
184
- } else {
185
- log(
186
- 'No changes have been made. The site likely already has the correct configuration.',
187
- );
188
- }
189
- }
@@ -1,50 +0,0 @@
1
- import { $ } from 'zx';
2
-
3
-
4
- export async function haproxySync() {
5
- const repoPath = '/root/repo/docupace-ansible';
6
- const inventory = path.join(repoPath, 'inventories/preprod/inventory');
7
-
8
- // Create haproxy.sh
9
- const scriptContent = `
10
- #!/bin/bash
11
-
12
- [[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
13
- cd ${repoPath}
14
- pwd
15
- git stash
16
- git pull origin master
17
- git checkout master
18
- git submodule update --remote
19
- git submodule foreach --recursive git checkout master
20
- git submodule foreach --recursive git pull origin master
21
-
22
- ansible-playbook -i inventories/preprod/inventory haproxy.yml -e "cluster=preprod"
23
-
24
- echo "proceeding"
25
- echo "committing changes"
26
- git add preprod-haproxy.cfg
27
- git commit -m "Sync haproxy"
28
- git push origin master
29
- `;
30
-
31
- await fs.writeFile('haproxy.sh', scriptContent);
32
-
33
- // Private key
34
- const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
35
- if (!haproxyPrivateKey) {
36
- log('Error: HAPROXY_PRIVATE_KEY not set.');
37
- process.exit(1);
38
- }
39
-
40
- await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
41
- await fs.chmod('private.key', 0o600);
42
-
43
- await $`cat private.key`; // Just to mimic the script's behavior
44
-
45
- // Copy script to remote
46
- await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@10.10.28.198:/tmp/haproxy.sh`;
47
-
48
- // Execute script on remote
49
- await $`ssh -i private.key -o StrictHostKeyChecking=no root@10.10.28.198 "bash /tmp/haproxy.sh"`;
50
- }