@itentialopensource/adapter-netbox_v210 0.1.1 → 0.2.1
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 +24 -1
- package/adapter.js +551 -1
- package/adapterBase.js +23 -1
- package/entities/.generic/action.json +5 -5
- package/entities/Graphql/action.json +25 -0
- package/entities/Graphql/schema.json +19 -0
- package/package.json +11 -7
- package/pronghorn.json +226 -0
- package/propertiesSchema.json +1 -1
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1644852199348.json +95 -0
- package/test/integration/adapterTestIntegration.js +28 -0
- package/test/unit/adapterBaseTestUnit.js +1 -1
- package/test/unit/adapterTestUnit.js +131 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +0 -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
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 };
|