@itentialopensource/adapter-bluecat_ipam 0.1.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/.eslintignore +5 -0
- package/.eslintrc.js +19 -0
- package/.jshintrc +3 -0
- package/AUTH.md +39 -0
- package/BROKER.md +211 -0
- package/CALLS.md +3069 -0
- package/CHANGELOG.md +9 -0
- package/CODE_OF_CONDUCT.md +43 -0
- package/CONTRIBUTING.md +13 -0
- package/ENHANCE.md +69 -0
- package/LICENSE +201 -0
- package/PROPERTIES.md +681 -0
- package/README.md +344 -0
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +25 -0
- package/TAB1.md +15 -0
- package/TAB2.md +318 -0
- package/TROUBLESHOOT.md +56 -0
- package/UTILITIES.md +473 -0
- package/adapter.js +47832 -0
- package/adapterBase.js +1526 -0
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +53 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/entities/ACLResources/action.json +127 -0
- package/entities/ACLResources/schema.json +24 -0
- package/entities/AdminResources/action.json +1954 -0
- package/entities/AdminResources/schema.json +113 -0
- package/entities/ConfigurationResources/action.json +106 -0
- package/entities/ConfigurationResources/schema.json +23 -0
- package/entities/DHCPClientClassResources/action.json +250 -0
- package/entities/DHCPClientClassResources/schema.json +30 -0
- package/entities/DHCPZoneResources/action.json +250 -0
- package/entities/DHCPZoneResources/schema.json +30 -0
- package/entities/DNSSECResources/action.json +147 -0
- package/entities/DNSSECResources/schema.json +25 -0
- package/entities/DeploymentOptionResources/action.json +250 -0
- package/entities/DeploymentOptionResources/schema.json +30 -0
- package/entities/DeploymentRoleResources/action.json +169 -0
- package/entities/DeploymentRoleResources/schema.json +26 -0
- package/entities/DeviceResources/action.json +352 -0
- package/entities/DeviceResources/schema.json +35 -0
- package/entities/FavoriteResources/action.json +65 -0
- package/entities/FavoriteResources/schema.json +21 -0
- package/entities/IPv4AndIPv6Resources/action.json +1964 -0
- package/entities/IPv4AndIPv6Resources/schema.json +113 -0
- package/entities/KerberosResources/action.json +393 -0
- package/entities/KerberosResources/schema.json +37 -0
- package/entities/LocationResources/action.json +209 -0
- package/entities/LocationResources/schema.json +28 -0
- package/entities/MACAddressAndClientIdentifierResources/action.json +395 -0
- package/entities/MACAddressAndClientIdentifierResources/schema.json +37 -0
- package/entities/NamingPolicyResources/action.json +476 -0
- package/entities/NamingPolicyResources/schema.json +41 -0
- package/entities/ResourceRecordResources/action.json +377 -0
- package/entities/ResourceRecordResources/schema.json +36 -0
- package/entities/ServerResources/action.json +784 -0
- package/entities/ServerResources/schema.json +56 -0
- package/entities/TFTPResources/action.json +250 -0
- package/entities/TFTPResources/schema.json +30 -0
- package/entities/TagResources/action.json +495 -0
- package/entities/TagResources/schema.json +42 -0
- package/entities/TaskResources/action.json +106 -0
- package/entities/TaskResources/schema.json +23 -0
- package/entities/VendorProfileResources/action.json +106 -0
- package/entities/VendorProfileResources/schema.json +23 -0
- package/entities/ViewAndZoneResources/action.json +660 -0
- package/entities/ViewAndZoneResources/schema.json +50 -0
- package/error.json +190 -0
- package/metadata.json +84 -0
- package/package.json +75 -0
- package/pronghorn.json +34480 -0
- package/propertiesDecorators.json +18 -0
- package/propertiesSchema.json +1777 -0
- package/report/Bluecat IPAM 9.5 v2 API.yml-OpenApi3Json.json +114720 -0
- package/report/adapterInfo.json +10 -0
- package/report/auto-adapter-openapi.json +28663 -0
- package/report/creationReport.json +2910 -0
- package/sampleProperties.json +264 -0
- package/test/integration/adapterTestBasicGet.js +117 -0
- package/test/integration/adapterTestConnectivity.js +117 -0
- package/test/integration/adapterTestIntegration.js +12568 -0
- package/test/unit/adapterBaseTestUnit.js +1628 -0
- package/test/unit/adapterTestUnit.js +16058 -0
- package/utils/adapterInfo.js +156 -0
- package/utils/argParser.js +44 -0
- package/utils/checkMigrate.js +102 -0
- package/utils/entitiesToDB.js +190 -0
- package/utils/findPath.js +74 -0
- package/utils/logger.js +26 -0
- package/utils/methodDocumentor.js +298 -0
- package/utils/modify.js +153 -0
- package/utils/mongoDbConnection.js +79 -0
- package/utils/mongoUtils.js +162 -0
- package/utils/pre-commit.sh +32 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/taskMover.js +308 -0
- package/utils/tbScript.js +103 -0
- package/utils/tbUtils.js +347 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +177 -0
- package/utils/updateAdapterConfig.js +158 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2025 */
|
|
3
|
+
|
|
4
|
+
/* eslint global-require:warn */
|
|
5
|
+
/* eslint import/no-dynamic-require:warn */
|
|
6
|
+
/* eslint prefer-destructuring:warn */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This script will determine the information about the adapter and store
|
|
10
|
+
* it into a file in the adapter. This is self contained and only depends on
|
|
11
|
+
* finding files within the adapter to gather information.
|
|
12
|
+
*
|
|
13
|
+
* This utility is used when adapters are committed and pushed. It is not used by
|
|
14
|
+
* any customers nor is it references in any scripts.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const fs = require('fs-extra');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @summary Count the number of lines in a file
|
|
22
|
+
* @param {string} filePath - The path to the file
|
|
23
|
+
* @returns {number} The total number of lines in the file
|
|
24
|
+
*/
|
|
25
|
+
function countLinesInFile(filePath) {
|
|
26
|
+
if (fs.existsSync(filePath)) {
|
|
27
|
+
const cFile = fs.readFileSync(filePath, 'utf8');
|
|
28
|
+
return cFile.split('\n').length;
|
|
29
|
+
}
|
|
30
|
+
console.log(`Missing - ${path.basename(filePath)}`);
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @summary Count the number of lines across multiple files
|
|
36
|
+
* @param {array} filePaths - An array of file paths
|
|
37
|
+
* @returns {number} The total number of lines across all files
|
|
38
|
+
*/
|
|
39
|
+
function countLinesInFiles(filePaths) {
|
|
40
|
+
return filePaths.reduce((total, filePath) => total + countLinesInFile(filePath), 0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @summary Count the number of lines in all json files within an entity directory
|
|
45
|
+
* @param {string} entityDir - The entity directory
|
|
46
|
+
* @returns {number} The total number of lines across all JSON files in the entity directory
|
|
47
|
+
*/
|
|
48
|
+
function countEntityLines(entityDir) {
|
|
49
|
+
let totalLines = 0;
|
|
50
|
+
|
|
51
|
+
if (!fs.existsSync(entityDir)) {
|
|
52
|
+
console.log('Could not find the entities directory');
|
|
53
|
+
return totalLines;
|
|
54
|
+
}
|
|
55
|
+
const entities = fs.readdirSync(entityDir);
|
|
56
|
+
for (let e = 0; e < entities.length; e += 1) {
|
|
57
|
+
const entityPath = path.join(entityDir, entities[e]);
|
|
58
|
+
if (fs.statSync(entityPath).isDirectory()) {
|
|
59
|
+
const jsonFiles = fs.readdirSync(entityPath).filter((f) => f.endsWith('.json'));
|
|
60
|
+
for (let j = 0; j < jsonFiles.length; j += 1) {
|
|
61
|
+
totalLines += countLinesInFile(path.join(entityPath, jsonFiles[j]));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return totalLines;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @summary Count the number of test cases in a file
|
|
70
|
+
* @param {string} filePath - The path to the test file
|
|
71
|
+
* @returns {number} The total number of test cases in the file
|
|
72
|
+
*/
|
|
73
|
+
function countTestsInFile(filePath) {
|
|
74
|
+
if (fs.existsSync(filePath)) {
|
|
75
|
+
const tFile = fs.readFileSync(filePath, 'utf8');
|
|
76
|
+
const ttestCount = tFile.split('it(\'').length;
|
|
77
|
+
return ttestCount;
|
|
78
|
+
}
|
|
79
|
+
console.log(`Missing - ${path.basename(filePath)}`);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @summary Count the number of test cases across multiple files
|
|
85
|
+
* @param {array} filePaths - An array of test file paths
|
|
86
|
+
* @returns {number} The total number of test cases across all files
|
|
87
|
+
*/
|
|
88
|
+
function countTestsInFiles(filePaths) {
|
|
89
|
+
return filePaths.reduce((total, filePath) => total + countTestsInFile(filePath), 0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function adapterInfo() {
|
|
93
|
+
// set the base pase of the adapter - tool shoud be one level up in utils
|
|
94
|
+
let adaptdir = __dirname;
|
|
95
|
+
const infoRes = {};
|
|
96
|
+
|
|
97
|
+
if (adaptdir.endsWith('/utils')) {
|
|
98
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 6);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// if no package.json then not in right place - end with error
|
|
102
|
+
if (!fs.existsSync(`${adaptdir}/package.json`)) {
|
|
103
|
+
throw new Error('Missing - package.json');
|
|
104
|
+
}
|
|
105
|
+
const pack = require(`${adaptdir}/package.json`);
|
|
106
|
+
infoRes.version = pack.version;
|
|
107
|
+
|
|
108
|
+
let configCount = 0;
|
|
109
|
+
const configFiles = ['pronghorn.json', 'propertiesSchema.json', 'error.json'].map((f) => path.join(adaptdir, f));
|
|
110
|
+
configCount = countLinesInFiles(configFiles);
|
|
111
|
+
|
|
112
|
+
const entityDir = path.join(adaptdir, '/entities');
|
|
113
|
+
configCount += countEntityLines(entityDir);
|
|
114
|
+
|
|
115
|
+
infoRes.configLines = configCount;
|
|
116
|
+
|
|
117
|
+
const utilFiles = ['argParser', 'checkMigrate.js', 'entitiesToDB.js', 'findPath.js', 'logger.js', 'methodDocumentor.js', 'modify.js', 'mongoDbConnection.js',
|
|
118
|
+
'mongoUtils.js', 'setup.js', 'taskMover.js', 'tbScript.js', 'tbUtils.js', 'testRunner.js', 'troubleshootingAdapter.js', 'updateAdapterConfig.js'
|
|
119
|
+
].map((f) => path.join(adaptdir, 'utils', f));
|
|
120
|
+
|
|
121
|
+
infoRes.scriptLines = countLinesInFiles(utilFiles);
|
|
122
|
+
|
|
123
|
+
const adapterFiles = ['adapter.js', 'adapterBase.js'].map((f) => path.join(adaptdir, f));
|
|
124
|
+
infoRes.codeLines = countLinesInFiles(adapterFiles);
|
|
125
|
+
|
|
126
|
+
const testFiles = [
|
|
127
|
+
'test/integration/adapterTestBasicGet.js',
|
|
128
|
+
'test/integration/adapterTestConnectivity.js',
|
|
129
|
+
'test/integration/adapterTestIntegration.js',
|
|
130
|
+
'test/unit/adapterBaseTestUnit.js',
|
|
131
|
+
'test/unit/adapterTestUnit.js'
|
|
132
|
+
].map((f) => path.join(adaptdir, f));
|
|
133
|
+
infoRes.testLines = countLinesInFiles(testFiles);
|
|
134
|
+
infoRes.testCases = countTestsInFiles(testFiles);
|
|
135
|
+
|
|
136
|
+
infoRes.totalCodeLines = infoRes.scriptLines + infoRes.codeLines + infoRes.testLines;
|
|
137
|
+
|
|
138
|
+
if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
139
|
+
// Read the entity schema from the file system
|
|
140
|
+
const phFile = path.join(adaptdir, '/pronghorn.json');
|
|
141
|
+
const prong = require(phFile);
|
|
142
|
+
infoRes.wfTasks = prong.methods.length;
|
|
143
|
+
} else {
|
|
144
|
+
console.log('Missing - pronghorn.json');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.log(JSON.stringify(infoRes));
|
|
148
|
+
fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
adapterInfo();
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error(err.message);
|
|
155
|
+
process.exit();
|
|
156
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const customLevels = {
|
|
2
|
+
spam: 6,
|
|
3
|
+
trace: 5,
|
|
4
|
+
debug: 4,
|
|
5
|
+
info: 3,
|
|
6
|
+
warn: 2,
|
|
7
|
+
error: 1,
|
|
8
|
+
none: 0
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function parseArgs(argv = process.argv) {
|
|
12
|
+
let properties = null;
|
|
13
|
+
let logLevel = 'none';
|
|
14
|
+
let maxCalls = 5;
|
|
15
|
+
let host = null;
|
|
16
|
+
|
|
17
|
+
argv.forEach((val) => {
|
|
18
|
+
if (val.startsWith('--PROPS=')) {
|
|
19
|
+
// get the properties
|
|
20
|
+
const inputVal = val.split('=')[1];
|
|
21
|
+
properties = JSON.parse(inputVal);
|
|
22
|
+
} else if (val.startsWith('--LOG=')) {
|
|
23
|
+
// get the desired log level
|
|
24
|
+
const level = val.split('=')[1];
|
|
25
|
+
// validate the log level is supported, if so set it
|
|
26
|
+
if (Object.hasOwnProperty.call(customLevels, level)) {
|
|
27
|
+
logLevel = level;
|
|
28
|
+
}
|
|
29
|
+
} else if (val.startsWith('--MAXCALLS=')) {
|
|
30
|
+
const override = parseInt(val.split('=')[1], 10);
|
|
31
|
+
if (!Number.isNaN(override) && override > 0) {
|
|
32
|
+
maxCalls = override;
|
|
33
|
+
}
|
|
34
|
+
} else if (val.startsWith('--HOST=')) {
|
|
35
|
+
[, host] = val.split('=');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
properties, logLevel, maxCalls, host
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { parseArgs };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/* @copyright Itential, LLC 2025 */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This script will determine if the adapter needs to be upgraded, a migration is needed or
|
|
5
|
+
* a remediation is needed. This is self contained and depends on accessing GitLab repos as well as
|
|
6
|
+
* finding files within the adapter to gather and compare information.
|
|
7
|
+
*
|
|
8
|
+
* This utility is executed from a script in the package.json by `npm run adapter:checkMigrate`. As a result,
|
|
9
|
+
* this utility is exposed and available to customers but exclusively through the CLI.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { execSync } = require('child_process');
|
|
13
|
+
const semver = require('semver');
|
|
14
|
+
const packageJson = require('../package.json');
|
|
15
|
+
const { get } = require('./tbUtils');
|
|
16
|
+
|
|
17
|
+
const localAdaptVer = packageJson.version;
|
|
18
|
+
const localEngineVer = packageJson.engineVersion;
|
|
19
|
+
const localUtils = execSync('npm list @itentialopensource/adapter-utils', { encoding: 'utf-8' });
|
|
20
|
+
const localUtilsVer = localUtils.split('@').pop().replace(/(\r\n|\n|\r| )/gm, '');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @summary Checks if adapter is the latest version
|
|
24
|
+
*
|
|
25
|
+
* @function updateNeeded
|
|
26
|
+
*/
|
|
27
|
+
async function updateNeeded() {
|
|
28
|
+
const adapterUrl = `https://registry.npmjs.org/${packageJson.name}`;
|
|
29
|
+
const latestAdapterVer = (await get(adapterUrl)).data['dist-tags'].latest;
|
|
30
|
+
console.log('\n[Upgrade Check]');
|
|
31
|
+
console.log(`Local Adapter Version : ${localAdaptVer}`);
|
|
32
|
+
console.log(`Latest Adapter Version: ${latestAdapterVer}`);
|
|
33
|
+
return semver.lt(localAdaptVer, latestAdapterVer);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @summary Checks if adapter is up-to-date or if migration is needed
|
|
38
|
+
*
|
|
39
|
+
* @function migrateNeeded
|
|
40
|
+
*/
|
|
41
|
+
async function migrateNeeded() {
|
|
42
|
+
const engineUrl = 'https://adapters.itential.io/engineVersion';
|
|
43
|
+
const latestEngineVer = (await get(engineUrl)).data;
|
|
44
|
+
console.log('\n[Migration Check]');
|
|
45
|
+
console.log(`Local Engine Version : ${localEngineVer}`);
|
|
46
|
+
console.log(`Latest Engine Version: ${latestEngineVer}`);
|
|
47
|
+
return semver.lt(localEngineVer, latestEngineVer);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @summary Checks if adapter is up-to-date or if remediation is needed
|
|
52
|
+
*
|
|
53
|
+
* @function remediationNeeded
|
|
54
|
+
*/
|
|
55
|
+
async function remediationNeeded() {
|
|
56
|
+
const utilsUrl = 'https://registry.npmjs.org/@itentialopensource/adapter-utils';
|
|
57
|
+
const latestUtilsVer = (await get(utilsUrl)).data['dist-tags'].latest;
|
|
58
|
+
console.log('\n[Remediation Check]');
|
|
59
|
+
console.log(`Local Utils Version : ${localUtilsVer}`);
|
|
60
|
+
console.log(`Latest Utils Version: ${latestUtilsVer}`);
|
|
61
|
+
return semver.lt(localUtilsVer, latestUtilsVer);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @summary Main Script (rest of file)
|
|
66
|
+
*
|
|
67
|
+
* Input - None
|
|
68
|
+
* Process - gets the adapter version from the package.json and compares it to the latest version of the adapter,
|
|
69
|
+
* then get the engine version from the package.json and compare it to the adapter engine version in the repo.
|
|
70
|
+
* then get the local adapter-utils version and compare that to the latest version of adapter-utils.
|
|
71
|
+
* Output - console logs providing state and path forward
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
updateNeeded().then((needed) => {
|
|
75
|
+
if (needed) {
|
|
76
|
+
console.log('You should update the adapter to the latest available version -- git pull');
|
|
77
|
+
} else {
|
|
78
|
+
console.log('Update is not needed at the current time.');
|
|
79
|
+
}
|
|
80
|
+
}).catch((error) => {
|
|
81
|
+
console.log('Could not get latest adapter version. Confirm the adapter is an open source adapter.', error.message);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
migrateNeeded().then((needed) => {
|
|
85
|
+
if (needed) {
|
|
86
|
+
console.log('Migration is needed -- if open source, request Itential migrate the adapter');
|
|
87
|
+
} else {
|
|
88
|
+
console.log('Migration is not needed at the current time.');
|
|
89
|
+
}
|
|
90
|
+
}).catch((error) => {
|
|
91
|
+
console.log('Could not get latest engine version. Confirm the adapter was built by the Itential Adapter Builder.', error.message);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
remediationNeeded().then((needed) => {
|
|
95
|
+
if (needed) {
|
|
96
|
+
console.log('Remediation is needed -- update the version of adapter-utils in the package.json, remove node modules and package-lock and run npm install');
|
|
97
|
+
} else {
|
|
98
|
+
console.log('Remediation is not needed at the current time.');
|
|
99
|
+
}
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
console.log('Could not get latest utils version. Confirm the adapter utilizes the Itential adapter foundation.', error.message);
|
|
102
|
+
});
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
/* eslint no-promise-executor-return: warn */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This script is used to read through an adapter's entities files
|
|
14
|
+
* and then creates documents and enters them into the IAP mongodb
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const tbUtils = require('./tbUtils');
|
|
20
|
+
const mongoUtils = require('./mongoUtils');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Function to load sample properties from the file system
|
|
24
|
+
*/
|
|
25
|
+
const loadSampleProperties = async () => {
|
|
26
|
+
const samplePath = path.join(__dirname, '../sampleProperties.json');
|
|
27
|
+
if (fs.existsSync(samplePath)) {
|
|
28
|
+
const fullProps = JSON.parse(fs.readFileSync(samplePath, 'utf-8'));
|
|
29
|
+
return fullProps.properties.mongo;
|
|
30
|
+
}
|
|
31
|
+
throw new Error('sampleProperties.json not found');
|
|
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 = async (options) => {
|
|
82
|
+
try {
|
|
83
|
+
// Try mongo properties from service config first
|
|
84
|
+
const mongoPronghornProps = options?.pronghornProps?.mongo;
|
|
85
|
+
const validatedPronghornProps = mongoPronghornProps ? mongoUtils.getAndValidateMongoProps(mongoPronghornProps) : undefined;
|
|
86
|
+
if (validatedPronghornProps) return validatedPronghornProps;
|
|
87
|
+
|
|
88
|
+
// Fallback to sample properties
|
|
89
|
+
const sampleProps = await loadSampleProperties();
|
|
90
|
+
const validatedSampleProps = mongoUtils.getAndValidateMongoProps(sampleProps);
|
|
91
|
+
if (validatedSampleProps) return validatedSampleProps;
|
|
92
|
+
|
|
93
|
+
throw new Error('No mongo properties provided! Need either a complete URL or both host and database');
|
|
94
|
+
} catch (error) {
|
|
95
|
+
log.error('Error in optionsHandler:', error.message);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Function used to put the adapter configuration into the provided database
|
|
102
|
+
*/
|
|
103
|
+
const moveEntitiesToDB = async (targetPath, options) => {
|
|
104
|
+
// set local variables
|
|
105
|
+
let myOpts = options;
|
|
106
|
+
let myPath = targetPath;
|
|
107
|
+
let mongoConnection = null;
|
|
108
|
+
|
|
109
|
+
// if we got a string parse into a JSON object
|
|
110
|
+
if (typeof myOpts === 'string') {
|
|
111
|
+
myOpts = JSON.parse(myOpts);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// if there is no target collection - set the collection to the default
|
|
115
|
+
if (!myOpts.targetCollection) {
|
|
116
|
+
myOpts.targetCollection = 'adapter_configs';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// if there is no id error since we need an id for the entities
|
|
120
|
+
if (!myOpts.id) {
|
|
121
|
+
throw new Error('Adapter ID required!');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Check valid filepath provided
|
|
125
|
+
if (!myPath) {
|
|
126
|
+
// if no path use the current directory without the utils
|
|
127
|
+
myPath = path.join(__dirname, '../');
|
|
128
|
+
} else if (myPath.slice(-1) === '/') {
|
|
129
|
+
myPath = myPath.slice(0, -1);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
// get the database properties from adapter service instance configs
|
|
134
|
+
const currentProps = await optionsHandler(options);
|
|
135
|
+
|
|
136
|
+
// verify set the entity path
|
|
137
|
+
const entitiesPath = `${myPath}/entities`;
|
|
138
|
+
if (!fs.existsSync(entitiesPath)) {
|
|
139
|
+
throw new Error(`Entities path does not exist in filesystem: ${entitiesPath}`);
|
|
140
|
+
} else {
|
|
141
|
+
log.trace('Target found on filesystem');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Get adapter details
|
|
145
|
+
if (!fs.existsSync(`${myPath}/pronghorn.json`)) {
|
|
146
|
+
throw new Error(`pronghorn.json does not exist in path: ${myPath}`);
|
|
147
|
+
} else {
|
|
148
|
+
log.trace('pronghorn.json found on filesystem');
|
|
149
|
+
}
|
|
150
|
+
const adapterData = JSON.parse(fs.readFileSync(`${myPath}/pronghorn.json`));
|
|
151
|
+
|
|
152
|
+
// Load files from the filesystem
|
|
153
|
+
const docs = [];
|
|
154
|
+
const entities = fs.readdirSync(entitiesPath);
|
|
155
|
+
entities.forEach((entity) => {
|
|
156
|
+
const entityPath = `${entitiesPath}/${entity}`;
|
|
157
|
+
const isDir = fs.lstatSync(entitiesPath).isDirectory();
|
|
158
|
+
|
|
159
|
+
// Build doc for entity
|
|
160
|
+
if (isDir) {
|
|
161
|
+
let doc = buildDoc(entityPath);
|
|
162
|
+
doc = {
|
|
163
|
+
id: myOpts.id,
|
|
164
|
+
type: adapterData.id,
|
|
165
|
+
entity,
|
|
166
|
+
...doc
|
|
167
|
+
};
|
|
168
|
+
docs.push(doc);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Upload documents to db collection
|
|
173
|
+
mongoConnection = await tbUtils.connect(currentProps).catch((err) => { log.error(err); throw err; });
|
|
174
|
+
if (!mongoConnection) {
|
|
175
|
+
log.error('Error occurred when connecting to database', currentProps);
|
|
176
|
+
throw new Error('Database not found');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const collection = mongoConnection.db.collection(myOpts.targetCollection);
|
|
180
|
+
const res = await collection.insertMany(docs, { checkKeys: false }).catch((err) => { log.error(err); throw err; });
|
|
181
|
+
return res;
|
|
182
|
+
} finally {
|
|
183
|
+
// Ensure connection is closed even if an error occurs
|
|
184
|
+
if (mongoConnection) {
|
|
185
|
+
await tbUtils.closeConnection(mongoConnection);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
module.exports = { moveEntitiesToDB };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
/* eslint global-require:warn */
|
|
4
|
+
/* eslint import/no-dynamic-require:warn */
|
|
5
|
+
/* eslint prefer-destructuring:warn */
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs-extra');
|
|
9
|
+
const rls = require('readline-sync');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This script will determine the type of integration test to run
|
|
13
|
+
* based on input. If other information is needed, it will solicit
|
|
14
|
+
* that input and then edit the integration test accordingly.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Updates the action files
|
|
19
|
+
*/
|
|
20
|
+
function checkActionFiles(apath) {
|
|
21
|
+
// verify the path
|
|
22
|
+
if (!apath) {
|
|
23
|
+
console.log(' NO PATH PROVIDED!');
|
|
24
|
+
return 'Done';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// make sure the entities directory exists
|
|
28
|
+
const entitydir = path.join(__dirname, '../entities');
|
|
29
|
+
if (!fs.statSync(entitydir).isDirectory()) {
|
|
30
|
+
console.log('Could not find the entities directory');
|
|
31
|
+
return 'error';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const entities = fs.readdirSync(entitydir);
|
|
35
|
+
let found = false;
|
|
36
|
+
|
|
37
|
+
// need to go through each entity in the entities directory
|
|
38
|
+
for (let e = 0; e < entities.length; e += 1) {
|
|
39
|
+
// make sure the entity is a directory - do not care about extra files
|
|
40
|
+
// only entities (dir)
|
|
41
|
+
if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
|
|
42
|
+
// see if the action file exists in the entity
|
|
43
|
+
if (fs.existsSync(`${entitydir}/${entities[e]}/action.json`)) {
|
|
44
|
+
// Read the entity actions from the file system
|
|
45
|
+
const actions = require(`${entitydir}/${entities[e]}/action.json`);
|
|
46
|
+
|
|
47
|
+
// go through all of the actions set the appropriate info in the newActions
|
|
48
|
+
for (let a = 0; a < actions.actions.length; a += 1) {
|
|
49
|
+
if (actions.actions[a].entitypath.indexOf(apath) >= 0) {
|
|
50
|
+
found = true;
|
|
51
|
+
console.log(` Found - entity: ${entities[e]} action: ${actions.actions[a].name}`);
|
|
52
|
+
console.log(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
|
|
53
|
+
console.log(' ');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
console.log(`Could not find entities ${entities[e]} action.json file`);
|
|
58
|
+
return 'error';
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
console.log(`Could not find entities ${entities[e]} directory`);
|
|
62
|
+
return 'error';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!found) {
|
|
67
|
+
console.log(' PATH NOT FOUND!');
|
|
68
|
+
}
|
|
69
|
+
return 'Done';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const findPath = rls.question('Enter the path/partial path you are looking for: ');
|
|
73
|
+
console.log(`PATH: ${findPath}`);
|
|
74
|
+
checkActionFiles(findPath);
|
package/utils/logger.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// utils/logger.js
|
|
2
|
+
const winston = require('winston');
|
|
3
|
+
const { parseArgs } = require('./argParser');
|
|
4
|
+
|
|
5
|
+
const customLevels = {
|
|
6
|
+
spam: 6,
|
|
7
|
+
trace: 5,
|
|
8
|
+
debug: 4,
|
|
9
|
+
info: 3,
|
|
10
|
+
warn: 2,
|
|
11
|
+
error: 1,
|
|
12
|
+
none: 0
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Only set global logger if it doesn't already exist (i.e., not provided by app)
|
|
16
|
+
if (!global.log) {
|
|
17
|
+
const { logLevel = 'info' } = parseArgs();
|
|
18
|
+
|
|
19
|
+
global.log = winston.createLogger({
|
|
20
|
+
level: logLevel,
|
|
21
|
+
levels: customLevels,
|
|
22
|
+
transports: [new winston.transports.Console()]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = global.log;
|