@itentialopensource/adapter-f5_bigiq 0.5.7 → 0.6.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/.eslintrc.js +1 -0
- package/AUTH.md +4 -4
- package/BROKER.md +4 -4
- package/CALLS.md +621 -9
- package/ENHANCE.md +3 -3
- package/PROPERTIES.md +24 -9
- package/README.md +24 -23
- package/SUMMARY.md +2 -2
- package/SYSTEMINFO.md +1 -1
- package/TAB1.md +2 -2
- package/TAB2.md +9 -5
- package/TROUBLESHOOT.md +10 -1
- package/UTILITIES.md +473 -0
- package/adapter.js +11315 -5
- package/adapterBase.js +52 -16
- package/entities/BIGIPAuthentication/action.json +106 -0
- package/entities/BIGIPAuthentication/schema.json +23 -0
- package/entities/BIGIPConfigurationManagement/action.json +310 -0
- package/entities/BIGIPConfigurationManagement/schema.json +33 -0
- package/entities/BIGIPLocalTrafficManager/action.json +1042 -0
- package/entities/BIGIPLocalTrafficManager/schema.json +69 -0
- package/entities/BIGIPNetwork/action.json +432 -0
- package/entities/BIGIPNetwork/schema.json +39 -0
- package/entities/BIGIPSystem/action.json +209 -0
- package/entities/BIGIPSystem/schema.json +28 -0
- package/package.json +24 -28
- package/pronghorn.json +5973 -13
- package/propertiesSchema.json +68 -7
- package/report/adapterInfo.json +8 -8
- package/report/auto-adapter-openapi.json +20632 -0
- package/report/updateReport1748555375038.json +120 -0
- package/sampleProperties.json +4 -0
- package/test/integration/adapterTestBasicGet.js +88 -54
- package/test/integration/adapterTestConnectivity.js +15 -16
- package/test/integration/adapterTestIntegration.js +2597 -38
- package/test/unit/adapterBaseTestUnit.js +641 -39
- package/test/unit/adapterTestUnit.js +4822 -61
- package/utils/adapterInfo.js +114 -164
- package/utils/argParser.js +44 -0
- package/utils/checkMigrate.js +77 -38
- package/utils/entitiesToDB.js +53 -42
- package/utils/logger.js +26 -0
- package/utils/modify.js +56 -55
- package/utils/mongoDbConnection.js +79 -0
- package/utils/mongoUtils.js +162 -0
- package/utils/taskMover.js +31 -32
- package/utils/tbScript.js +36 -172
- package/utils/tbUtils.js +84 -226
- package/utils/troubleshootingAdapter.js +68 -84
- package/utils/updateAdapterConfig.js +158 -0
- package/utils/addAuth.js +0 -94
- package/utils/artifactize.js +0 -146
- package/utils/basicGet.js +0 -50
- package/utils/packModificationScript.js +0 -35
- package/utils/patches2bundledDeps.js +0 -90
package/utils/adapterInfo.js
CHANGED
|
@@ -1,20 +1,94 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/* @copyright Itential, LLC
|
|
2
|
+
/* @copyright Itential, LLC 2025 */
|
|
3
|
+
|
|
3
4
|
/* eslint global-require:warn */
|
|
4
5
|
/* eslint import/no-dynamic-require:warn */
|
|
5
6
|
/* eslint prefer-destructuring:warn */
|
|
6
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
|
+
|
|
7
17
|
const path = require('path');
|
|
8
18
|
const fs = require('fs-extra');
|
|
9
19
|
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
|
|
13
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
|
+
}
|
|
14
82
|
|
|
15
83
|
/**
|
|
16
|
-
*
|
|
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
|
|
17
87
|
*/
|
|
88
|
+
function countTestsInFiles(filePaths) {
|
|
89
|
+
return filePaths.reduce((total, filePath) => total + countTestsInFile(filePath), 0);
|
|
90
|
+
}
|
|
91
|
+
|
|
18
92
|
function adapterInfo() {
|
|
19
93
|
// set the base pase of the adapter - tool shoud be one level up in utils
|
|
20
94
|
let adaptdir = __dirname;
|
|
@@ -23,172 +97,43 @@ function adapterInfo() {
|
|
|
23
97
|
if (adaptdir.endsWith('/utils')) {
|
|
24
98
|
adaptdir = adaptdir.substring(0, adaptdir.length - 6);
|
|
25
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
|
+
}
|
|
26
105
|
const pack = require(`${adaptdir}/package.json`);
|
|
27
106
|
infoRes.version = pack.version;
|
|
28
107
|
|
|
29
108
|
let configCount = 0;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
|
|
37
|
-
const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
|
|
38
|
-
configCount += cFile.split('\n').length;
|
|
39
|
-
} else {
|
|
40
|
-
console.log('Missing - propertiesSchema.json');
|
|
41
|
-
}
|
|
42
|
-
if (fs.existsSync(`${adaptdir}/error.json`)) {
|
|
43
|
-
const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
|
|
44
|
-
configCount += cFile.split('\n').length;
|
|
45
|
-
} else {
|
|
46
|
-
console.log('Missing - error.json');
|
|
47
|
-
}
|
|
48
|
-
const entitydir = path.join(adaptdir, '/entities');
|
|
49
|
-
if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
|
|
50
|
-
const entities = fs.readdirSync(entitydir);
|
|
51
|
-
// need to go through each entity in the entities directory
|
|
52
|
-
for (let e = 0; e < entities.length; e += 1) {
|
|
53
|
-
if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
|
|
54
|
-
const cfiles = fs.readdirSync(entitydir);
|
|
55
|
-
for (let c = 0; c < cfiles.length; c += 1) {
|
|
56
|
-
if (cfiles[c].endsWith('.json')) {
|
|
57
|
-
const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
|
|
58
|
-
configCount += ccFile.split('\n').length;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
console.log('Could not find the entities directory');
|
|
65
|
-
}
|
|
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
|
+
|
|
66
115
|
infoRes.configLines = configCount;
|
|
67
116
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
scodeCount += sFile.split('\n').length;
|
|
72
|
-
} else {
|
|
73
|
-
console.log('Missing - utils/artifactize.js');
|
|
74
|
-
}
|
|
75
|
-
if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
|
|
76
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
|
|
77
|
-
scodeCount += sFile.split('\n').length;
|
|
78
|
-
} else {
|
|
79
|
-
console.log('Missing - utils/basicGet.js');
|
|
80
|
-
}
|
|
81
|
-
if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
|
|
82
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
|
|
83
|
-
scodeCount += sFile.split('\n').length;
|
|
84
|
-
} else {
|
|
85
|
-
console.log('Missing - utils/checkMigrate.js');
|
|
86
|
-
}
|
|
87
|
-
if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
|
|
88
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
|
|
89
|
-
scodeCount += sFile.split('\n').length;
|
|
90
|
-
} else {
|
|
91
|
-
console.log('Missing - utils/findPath.js');
|
|
92
|
-
}
|
|
93
|
-
if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
|
|
94
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
|
|
95
|
-
scodeCount += sFile.split('\n').length;
|
|
96
|
-
} else {
|
|
97
|
-
console.log('Missing - utils/modify.js');
|
|
98
|
-
}
|
|
99
|
-
if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
|
|
100
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
|
|
101
|
-
scodeCount += sFile.split('\n').length;
|
|
102
|
-
} else {
|
|
103
|
-
console.log('Missing - utils/packModificationScript.js');
|
|
104
|
-
}
|
|
105
|
-
if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
|
|
106
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
|
|
107
|
-
scodeCount += sFile.split('\n').length;
|
|
108
|
-
} else {
|
|
109
|
-
console.log('Missing - utils/setup.js');
|
|
110
|
-
}
|
|
111
|
-
if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
|
|
112
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
|
|
113
|
-
scodeCount += sFile.split('\n').length;
|
|
114
|
-
} else {
|
|
115
|
-
console.log('Missing - utils/tbScript.js');
|
|
116
|
-
}
|
|
117
|
-
if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
|
|
118
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
|
|
119
|
-
scodeCount += sFile.split('\n').length;
|
|
120
|
-
} else {
|
|
121
|
-
console.log('Missing - utils/tbUtils.js');
|
|
122
|
-
}
|
|
123
|
-
if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
|
|
124
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
|
|
125
|
-
scodeCount += sFile.split('\n').length;
|
|
126
|
-
} else {
|
|
127
|
-
console.log('Missing - utils/testRunner.js');
|
|
128
|
-
}
|
|
129
|
-
if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
|
|
130
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
|
|
131
|
-
scodeCount += sFile.split('\n').length;
|
|
132
|
-
} else {
|
|
133
|
-
console.log('Missing - utils/troubleshootingAdapter.js');
|
|
134
|
-
}
|
|
135
|
-
infoRes.scriptLines = scodeCount;
|
|
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));
|
|
136
120
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
infoRes.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
let ttestCount = 0;
|
|
154
|
-
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
|
|
155
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
|
|
156
|
-
tcodeCount += tFile.split('\n').length;
|
|
157
|
-
ttestCount += tFile.split('it(\'').length;
|
|
158
|
-
} else {
|
|
159
|
-
console.log('Missing - test/integration/adapterTestBasicGet.js');
|
|
160
|
-
}
|
|
161
|
-
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
|
|
162
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
|
|
163
|
-
tcodeCount += tFile.split('\n').length;
|
|
164
|
-
ttestCount += tFile.split('it(\'').length;
|
|
165
|
-
} else {
|
|
166
|
-
console.log('Missing - test/integration/adapterTestConnectivity.js');
|
|
167
|
-
}
|
|
168
|
-
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
|
|
169
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
|
|
170
|
-
tcodeCount += tFile.split('\n').length;
|
|
171
|
-
ttestCount += tFile.split('it(\'').length;
|
|
172
|
-
} else {
|
|
173
|
-
console.log('Missing - test/integration/adapterTestIntegration.js');
|
|
174
|
-
}
|
|
175
|
-
if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
|
|
176
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
|
|
177
|
-
tcodeCount += tFile.split('\n').length;
|
|
178
|
-
ttestCount += tFile.split('it(\'').length;
|
|
179
|
-
} else {
|
|
180
|
-
console.log('Missing - test/unit/adapterBaseTestUnit.js');
|
|
181
|
-
}
|
|
182
|
-
if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
|
|
183
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
|
|
184
|
-
tcodeCount += tFile.split('\n').length;
|
|
185
|
-
ttestCount += tFile.split('it(\'').length;
|
|
186
|
-
} else {
|
|
187
|
-
console.log('Missing - test/unit/adapterTestUnit.js');
|
|
188
|
-
}
|
|
189
|
-
infoRes.testLines = tcodeCount;
|
|
190
|
-
infoRes.testCases = ttestCount;
|
|
191
|
-
infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
|
|
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;
|
|
192
137
|
|
|
193
138
|
if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
194
139
|
// Read the entity schema from the file system
|
|
@@ -203,4 +148,9 @@ function adapterInfo() {
|
|
|
203
148
|
fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
|
|
204
149
|
}
|
|
205
150
|
|
|
206
|
-
|
|
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 };
|
package/utils/checkMigrate.js
CHANGED
|
@@ -1,63 +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
|
+
|
|
1
12
|
const { execSync } = require('child_process');
|
|
2
|
-
const fs = require('fs');
|
|
3
13
|
const semver = require('semver');
|
|
4
|
-
const axios = require('axios');
|
|
5
14
|
const packageJson = require('../package.json');
|
|
15
|
+
const { get } = require('./tbUtils');
|
|
6
16
|
|
|
17
|
+
const localAdaptVer = packageJson.version;
|
|
7
18
|
const localEngineVer = packageJson.engineVersion;
|
|
8
19
|
const localUtils = execSync('npm list @itentialopensource/adapter-utils', { encoding: 'utf-8' });
|
|
9
20
|
const localUtilsVer = localUtils.split('@').pop().replace(/(\r\n|\n|\r| )/gm, '');
|
|
10
21
|
|
|
11
22
|
/**
|
|
12
|
-
* @summary
|
|
23
|
+
* @summary Checks if adapter is the latest version
|
|
13
24
|
*
|
|
14
|
-
* @function
|
|
15
|
-
* @param {String} url - url to make the call to
|
|
25
|
+
* @function updateNeeded
|
|
16
26
|
*/
|
|
17
|
-
function
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
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);
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
/**
|
|
26
|
-
* @summary Checks if adapter
|
|
37
|
+
* @summary Checks if adapter is up-to-date or if migration is needed
|
|
27
38
|
*
|
|
28
|
-
* @function
|
|
39
|
+
* @function migrateNeeded
|
|
29
40
|
*/
|
|
30
|
-
function
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
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);
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
/**
|
|
38
|
-
* @summary Checks if adapter is up-to-date or if
|
|
51
|
+
* @summary Checks if adapter is up-to-date or if remediation is needed
|
|
39
52
|
*
|
|
40
|
-
* @function
|
|
53
|
+
* @function remediationNeeded
|
|
41
54
|
*/
|
|
42
|
-
async function
|
|
43
|
-
const engineUrl = 'https://adapters.itential.io/engineVersion';
|
|
55
|
+
async function remediationNeeded() {
|
|
44
56
|
const utilsUrl = 'https://registry.npmjs.org/@itentialopensource/adapter-utils';
|
|
45
|
-
const latestEngineVer = (await get(engineUrl)).data;
|
|
46
57
|
const latestUtilsVer = (await get(utilsUrl)).data['dist-tags'].latest;
|
|
47
|
-
|
|
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);
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
});
|
package/utils/entitiesToDB.js
CHANGED
|
@@ -16,18 +16,19 @@
|
|
|
16
16
|
|
|
17
17
|
const fs = require('fs');
|
|
18
18
|
const path = require('path');
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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');
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -77,22 +78,23 @@ const buildDoc = (pathstring) => {
|
|
|
77
78
|
/**
|
|
78
79
|
* Function used to get the database from the options or a provided directory
|
|
79
80
|
*/
|
|
80
|
-
const optionsHandler = (options) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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;
|
|
92
97
|
}
|
|
93
|
-
|
|
94
|
-
// if nothing was provided, error
|
|
95
|
-
return new Promise((resolve, reject) => reject(new Error('Neither pronghornProps nor iapDir defined in options!')));
|
|
96
98
|
};
|
|
97
99
|
|
|
98
100
|
/**
|
|
@@ -102,6 +104,7 @@ const moveEntitiesToDB = async (targetPath, options) => {
|
|
|
102
104
|
// set local variables
|
|
103
105
|
let myOpts = options;
|
|
104
106
|
let myPath = targetPath;
|
|
107
|
+
let mongoConnection = null;
|
|
105
108
|
|
|
106
109
|
// if we got a string parse into a JSON object
|
|
107
110
|
if (typeof myOpts === 'string') {
|
|
@@ -118,15 +121,17 @@ const moveEntitiesToDB = async (targetPath, options) => {
|
|
|
118
121
|
throw new Error('Adapter ID required!');
|
|
119
122
|
}
|
|
120
123
|
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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);
|
|
130
135
|
|
|
131
136
|
// verify set the entity path
|
|
132
137
|
const entitiesPath = `${myPath}/entities`;
|
|
@@ -165,15 +170,21 @@ const moveEntitiesToDB = async (targetPath, options) => {
|
|
|
165
170
|
});
|
|
166
171
|
|
|
167
172
|
// Upload documents to db collection
|
|
168
|
-
|
|
169
|
-
if (!
|
|
170
|
-
|
|
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);
|
|
171
176
|
throw new Error('Database not found');
|
|
172
177
|
}
|
|
173
|
-
|
|
174
|
-
const
|
|
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; });
|
|
175
181
|
return res;
|
|
176
|
-
}
|
|
182
|
+
} finally {
|
|
183
|
+
// Ensure connection is closed even if an error occurs
|
|
184
|
+
if (mongoConnection) {
|
|
185
|
+
await tbUtils.closeConnection(mongoConnection);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
177
188
|
};
|
|
178
189
|
|
|
179
190
|
module.exports = { moveEntitiesToDB };
|
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;
|