@itentialopensource/adapter-vmware_vcenter 0.6.0 → 0.7.0
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/CHANGELOG.md +8 -0
- package/adapter.js +469 -1
- package/adapterBase.js +23 -1
- package/entities/.generic/action.json +5 -5
- package/package.json +11 -7
- package/pronghorn.json +192 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1643047821981.json +95 -0
- package/test/integration/adapterTestIntegration.js +7 -1
- package/test/unit/adapterBaseTestUnit.js +1 -1
- package/test/unit/adapterTestUnit.js +102 -3
- package/utils/addAuth.js +94 -0
- package/utils/basicGet.js +1 -14
- package/utils/entitiesToDB.js +224 -0
- package/utils/modify.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +14 -8
- package/utils/tbUtils.js +70 -8
- package/utils/troubleshootingAdapter.js +2 -26
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/* @copyright Itential, LLC 2021 */
|
|
2
|
+
|
|
3
|
+
// Set globals
|
|
4
|
+
/* global log */
|
|
5
|
+
|
|
6
|
+
/* eslint import/no-dynamic-require: warn */
|
|
7
|
+
/* eslint global-require: warn */
|
|
8
|
+
/* eslint no-unused-vars: warn */
|
|
9
|
+
/* eslint import/no-unresolved: warn */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This script is used to read through an adapter's entities files
|
|
13
|
+
* and then creates documents and enters them into the IAP mongodb
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const { MongoClient } = require('mongodb');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
// const { argv } = require('process');
|
|
20
|
+
// const { string } = require('yargs');
|
|
21
|
+
|
|
22
|
+
// get the pronghorn database information
|
|
23
|
+
const getPronghornProps = async (iapDir) => {
|
|
24
|
+
log.trace('Retrieving properties.json file...');
|
|
25
|
+
const rawProps = require(path.join(iapDir, 'properties.json'));
|
|
26
|
+
log.trace('Decrypting properties...');
|
|
27
|
+
const { PropertyEncryption } = require('@itential/itential-utils');
|
|
28
|
+
const propertyEncryption = new PropertyEncryption();
|
|
29
|
+
const pronghornProps = await propertyEncryption.decryptProps(rawProps);
|
|
30
|
+
log.trace('Found properties.\n');
|
|
31
|
+
return pronghornProps;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Function used to take a file path to a entity directory and build
|
|
36
|
+
* a document that corresponds to the entity files.
|
|
37
|
+
*/
|
|
38
|
+
const buildDoc = (pathstring) => {
|
|
39
|
+
let files = fs.readdirSync(pathstring);
|
|
40
|
+
|
|
41
|
+
// load the mockdatafiles
|
|
42
|
+
const mockdatafiles = {};
|
|
43
|
+
if (files.includes('mockdatafiles') && fs.lstatSync(`${pathstring}/mockdatafiles`).isDirectory()) {
|
|
44
|
+
fs.readdirSync(`${pathstring}/mockdatafiles`).forEach((file) => {
|
|
45
|
+
if (file.split('.').pop() === 'json') {
|
|
46
|
+
const mockpath = `${pathstring}/mockdatafiles/${file}`;
|
|
47
|
+
const data = JSON.parse(fs.readFileSync(mockpath));
|
|
48
|
+
mockdatafiles[mockpath.split('/').pop()] = data;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// load the action data
|
|
54
|
+
let actions;
|
|
55
|
+
if (files.includes('action.json')) {
|
|
56
|
+
actions = JSON.parse(fs.readFileSync(`${pathstring}/action.json`));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Load schema.json and other schemas in remaining json files
|
|
60
|
+
files = files.filter((f) => (f !== 'action.json') && f.endsWith('.json'));
|
|
61
|
+
const schema = [];
|
|
62
|
+
files.forEach((file) => {
|
|
63
|
+
const data = JSON.parse(fs.readFileSync(`${pathstring}/${file}`));
|
|
64
|
+
schema.push({
|
|
65
|
+
name: file,
|
|
66
|
+
schema: data
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// return the data
|
|
71
|
+
return {
|
|
72
|
+
actions: actions.actions,
|
|
73
|
+
schema,
|
|
74
|
+
mockdatafiles
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Function used to get the database from the options or a provided directory
|
|
80
|
+
*/
|
|
81
|
+
const optionsHandler = (options) => {
|
|
82
|
+
// if the database properties were provided in the options - return them
|
|
83
|
+
if (options.pronghornProps) {
|
|
84
|
+
if (typeof options.pronghornProps === 'string') {
|
|
85
|
+
return JSON.parse(options.pronghornProps);
|
|
86
|
+
}
|
|
87
|
+
return new Promise((resolve, reject) => resolve(options.pronghornProps));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// if the directory was provided, get the pronghorn props from the directory
|
|
91
|
+
if (options.iapDir) {
|
|
92
|
+
return getPronghornProps(options.iapDir);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// if nothing was provided, error
|
|
96
|
+
return new Promise((resolve, reject) => reject(new Error('Neither pronghornProps nor iapDir defined in options!')));
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Function used to put the adapter configuration into the provided database
|
|
101
|
+
*/
|
|
102
|
+
const moveEntitiesToDB = (targetPath, options) => {
|
|
103
|
+
// set local variables
|
|
104
|
+
let myOpts = options;
|
|
105
|
+
let myPath = targetPath;
|
|
106
|
+
|
|
107
|
+
// if we got a string parse into a JSON object
|
|
108
|
+
if (typeof myOpts === 'string') {
|
|
109
|
+
myOpts = JSON.parse(myOpts);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// if there is no target collection - set the collection to the default
|
|
113
|
+
if (!myOpts.targetCollection) {
|
|
114
|
+
myOpts.targetCollection = 'adapter_configs';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// if there is no id error since we need an id for the entities
|
|
118
|
+
if (!myOpts.id) {
|
|
119
|
+
throw new Error('Adapter ID required!');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// get the pronghorn database properties
|
|
123
|
+
optionsHandler(options).then((currentProps) => {
|
|
124
|
+
let mongoUrl;
|
|
125
|
+
let dbName;
|
|
126
|
+
|
|
127
|
+
// find the mongo properties so we can connect
|
|
128
|
+
if (currentProps.mongoProps) {
|
|
129
|
+
mongoUrl = currentProps.mongoProps.url;
|
|
130
|
+
dbName = currentProps.mongoProps.db;
|
|
131
|
+
} else if (currentProps.mongo) {
|
|
132
|
+
if (currentProps.mongo.url) {
|
|
133
|
+
mongoUrl = currentProps.mongo.url;
|
|
134
|
+
} else {
|
|
135
|
+
mongoUrl = `mongodb://${currentProps.mongo.host}:${currentProps.mongo.port}`;
|
|
136
|
+
}
|
|
137
|
+
dbName = currentProps.mongo.database;
|
|
138
|
+
} else {
|
|
139
|
+
throw new Error('Mongo properties are not specified in adapter preferences!');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Check valid filepath provided
|
|
143
|
+
if (!myPath) {
|
|
144
|
+
// if no path use the current directory without the utils
|
|
145
|
+
myPath = path.join(__dirname, '../');
|
|
146
|
+
} else if (myPath.slice(-1) === '/') {
|
|
147
|
+
myPath = myPath.slice(0, -1);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// verify set the entity path
|
|
151
|
+
const entitiesPath = `${myPath}/entities`;
|
|
152
|
+
if (!fs.existsSync(entitiesPath)) {
|
|
153
|
+
throw new Error(`Entities path does not exist in filesystem: ${entitiesPath}`);
|
|
154
|
+
} else {
|
|
155
|
+
log.trace('Target found on filesystem');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Get adapter details
|
|
159
|
+
if (!fs.existsSync(`${myPath}/pronghorn.json`)) {
|
|
160
|
+
throw new Error(`pronghorn.json does not exist in path: ${myPath}`);
|
|
161
|
+
} else {
|
|
162
|
+
log.trace('pronghorn.json found on filesystem');
|
|
163
|
+
}
|
|
164
|
+
const adapterData = JSON.parse(fs.readFileSync(`${myPath}/pronghorn.json`));
|
|
165
|
+
|
|
166
|
+
// Load files from the filesystem
|
|
167
|
+
const docs = [];
|
|
168
|
+
const entities = fs.readdirSync(entitiesPath);
|
|
169
|
+
entities.forEach((entity) => {
|
|
170
|
+
const entityPath = `${entitiesPath}/${entity}`;
|
|
171
|
+
const isDir = fs.lstatSync(entitiesPath).isDirectory();
|
|
172
|
+
|
|
173
|
+
// Build doc for entity
|
|
174
|
+
if (isDir) {
|
|
175
|
+
let doc = buildDoc(entityPath);
|
|
176
|
+
doc = {
|
|
177
|
+
id: myOpts.id,
|
|
178
|
+
type: adapterData.id,
|
|
179
|
+
entity,
|
|
180
|
+
...doc
|
|
181
|
+
};
|
|
182
|
+
docs.push(doc);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Upload documents to db collection
|
|
187
|
+
MongoClient.connect(mongoUrl, (err, db) => {
|
|
188
|
+
if (err) {
|
|
189
|
+
log.error(JSON.stringify(err));
|
|
190
|
+
throw err;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// get the proper collection
|
|
194
|
+
const collection = db.db(dbName).collection(myOpts.targetCollection);
|
|
195
|
+
// insert the documents into the collection
|
|
196
|
+
collection.insertMany(docs, { checkKeys: false }, (error, res) => {
|
|
197
|
+
if (error) {
|
|
198
|
+
log.error(JSON.stringify(error));
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
// log the insertion, close the database and return
|
|
202
|
+
log.debug(`Inserted ${docs.length} documents to ${dbName}.${myOpts.targetCollection} with response ${JSON.stringify(res)}`);
|
|
203
|
+
db.close();
|
|
204
|
+
return res;
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// const args = process.argv.slice(2);
|
|
211
|
+
|
|
212
|
+
// throw new SyntaxError(args[0]);
|
|
213
|
+
|
|
214
|
+
// if (args.length === 0) {
|
|
215
|
+
// console.error('ERROR: target path not specified!');
|
|
216
|
+
// } else if (args[0] === 'help') {
|
|
217
|
+
// log.trace('node ./entitiesToDB <target path> <options object: {iapDir: string, pronghornProps: string, targetCollection: string}>');
|
|
218
|
+
// } else if (args.length === 1) {
|
|
219
|
+
// console.error('ERROR: IAP directory not specified');
|
|
220
|
+
// } else {
|
|
221
|
+
// moveEntitiesToDB(args[0], args[1]);
|
|
222
|
+
// }
|
|
223
|
+
|
|
224
|
+
module.exports = { moveEntitiesToDB };
|
package/utils/modify.js
CHANGED
|
@@ -3,7 +3,7 @@ const Ajv = require('ajv');
|
|
|
3
3
|
const rls = require('readline-sync');
|
|
4
4
|
const { execSync } = require('child_process');
|
|
5
5
|
const { existsSync } = require('fs-extra');
|
|
6
|
-
const { getAdapterConfig } = require('./
|
|
6
|
+
const { getAdapterConfig } = require('./tbUtils');
|
|
7
7
|
const { name } = require('../package.json');
|
|
8
8
|
const propertiesSchema = require('../propertiesSchema.json');
|
|
9
9
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const semverSatisfies = require('semver/functions/satisfies');
|
|
3
|
+
const packageJson = require('../package.json');
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
// pattern supplied by semver.org via https://regex101.com/r/vkijKf/1/ but removed gm from end to only match a single semver
|
|
7
|
+
// const semverPat = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
8
|
+
// pattern supplied by semver.org via https://regex101.com/r/Ly7O1x/3/ with following changes
|
|
9
|
+
// removed P's from before capturing group names and
|
|
10
|
+
// removed gm from end to only match a single semver
|
|
11
|
+
// const semverPat = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
12
|
+
|
|
13
|
+
const patches = (fs.existsSync('./patches')) ? fs.readdirSync('./patches', { withFileTypes: true }) : [];
|
|
14
|
+
if (!patches.length) {
|
|
15
|
+
console.error('\nno patches - nothing to do\n');
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const dependencies = packageJson.dependencies || {};
|
|
20
|
+
if (!Object.keys(dependencies).length) {
|
|
21
|
+
console.error('\nno dependencies - nothing to do\n');
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let changed = false;
|
|
26
|
+
console.error('\nprocessing patches');
|
|
27
|
+
const bundledDependencies = packageJson.bundledDependencies || packageJson.bundleDependencies || [];
|
|
28
|
+
|
|
29
|
+
patches.forEach((patch) => {
|
|
30
|
+
if (!patch.isFile()) {
|
|
31
|
+
console.error(`${patch.name} skipped, is not a regular file`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!patch.name.endsWith('.patch')) {
|
|
35
|
+
console.error(`${patch.name} skipped, does not end with .patch`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const splits = patch.name.slice(0, -6).split('+');
|
|
39
|
+
if (splits.length > 4) {
|
|
40
|
+
console.error(`${patch.name} skipped, does not follow the naming convention (cannot use '+' other than to separate scope/package/semver and at most once within semver)`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const scope = splits[0][0] === '@' ? splits.shift() : null;
|
|
44
|
+
const packageName = splits.shift();
|
|
45
|
+
const semver = splits.join('+');
|
|
46
|
+
// const { groups } = semver.match(semverPat);
|
|
47
|
+
const file = scope ? `${scope}/${packageName}` : packageName;
|
|
48
|
+
if (dependencies[file] && semverSatisfies(semver, dependencies[file])) {
|
|
49
|
+
if (!bundledDependencies.includes(file)) {
|
|
50
|
+
bundledDependencies.push(file);
|
|
51
|
+
console.error(`added ${file} to bundledDependencies`);
|
|
52
|
+
changed = true;
|
|
53
|
+
} else {
|
|
54
|
+
console.error(`bundledDependencies already has ${file}`);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
const depmsg = dependencies[file] ? `version mismatch (${dependencies[file]}) in dependencies` : 'not found in dependencies';
|
|
58
|
+
console.error(`patch ${patch.name} ${depmsg}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!packageJson.bundledDependencies && bundledDependencies.length) {
|
|
63
|
+
delete packageJson.bundleDependencies;
|
|
64
|
+
packageJson.bundledDependencies = bundledDependencies;
|
|
65
|
+
console.error('renaming bundleDependencies to bundledDependencies');
|
|
66
|
+
changed = true;
|
|
67
|
+
}
|
|
68
|
+
if (changed) {
|
|
69
|
+
fs.writeFileSync('./package.json.new', JSON.stringify(packageJson, null, 2));
|
|
70
|
+
console.error('wrote package.json.new');
|
|
71
|
+
fs.renameSync('./package.json', './package.json.old');
|
|
72
|
+
console.error('moved package.json to package.json.old');
|
|
73
|
+
fs.renameSync('./package.json.new', './package.json');
|
|
74
|
+
console.error('moved package.json.new to package.json');
|
|
75
|
+
} else {
|
|
76
|
+
console.error('no changes\n');
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (e) {
|
|
81
|
+
// caught error, exit with status 2 to signify abject failure
|
|
82
|
+
console.error(`\ncaught exception - ${e}\n`);
|
|
83
|
+
process.exitCode = 2;
|
|
84
|
+
} else {
|
|
85
|
+
// caught false, exit with status 1 to signify nothing done
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
}
|
|
88
|
+
} finally {
|
|
89
|
+
console.error('done\n');
|
|
90
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This script will uninstall pre-commit or pre-push hooks in case there's ever a need to
|
|
5
|
+
* commit/push something that has issues
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const precommitPath = '.git/hooks/pre-commit';
|
|
9
|
+
const prepushPath = '.git/hooks/pre-push';
|
|
10
|
+
fs.unlink(precommitPath, (err) => {
|
|
11
|
+
if (err && err.code !== 'ENOENT') {
|
|
12
|
+
console.log(`${err.message}`);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
fs.unlink(prepushPath, (err) => {
|
|
17
|
+
if (err && err.code !== 'ENOENT') {
|
|
18
|
+
console.log(`${err.message}`);
|
|
19
|
+
}
|
|
20
|
+
});
|
package/utils/tbScript.js
CHANGED
|
@@ -15,13 +15,18 @@ const basicGet = require('./basicGet');
|
|
|
15
15
|
const { name } = require('../package.json');
|
|
16
16
|
const sampleProperties = require('../sampleProperties.json');
|
|
17
17
|
const adapterPronghorn = require('../pronghorn.json');
|
|
18
|
+
const { addAuthInfo } = require('./addAuth');
|
|
18
19
|
|
|
19
|
-
const { troubleshoot,
|
|
20
|
+
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
|
20
21
|
|
|
21
22
|
const main = async (command) => {
|
|
22
|
-
const
|
|
23
|
+
const dirname = utils.getDirname();
|
|
24
|
+
const iapDir = path.join(dirname, '../../../');
|
|
23
25
|
if (!utils.withinIAP(iapDir)) {
|
|
24
|
-
if (command === '
|
|
26
|
+
if (command === 'install') {
|
|
27
|
+
console.log('Not currently in IAP directory - installation not possible');
|
|
28
|
+
process.exit(0);
|
|
29
|
+
} else if (command === 'connectivity') {
|
|
25
30
|
const { host } = sampleProperties.properties;
|
|
26
31
|
console.log(`perform networking diagnositics to ${host}`);
|
|
27
32
|
await utils.runConnectivity(host);
|
|
@@ -43,7 +48,7 @@ const main = async (command) => {
|
|
|
43
48
|
if (command === undefined) {
|
|
44
49
|
await troubleshoot({}, true, true);
|
|
45
50
|
} else if (command === 'install') {
|
|
46
|
-
const { database, serviceItem, pronghornProps } = await getAdapterConfig();
|
|
51
|
+
const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
|
|
47
52
|
const filter = { id: pronghornProps.id };
|
|
48
53
|
const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
|
|
49
54
|
if (!profileItem) {
|
|
@@ -74,14 +79,16 @@ const main = async (command) => {
|
|
|
74
79
|
process.exit(0);
|
|
75
80
|
}
|
|
76
81
|
} else {
|
|
77
|
-
utils.verifyInstallationDir(
|
|
78
|
-
utils.npmInstall();
|
|
82
|
+
utils.verifyInstallationDir(dirname, name);
|
|
79
83
|
utils.runTest();
|
|
80
84
|
if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
|
|
81
85
|
console.log('Creating database entries...');
|
|
82
86
|
const adapter = utils.createAdapter(
|
|
83
87
|
pronghornProps, profileItem, sampleProperties, adapterPronghorn
|
|
84
88
|
);
|
|
89
|
+
|
|
90
|
+
adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
|
|
91
|
+
|
|
85
92
|
await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
|
|
86
93
|
profileItem.services.push(adapter.name);
|
|
87
94
|
const update = { $set: { services: profileItem.services } };
|
|
@@ -94,7 +101,7 @@ const main = async (command) => {
|
|
|
94
101
|
process.exit(0);
|
|
95
102
|
}
|
|
96
103
|
} else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
|
|
97
|
-
const { serviceItem } = await getAdapterConfig();
|
|
104
|
+
const { serviceItem } = await utils.getAdapterConfig();
|
|
98
105
|
if (serviceItem) {
|
|
99
106
|
const adapter = serviceItem;
|
|
100
107
|
const a = basicGet.getAdapterInstance(adapter);
|
|
@@ -154,7 +161,6 @@ program.parse(process.argv);
|
|
|
154
161
|
if (process.argv.length < 3) {
|
|
155
162
|
main();
|
|
156
163
|
}
|
|
157
|
-
|
|
158
164
|
const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity'];
|
|
159
165
|
if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
|
|
160
166
|
console.log(`unknown parameter ${process.argv[2]}`);
|
package/utils/tbUtils.js
CHANGED
|
@@ -100,8 +100,8 @@ module.exports = {
|
|
|
100
100
|
*
|
|
101
101
|
* @function decryptProperties
|
|
102
102
|
*/
|
|
103
|
-
decryptProperties: (props,
|
|
104
|
-
const propertyEncryptionClassPath = path.join(
|
|
103
|
+
decryptProperties: (props, iapDir, discovery) => {
|
|
104
|
+
const propertyEncryptionClassPath = path.join(iapDir, 'node_modules/@itential/pronghorn-core/core/PropertyEncryption.js');
|
|
105
105
|
const isEncrypted = props.pathProps.encrypted;
|
|
106
106
|
const PropertyEncryption = discovery.require(propertyEncryptionClassPath, isEncrypted);
|
|
107
107
|
const propertyEncryption = new PropertyEncryption({
|
|
@@ -177,12 +177,12 @@ module.exports = {
|
|
|
177
177
|
verifyInstallationDir: (dirname, name) => {
|
|
178
178
|
const pathArray = dirname.split(path.sep);
|
|
179
179
|
const expectedPath = `node_modules/${name}`;
|
|
180
|
-
const currentPath = pathArray.slice(pathArray.length -
|
|
181
|
-
if (
|
|
182
|
-
throw new Error(`adapter should be installed under ${expectedPath}`);
|
|
180
|
+
const currentPath = pathArray.slice(pathArray.length - 3, pathArray.length).join('/');
|
|
181
|
+
if (currentPath.trim() !== expectedPath.trim()) {
|
|
182
|
+
throw new Error(`adapter should be installed under ${expectedPath} but is installed under ${currentPath}`);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
const serverFile = path.join(dirname, '
|
|
185
|
+
const serverFile = path.join(dirname, '../../../', 'server.js');
|
|
186
186
|
if (!fs.existsSync(serverFile)) {
|
|
187
187
|
throw new Error(`adapter should be installed under IAP/${expectedPath}`);
|
|
188
188
|
}
|
|
@@ -304,8 +304,9 @@ module.exports = {
|
|
|
304
304
|
* @param {Object} adapterPronghorn - ./pronghorn.json in adapter dir
|
|
305
305
|
* @param {Object} sampleProperties - './sampleProperties.json' in adapter dir
|
|
306
306
|
*/
|
|
307
|
-
createAdapter: (pronghornProps, profileItem, sampleProperties, adapterPronghorn)
|
|
308
|
-
const
|
|
307
|
+
createAdapter: function createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn) {
|
|
308
|
+
const dirname = this.getDirname();
|
|
309
|
+
const packagePath = `${dirname.split('node_modules')[0]}package.json`;
|
|
309
310
|
const info = JSON.parse(fs.readFileSync(packagePath));
|
|
310
311
|
const version = parseInt(info.version.split('.')[0], 10);
|
|
311
312
|
|
|
@@ -338,6 +339,37 @@ module.exports = {
|
|
|
338
339
|
return adapter;
|
|
339
340
|
},
|
|
340
341
|
|
|
342
|
+
getPronghornProps: function getPronghornProps(iapDir) {
|
|
343
|
+
console.log('Retrieving properties.json file...');
|
|
344
|
+
const rawProps = require(path.join(iapDir, 'properties.json'));
|
|
345
|
+
console.log('Decrypting properties...');
|
|
346
|
+
const { Discovery } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
|
|
347
|
+
const discovery = new Discovery();
|
|
348
|
+
const pronghornProps = this.decryptProperties(rawProps, iapDir, discovery);
|
|
349
|
+
console.log('Found properties.\n');
|
|
350
|
+
return pronghornProps;
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
// get database connection and existing adapter config
|
|
354
|
+
getAdapterConfig: async function getAdapterConfig() {
|
|
355
|
+
const newDirname = this.getDirname();
|
|
356
|
+
let iapDir;
|
|
357
|
+
if (this.withinIAP(newDirname)) { // when this script is called from IAP
|
|
358
|
+
iapDir = newDirname;
|
|
359
|
+
} else {
|
|
360
|
+
iapDir = path.join(this.getDirname(), 'utils', '../../../../');
|
|
361
|
+
}
|
|
362
|
+
const pronghornProps = this.getPronghornProps(iapDir);
|
|
363
|
+
console.log('Connecting to Database...');
|
|
364
|
+
const database = await this.connect(iapDir, pronghornProps);
|
|
365
|
+
console.log('Connection established.');
|
|
366
|
+
const { name } = require(path.join(__dirname, '..', 'package.json'));
|
|
367
|
+
const serviceItem = await database.collection(this.SERVICE_CONFIGS_COLLECTION).findOne(
|
|
368
|
+
{ model: name }
|
|
369
|
+
);
|
|
370
|
+
return { database, serviceItem, pronghornProps };
|
|
371
|
+
},
|
|
372
|
+
|
|
341
373
|
/**
|
|
342
374
|
* @summary return async healthcheck result as a Promise
|
|
343
375
|
*
|
|
@@ -385,5 +417,35 @@ module.exports = {
|
|
|
385
417
|
} catch (error) {
|
|
386
418
|
return false;
|
|
387
419
|
}
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* @summary Used to determine the proper dirname to return in case adapter reference is
|
|
424
|
+
* symlinked withink IAP
|
|
425
|
+
* @returns the symlinked path (using pwd command) of the adapter in case properties.json
|
|
426
|
+
* is not found in the original path
|
|
427
|
+
* @function getDirname
|
|
428
|
+
*/
|
|
429
|
+
getDirname: function getDirname() {
|
|
430
|
+
if (this.withinIAP(path.join(__dirname, '../../../../'))) {
|
|
431
|
+
return __dirname;
|
|
432
|
+
}
|
|
433
|
+
const { stdout } = this.systemSync('pwd', true);
|
|
434
|
+
return stdout.trim();
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @summary connect to mongodb
|
|
439
|
+
*
|
|
440
|
+
* @function connect
|
|
441
|
+
* @param {Object} properties - pronghornProps
|
|
442
|
+
*/
|
|
443
|
+
connect: async function connect(iapDir, properties) {
|
|
444
|
+
// Connect to Mongo
|
|
445
|
+
const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
|
|
446
|
+
const connection = new MongoDBConnection(properties.mongoProps);
|
|
447
|
+
const database = await connection.connect(true);
|
|
448
|
+
return database;
|
|
388
449
|
}
|
|
450
|
+
|
|
389
451
|
};
|
|
@@ -117,30 +117,6 @@ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
|
|
|
117
117
|
return { result, updatedAdapter };
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
const getPronghornProps = (iapDir) => {
|
|
121
|
-
console.log('Retrieving properties.json file...');
|
|
122
|
-
const rawProps = require(path.join(iapDir, 'properties.json'));
|
|
123
|
-
console.log('Decrypting properties...');
|
|
124
|
-
const { Discovery } = require('@itential/itential-utils');
|
|
125
|
-
const discovery = new Discovery();
|
|
126
|
-
const pronghornProps = utils.decryptProperties(rawProps, __dirname, discovery);
|
|
127
|
-
console.log('Found properties.\n');
|
|
128
|
-
return pronghornProps;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// get database connection and existing adapter config
|
|
132
|
-
const getAdapterConfig = async () => {
|
|
133
|
-
const iapDir = path.join(__dirname, '../../../../');
|
|
134
|
-
const pronghornProps = getPronghornProps(iapDir);
|
|
135
|
-
console.log('Connecting to Database...');
|
|
136
|
-
const database = await basicGet.connect(pronghornProps);
|
|
137
|
-
console.log('Connection established.');
|
|
138
|
-
const serviceItem = await database.collection(utils.SERVICE_CONFIGS_COLLECTION).findOne(
|
|
139
|
-
{ model: name }
|
|
140
|
-
);
|
|
141
|
-
return { database, serviceItem, pronghornProps };
|
|
142
|
-
};
|
|
143
|
-
|
|
144
120
|
const offline = async () => {
|
|
145
121
|
console.log('Start offline troubleshooting');
|
|
146
122
|
const { updatedAdapter } = VerifyHealthCheckEndpoint({ properties: sampleProperties }, {}, true);
|
|
@@ -159,7 +135,7 @@ const offline = async () => {
|
|
|
159
135
|
|
|
160
136
|
const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
|
|
161
137
|
// get database connection and existing adapter config
|
|
162
|
-
const { database, serviceItem } = await getAdapterConfig();
|
|
138
|
+
const { database, serviceItem } = await utils.getAdapterConfig();
|
|
163
139
|
// where troubleshoot should start
|
|
164
140
|
if (serviceItem) {
|
|
165
141
|
if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
|
|
@@ -211,4 +187,4 @@ const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
|
|
|
211
187
|
return null;
|
|
212
188
|
};
|
|
213
189
|
|
|
214
|
-
module.exports = { troubleshoot,
|
|
190
|
+
module.exports = { troubleshoot, offline };
|