@itentialopensource/adapter-nokia_altiplano 0.1.3 → 0.2.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/AUTH.md +37 -0
- package/CALLS.md +95 -0
- package/CHANGELOG.md +8 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +241 -0
- package/SUMMARY.md +9 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +469 -1
- package/adapterBase.js +1 -1
- package/package.json +3 -3
- package/pronghorn.json +192 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1647623246588.json +95 -0
- package/sampleProperties.json +2 -2
- package/test/integration/adapterTestIntegration.js +3 -0
- package/test/unit/adapterTestUnit.js +96 -0
- package/utils/basicGet.js +0 -17
- package/utils/modify.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/tbScript.js +4 -4
- package/utils/tbUtils.js +51 -6
- package/utils/troubleshootingAdapter.js +2 -26
package/pronghorn.json
CHANGED
|
@@ -386,6 +386,198 @@
|
|
|
386
386
|
},
|
|
387
387
|
"task": true
|
|
388
388
|
},
|
|
389
|
+
{
|
|
390
|
+
"name": "moveEntitiesToDB",
|
|
391
|
+
"summary": "Moves entities from an adapter into the IAP database",
|
|
392
|
+
"description": "Moves entities from an adapter into the IAP database",
|
|
393
|
+
"input": [],
|
|
394
|
+
"output": {
|
|
395
|
+
"name": "res",
|
|
396
|
+
"type": "object",
|
|
397
|
+
"description": "A JSON Object containing status, code and the response from the mongo transaction",
|
|
398
|
+
"schema": {
|
|
399
|
+
"title": "res",
|
|
400
|
+
"type": "object"
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
"roles": [
|
|
404
|
+
"admin"
|
|
405
|
+
],
|
|
406
|
+
"route": {
|
|
407
|
+
"verb": "POST",
|
|
408
|
+
"path": "/moveEntitiesToDB"
|
|
409
|
+
},
|
|
410
|
+
"task": true
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
"name": "getDevice",
|
|
414
|
+
"summary": "Get the Appliance",
|
|
415
|
+
"description": "Get the Appliance",
|
|
416
|
+
"input": [
|
|
417
|
+
{
|
|
418
|
+
"name": "deviceName",
|
|
419
|
+
"type": "string",
|
|
420
|
+
"info": "An Appliance Device Name",
|
|
421
|
+
"required": true,
|
|
422
|
+
"schema": {
|
|
423
|
+
"title": "deviceName",
|
|
424
|
+
"type": "string"
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
"output": {
|
|
429
|
+
"name": "result",
|
|
430
|
+
"type": "object",
|
|
431
|
+
"description": "A JSON Object containing status, code and the result",
|
|
432
|
+
"schema": {
|
|
433
|
+
"title": "result",
|
|
434
|
+
"type": "object"
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
"roles": [
|
|
438
|
+
"admin"
|
|
439
|
+
],
|
|
440
|
+
"route": {
|
|
441
|
+
"verb": "POST",
|
|
442
|
+
"path": "/getDevice"
|
|
443
|
+
},
|
|
444
|
+
"task": false
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
"name": "getDevicesFiltered",
|
|
448
|
+
"summary": "Get Appliances that match the filter",
|
|
449
|
+
"description": "Get Appliances that match the filter",
|
|
450
|
+
"input": [
|
|
451
|
+
{
|
|
452
|
+
"name": "options",
|
|
453
|
+
"type": "object",
|
|
454
|
+
"info": "options - e.g. { 'start': 1, 'limit': 20, 'filter': { 'name': 'abc123' } }",
|
|
455
|
+
"required": true,
|
|
456
|
+
"schema": {
|
|
457
|
+
"title": "options",
|
|
458
|
+
"type": "object"
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
],
|
|
462
|
+
"output": {
|
|
463
|
+
"name": "result",
|
|
464
|
+
"type": "array",
|
|
465
|
+
"description": "A JSON Object containing status, code and the result",
|
|
466
|
+
"schema": {
|
|
467
|
+
"title": "result",
|
|
468
|
+
"type": "array"
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
"roles": [
|
|
472
|
+
"admin"
|
|
473
|
+
],
|
|
474
|
+
"route": {
|
|
475
|
+
"verb": "POST",
|
|
476
|
+
"path": "/getDevicesFiltered"
|
|
477
|
+
},
|
|
478
|
+
"task": false
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
"name": "isAlive",
|
|
482
|
+
"summary": "Checks the status for the provided Appliance",
|
|
483
|
+
"description": "Checks the status for the provided Appliance",
|
|
484
|
+
"input": [
|
|
485
|
+
{
|
|
486
|
+
"name": "deviceName",
|
|
487
|
+
"type": "string",
|
|
488
|
+
"info": "An Appliance Device Name",
|
|
489
|
+
"required": true,
|
|
490
|
+
"schema": {
|
|
491
|
+
"title": "deviceName",
|
|
492
|
+
"type": "string"
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
],
|
|
496
|
+
"output": {
|
|
497
|
+
"name": "result",
|
|
498
|
+
"type": "boolean",
|
|
499
|
+
"description": "A JSON Object containing status, code and the result",
|
|
500
|
+
"schema": {
|
|
501
|
+
"title": "result",
|
|
502
|
+
"type": "boolean"
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
"roles": [
|
|
506
|
+
"admin"
|
|
507
|
+
],
|
|
508
|
+
"route": {
|
|
509
|
+
"verb": "POST",
|
|
510
|
+
"path": "/isAlive"
|
|
511
|
+
},
|
|
512
|
+
"task": false
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
"name": "getConfig",
|
|
516
|
+
"summary": "Gets a config for the provided Appliance",
|
|
517
|
+
"description": "Gets a config for the provided Appliance",
|
|
518
|
+
"input": [
|
|
519
|
+
{
|
|
520
|
+
"name": "deviceName",
|
|
521
|
+
"type": "string",
|
|
522
|
+
"info": "An Appliance Device Name",
|
|
523
|
+
"required": true,
|
|
524
|
+
"schema": {
|
|
525
|
+
"title": "deviceName",
|
|
526
|
+
"type": "string"
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
"name": "format",
|
|
531
|
+
"type": "string",
|
|
532
|
+
"info": "The format to be returned - this is ignored as we always return json",
|
|
533
|
+
"required": false,
|
|
534
|
+
"schema": {
|
|
535
|
+
"title": "format",
|
|
536
|
+
"type": "string"
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
],
|
|
540
|
+
"output": {
|
|
541
|
+
"name": "result",
|
|
542
|
+
"type": "object",
|
|
543
|
+
"description": "A JSON Object containing status, code and the result",
|
|
544
|
+
"schema": {
|
|
545
|
+
"title": "result",
|
|
546
|
+
"type": "object"
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
"roles": [
|
|
550
|
+
"admin"
|
|
551
|
+
],
|
|
552
|
+
"route": {
|
|
553
|
+
"verb": "POST",
|
|
554
|
+
"path": "/getConfig"
|
|
555
|
+
},
|
|
556
|
+
"task": false
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
"name": "getCount",
|
|
560
|
+
"summary": "Gets a device count from the system",
|
|
561
|
+
"description": "Gets a device count from the system",
|
|
562
|
+
"input": [],
|
|
563
|
+
"output": {
|
|
564
|
+
"name": "result",
|
|
565
|
+
"type": "object",
|
|
566
|
+
"description": "A JSON Object containing status, code and the result",
|
|
567
|
+
"schema": {
|
|
568
|
+
"title": "result",
|
|
569
|
+
"type": "object"
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
"roles": [
|
|
573
|
+
"admin"
|
|
574
|
+
],
|
|
575
|
+
"route": {
|
|
576
|
+
"verb": "POST",
|
|
577
|
+
"path": "/getCount"
|
|
578
|
+
},
|
|
579
|
+
"task": false
|
|
580
|
+
},
|
|
389
581
|
{
|
|
390
582
|
"name": "getAccessToken",
|
|
391
583
|
"summary": "GetAccessToken",
|
|
Binary file
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"errors": [],
|
|
3
|
+
"statistics": [
|
|
4
|
+
{
|
|
5
|
+
"owner": "errorJson",
|
|
6
|
+
"description": "New adapter errors available for use",
|
|
7
|
+
"value": 0
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"owner": "errorJson",
|
|
11
|
+
"description": "Adapter errors no longer available for use",
|
|
12
|
+
"value": 0
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"owner": "errorJson",
|
|
16
|
+
"description": "Adapter errors that have been updated (e.g. recommendation changes)",
|
|
17
|
+
"value": 30
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"owner": "packageJson",
|
|
21
|
+
"description": "Number of production dependencies",
|
|
22
|
+
"value": 13
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"owner": "packageJson",
|
|
26
|
+
"description": "Number of development dependencies",
|
|
27
|
+
"value": 7
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"owner": "packageJson",
|
|
31
|
+
"description": "Number of npm scripts",
|
|
32
|
+
"value": 23
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"owner": "packageJson",
|
|
36
|
+
"description": "Runtime Library dependency",
|
|
37
|
+
"value": "^4.44.11"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"owner": "propertiesSchemaJson",
|
|
41
|
+
"description": "Adapter properties defined in the propertiesSchema file",
|
|
42
|
+
"value": 64
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"owner": "readmeMd",
|
|
46
|
+
"description": "Number of lines in the README.md",
|
|
47
|
+
"value": 688
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"owner": "unitTestJS",
|
|
51
|
+
"description": "Number of lines of code in unit tests",
|
|
52
|
+
"value": 1822
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"owner": "unitTestJS",
|
|
56
|
+
"description": "Number of unit tests",
|
|
57
|
+
"value": 86
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"owner": "integrationTestJS",
|
|
61
|
+
"description": "Number of lines of code in integration tests",
|
|
62
|
+
"value": 859
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"owner": "integrationTestJS",
|
|
66
|
+
"description": "Number of integration tests",
|
|
67
|
+
"value": 20
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"owner": "staticFile",
|
|
71
|
+
"description": "Number of lines of code in adapterBase.js",
|
|
72
|
+
"value": 1029
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"owner": "staticFile",
|
|
76
|
+
"description": "Number of static files added",
|
|
77
|
+
"value": 34
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"owner": "Overall",
|
|
81
|
+
"description": "Total lines of Code",
|
|
82
|
+
"value": 3710
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"owner": "Overall",
|
|
86
|
+
"description": "Total Tests",
|
|
87
|
+
"value": 106
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"owner": "Overall",
|
|
91
|
+
"description": "Total Files",
|
|
92
|
+
"value": 6
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
package/sampleProperties.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"base_path": "/rest",
|
|
8
8
|
"version": "",
|
|
9
9
|
"cache_location": "none",
|
|
10
|
-
"encode_pathvars":
|
|
10
|
+
"encode_pathvars": false,
|
|
11
11
|
"save_metric": true,
|
|
12
12
|
"stub": true,
|
|
13
13
|
"protocol": "https",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"token_cache": "local",
|
|
21
21
|
"invalid_token_error": 401,
|
|
22
22
|
"auth_field": "header.headers.Authorization",
|
|
23
|
-
"auth_field_format": "{token}",
|
|
23
|
+
"auth_field_format": "Bearer {token}",
|
|
24
24
|
"auth_logging": false,
|
|
25
25
|
"client_id": "",
|
|
26
26
|
"client_secret": "",
|
|
@@ -13,7 +13,10 @@ const winston = require('winston');
|
|
|
13
13
|
const { expect } = require('chai');
|
|
14
14
|
const { use } = require('chai');
|
|
15
15
|
const td = require('testdouble');
|
|
16
|
+
const util = require('util');
|
|
17
|
+
const pronghorn = require('../../pronghorn.json');
|
|
16
18
|
|
|
19
|
+
pronghorn.methodsByName = pronghorn.methods.reduce((result, meth) => ({ ...result, [meth.name]: meth }), {});
|
|
17
20
|
const anything = td.matchers.anything();
|
|
18
21
|
|
|
19
22
|
// stub and attemptTimeout are used throughout the code so set them here
|
|
@@ -1132,6 +1132,18 @@ describe('[unit] Nokia_altiplano Adapter Test', () => {
|
|
|
1132
1132
|
});
|
|
1133
1133
|
});
|
|
1134
1134
|
|
|
1135
|
+
describe('#moveEntitiesToDB', () => {
|
|
1136
|
+
it('should have a moveEntitiesToDB function', (done) => {
|
|
1137
|
+
try {
|
|
1138
|
+
assert.equal(true, typeof a.moveEntitiesToDB === 'function');
|
|
1139
|
+
done();
|
|
1140
|
+
} catch (error) {
|
|
1141
|
+
log.error(`Test Failure: ${error}`);
|
|
1142
|
+
done(error);
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1135
1147
|
describe('#checkActionFiles', () => {
|
|
1136
1148
|
it('should have a checkActionFiles function', (done) => {
|
|
1137
1149
|
try {
|
|
@@ -1261,6 +1273,90 @@ describe('[unit] Nokia_altiplano Adapter Test', () => {
|
|
|
1261
1273
|
// }).timeout(attemptTimeout);
|
|
1262
1274
|
// });
|
|
1263
1275
|
|
|
1276
|
+
describe('#hasEntities', () => {
|
|
1277
|
+
it('should have a hasEntities function', (done) => {
|
|
1278
|
+
try {
|
|
1279
|
+
assert.equal(true, typeof a.hasEntities === 'function');
|
|
1280
|
+
done();
|
|
1281
|
+
} catch (error) {
|
|
1282
|
+
log.error(`Test Failure: ${error}`);
|
|
1283
|
+
done(error);
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
});
|
|
1287
|
+
|
|
1288
|
+
describe('#hasDevices', () => {
|
|
1289
|
+
it('should have a hasDevices function', (done) => {
|
|
1290
|
+
try {
|
|
1291
|
+
assert.equal(true, typeof a.hasDevices === 'function');
|
|
1292
|
+
done();
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
log.error(`Test Failure: ${error}`);
|
|
1295
|
+
done(error);
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
describe('#getDevice', () => {
|
|
1301
|
+
it('should have a getDevice function', (done) => {
|
|
1302
|
+
try {
|
|
1303
|
+
assert.equal(true, typeof a.getDevice === 'function');
|
|
1304
|
+
done();
|
|
1305
|
+
} catch (error) {
|
|
1306
|
+
log.error(`Test Failure: ${error}`);
|
|
1307
|
+
done(error);
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
describe('#getDevicesFiltered', () => {
|
|
1313
|
+
it('should have a getDevicesFiltered function', (done) => {
|
|
1314
|
+
try {
|
|
1315
|
+
assert.equal(true, typeof a.getDevicesFiltered === 'function');
|
|
1316
|
+
done();
|
|
1317
|
+
} catch (error) {
|
|
1318
|
+
log.error(`Test Failure: ${error}`);
|
|
1319
|
+
done(error);
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
describe('#isAlive', () => {
|
|
1325
|
+
it('should have a isAlive function', (done) => {
|
|
1326
|
+
try {
|
|
1327
|
+
assert.equal(true, typeof a.isAlive === 'function');
|
|
1328
|
+
done();
|
|
1329
|
+
} catch (error) {
|
|
1330
|
+
log.error(`Test Failure: ${error}`);
|
|
1331
|
+
done(error);
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
describe('#getConfig', () => {
|
|
1337
|
+
it('should have a getConfig function', (done) => {
|
|
1338
|
+
try {
|
|
1339
|
+
assert.equal(true, typeof a.getConfig === 'function');
|
|
1340
|
+
done();
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
log.error(`Test Failure: ${error}`);
|
|
1343
|
+
done(error);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
});
|
|
1347
|
+
|
|
1348
|
+
describe('#getCount', () => {
|
|
1349
|
+
it('should have a getCount function', (done) => {
|
|
1350
|
+
try {
|
|
1351
|
+
assert.equal(true, typeof a.getCount === 'function');
|
|
1352
|
+
done();
|
|
1353
|
+
} catch (error) {
|
|
1354
|
+
log.error(`Test Failure: ${error}`);
|
|
1355
|
+
done(error);
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
});
|
|
1359
|
+
|
|
1264
1360
|
/*
|
|
1265
1361
|
-----------------------------------------------------------------------
|
|
1266
1362
|
-----------------------------------------------------------------------
|
package/utils/basicGet.js
CHANGED
|
@@ -6,11 +6,8 @@
|
|
|
6
6
|
/* eslint import/no-unresolved: warn */
|
|
7
7
|
/* eslint import/no-dynamic-require: warn */
|
|
8
8
|
|
|
9
|
-
const path = require('path');
|
|
10
9
|
const winston = require('winston');
|
|
11
10
|
|
|
12
|
-
const utils = require(path.join(__dirname, 'tbUtils'));
|
|
13
|
-
|
|
14
11
|
const logLevel = 'none';
|
|
15
12
|
const myCustomLevels = {
|
|
16
13
|
levels: {
|
|
@@ -47,20 +44,6 @@ const basicGet = {
|
|
|
47
44
|
adapter.id,
|
|
48
45
|
adapterProps
|
|
49
46
|
);
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @summary connect to mongodb
|
|
54
|
-
*
|
|
55
|
-
* @function connect
|
|
56
|
-
* @param {Object} properties - pronghornProps
|
|
57
|
-
*/
|
|
58
|
-
connect: async function connect(properties) {
|
|
59
|
-
// Connect to Mongo
|
|
60
|
-
const { MongoDBConnection } = require(path.join(utils.getDirname(), '../../../', '@itential/database'));
|
|
61
|
-
const connection = new MongoDBConnection(properties.mongoProps);
|
|
62
|
-
const database = await connection.connect(true);
|
|
63
|
-
return database;
|
|
64
47
|
}
|
|
65
48
|
};
|
|
66
49
|
|
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
|
+
}
|
package/utils/tbScript.js
CHANGED
|
@@ -17,11 +17,11 @@ const sampleProperties = require('../sampleProperties.json');
|
|
|
17
17
|
const adapterPronghorn = require('../pronghorn.json');
|
|
18
18
|
const { addAuthInfo } = require('./addAuth');
|
|
19
19
|
|
|
20
|
-
const { troubleshoot,
|
|
20
|
+
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
|
21
21
|
|
|
22
22
|
const main = async (command) => {
|
|
23
23
|
const dirname = utils.getDirname();
|
|
24
|
-
const iapDir = path.join(dirname, '
|
|
24
|
+
const iapDir = path.join(dirname, '../../../');
|
|
25
25
|
if (!utils.withinIAP(iapDir)) {
|
|
26
26
|
if (command === 'install') {
|
|
27
27
|
console.log('Not currently in IAP directory - installation not possible');
|
|
@@ -48,7 +48,7 @@ const main = async (command) => {
|
|
|
48
48
|
if (command === undefined) {
|
|
49
49
|
await troubleshoot({}, true, true);
|
|
50
50
|
} else if (command === 'install') {
|
|
51
|
-
const { database, serviceItem, pronghornProps } = await getAdapterConfig();
|
|
51
|
+
const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
|
|
52
52
|
const filter = { id: pronghornProps.id };
|
|
53
53
|
const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
|
|
54
54
|
if (!profileItem) {
|
|
@@ -101,7 +101,7 @@ const main = async (command) => {
|
|
|
101
101
|
process.exit(0);
|
|
102
102
|
}
|
|
103
103
|
} else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
|
|
104
|
-
const { serviceItem } = await getAdapterConfig();
|
|
104
|
+
const { serviceItem } = await utils.getAdapterConfig();
|
|
105
105
|
if (serviceItem) {
|
|
106
106
|
const adapter = serviceItem;
|
|
107
107
|
const a = basicGet.getAdapterInstance(adapter);
|
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 -
|
|
180
|
+
const currentPath = pathArray.slice(pathArray.length - 3, pathArray.length).join('/');
|
|
181
181
|
if (currentPath.trim() !== expectedPath.trim()) {
|
|
182
|
-
throw new Error(`adapter should be installed under ${expectedPath}`);
|
|
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
|
}
|
|
@@ -339,6 +339,37 @@ module.exports = {
|
|
|
339
339
|
return adapter;
|
|
340
340
|
},
|
|
341
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
|
+
|
|
342
373
|
/**
|
|
343
374
|
* @summary return async healthcheck result as a Promise
|
|
344
375
|
*
|
|
@@ -400,7 +431,21 @@ module.exports = {
|
|
|
400
431
|
return __dirname;
|
|
401
432
|
}
|
|
402
433
|
const { stdout } = this.systemSync('pwd', true);
|
|
403
|
-
return
|
|
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;
|
|
404
449
|
}
|
|
405
450
|
|
|
406
451
|
};
|