@itentialopensource/adapter-vmware_vcenter 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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": "postComvmwarevcenterinventorydatastoreactionfind",
391
583
  "summary": "Returns datastore information for the specified datastores. The key in the {@term result} {@term map} is the datastore identifier and the value in the {@term map} is the datastore information.",
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": 4899
53
+ },
54
+ {
55
+ "owner": "unitTestJS",
56
+ "description": "Number of unit tests",
57
+ "value": 291
58
+ },
59
+ {
60
+ "owner": "integrationTestJS",
61
+ "description": "Number of lines of code in integration tests",
62
+ "value": 3562
63
+ },
64
+ {
65
+ "owner": "integrationTestJS",
66
+ "description": "Number of integration tests",
67
+ "value": 101
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": 9490
83
+ },
84
+ {
85
+ "owner": "Overall",
86
+ "description": "Total Tests",
87
+ "value": 392
88
+ },
89
+ {
90
+ "owner": "Overall",
91
+ "description": "Total Files",
92
+ "value": 6
93
+ }
94
+ ]
95
+ }
@@ -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
@@ -63,7 +66,10 @@ global.pronghornProps = {
63
66
  invalid_token_error: 401,
64
67
  auth_field: 'header.headers.Authorization',
65
68
  auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
66
- auth_logging: false
69
+ auth_logging: false,
70
+ client_id: '',
71
+ client_secret: '',
72
+ grant_type: ''
67
73
  },
68
74
  healthcheck: {
69
75
  type: 'startup',
@@ -317,7 +317,7 @@ describe('[unit] Adapter Base Test', () => {
317
317
  });
318
318
  it('should return a list of functions', (done) => {
319
319
  const returnedFunctions = ['addEntityCache', 'capabilityResults', 'checkActionFiles', 'checkProperties', 'connect', 'encryptProperty',
320
- 'entityInList', 'findPath', 'getAllCapabilities', 'getAllFunctions', 'getQueue', 'getWorkflowFunctions', 'healthCheck',
320
+ 'entityInList', 'findPath', 'getAllCapabilities', 'getAllFunctions', 'getQueue', 'getWorkflowFunctions', 'healthCheck', 'moveEntitiesToDB',
321
321
  'refreshProperties', 'runBasicGet', 'runConnectivity', 'runHealthcheck', 'suspend', 'troubleshoot', 'unsuspend', 'updateAdapterConfiguration', 'addListener',
322
322
  'emit', 'eventNames', 'getMaxListeners', 'listenerCount', 'listeners', 'off', 'on', 'once', 'prependListener',
323
323
  'prependOnceListener', 'rawListeners', 'removeAllListeners', 'removeListener', 'setMaxListeners'];
@@ -65,7 +65,10 @@ global.pronghornProps = {
65
65
  invalid_token_error: 401,
66
66
  auth_field: 'header.headers.Authorization',
67
67
  auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
68
- auth_logging: false
68
+ auth_logging: false,
69
+ client_id: '',
70
+ client_secret: '',
71
+ grant_type: ''
69
72
  },
70
73
  healthcheck: {
71
74
  type: 'startup',
@@ -353,7 +356,7 @@ describe('[unit] Vmware_vCenter Adapter Test', () => {
353
356
  assert.notEqual(undefined, packageDotJson.scripts);
354
357
  assert.notEqual(null, packageDotJson.scripts);
355
358
  assert.notEqual('', packageDotJson.scripts);
356
- assert.equal('node utils/setup.js', packageDotJson.scripts.preinstall);
359
+ assert.equal('node utils/setup.js && npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions', packageDotJson.scripts.preinstall);
357
360
  assert.equal('node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js', packageDotJson.scripts.lint);
358
361
  assert.equal('node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js --quiet', packageDotJson.scripts['lint:errors']);
359
362
  assert.equal('mocha test/unit/adapterBaseTestUnit.js --LOG=error', packageDotJson.scripts['test:baseunit']);
@@ -361,7 +364,7 @@ describe('[unit] Vmware_vCenter Adapter Test', () => {
361
364
  assert.equal('mocha test/integration/adapterTestIntegration.js --LOG=error', packageDotJson.scripts['test:integration']);
362
365
  assert.equal('nyc --reporter html --reporter text mocha --reporter dot test/*', packageDotJson.scripts['test:cover']);
363
366
  assert.equal('npm run test:baseunit && npm run test:unit && npm run test:integration', packageDotJson.scripts.test);
364
- assert.equal('npm publish --registry=http://registry.npmjs.org --access=public', packageDotJson.scripts.deploy);
367
+ assert.equal('npm publish --registry=https://registry.npmjs.org --access=public', packageDotJson.scripts.deploy);
365
368
  assert.equal('npm run deploy', packageDotJson.scripts.build);
366
369
  done();
367
370
  } catch (error) {
@@ -1129,6 +1132,18 @@ describe('[unit] Vmware_vCenter Adapter Test', () => {
1129
1132
  });
1130
1133
  });
1131
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
+
1132
1147
  describe('#checkActionFiles', () => {
1133
1148
  it('should have a checkActionFiles function', (done) => {
1134
1149
  try {
@@ -1258,6 +1273,90 @@ describe('[unit] Vmware_vCenter Adapter Test', () => {
1258
1273
  // }).timeout(attemptTimeout);
1259
1274
  // });
1260
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
+
1261
1360
  /*
1262
1361
  -----------------------------------------------------------------------
1263
1362
  -----------------------------------------------------------------------
@@ -0,0 +1,94 @@
1
+ /* eslint-disable no-plusplus */
2
+ /* eslint global-require: warn */
3
+ /* eslint import/no-dynamic-require: warn */
4
+
5
+ const rls = require('readline-sync');
6
+ const path = require('path');
7
+ const fs = require('fs');
8
+
9
+ function getQuestions(props, obj) {
10
+ const questions = props.map((p) => `${p}: ${(obj[p] !== undefined) ? `(${obj[p]})` : ''} `);
11
+ return questions;
12
+ }
13
+
14
+ // function outputs each property for user to edit/confirm
15
+ // props are the fields that need to be changed depending on what the user selects
16
+ // obj is the JSON object that's being updated
17
+ function confirm(props, obj) {
18
+ // create array of questions
19
+ const updatedObj = obj;
20
+ getQuestions(props, obj).forEach((q) => {
21
+ const answer = rls.question(q);
22
+ // only update the field if the answer is NOT and empty string
23
+ if (answer) {
24
+ updatedObj[q.split(':')[0].trim()] = answer;
25
+ }
26
+ });
27
+ return updatedObj;
28
+ }
29
+
30
+ const updateBasicAuth = (auth) => {
31
+ const propsToUpdate = ['username', 'password', 'auth_field', 'auth_field_format'];
32
+ return confirm(propsToUpdate, auth);
33
+ };
34
+
35
+ const updateStaticTokenAuth = (auth) => {
36
+ const propsToUpdate = ['token', 'auth_field', 'auth_field_format'];
37
+ return confirm(propsToUpdate, auth);
38
+ };
39
+
40
+ function updateTokenSchemas(user, pw, token) {
41
+ let schemaPath = path.join(__dirname, '..', 'entities/.system/schemaTokenReq.json');
42
+ const reqSchema = require(schemaPath);
43
+ reqSchema.properties.username.external_name = user;
44
+ reqSchema.properties.password.external_name = pw;
45
+ fs.writeFileSync(schemaPath, JSON.stringify(reqSchema, null, 2));
46
+ schemaPath = path.join(__dirname, '..', 'entities/.system/schemaTokenResp.json');
47
+ const respSchema = require(schemaPath);
48
+ respSchema.properties.token.external_name = token;
49
+ fs.writeFileSync(schemaPath, JSON.stringify(respSchema, null, 2));
50
+ }
51
+
52
+ function updateRequestToken(auth) {
53
+ const propsToUpdate = [
54
+ 'username',
55
+ 'password',
56
+ 'auth_field',
57
+ 'auth_field_format',
58
+ 'token_user_field',
59
+ 'token_password_field',
60
+ 'token_result_field',
61
+ 'token_URI_path'
62
+ ];
63
+ const newAuth = confirm(propsToUpdate, auth);
64
+ updateTokenSchemas(newAuth.token_user_field, newAuth.token_password_field, newAuth.token_result_field);
65
+
66
+ return newAuth;
67
+ }
68
+
69
+ // prompt users to pick an auth method from the list above
70
+ const addAuthInfo = (props) => {
71
+ const authOptions = [
72
+ 'basic user_password',
73
+ 'static_token',
74
+ 'request_token',
75
+ 'no_authentication'
76
+ ];
77
+ const newProps = confirm(['host', 'port', 'base_path'], props);
78
+
79
+ const newAuthMethod = authOptions[rls.keyInSelect(authOptions, 'Which authentication method?')];
80
+ newProps.authentication.auth_method = newAuthMethod;
81
+
82
+ if (newAuthMethod === 'basic user_password') {
83
+ newProps.authentication = updateBasicAuth(newProps.authentication);
84
+ } else if (newAuthMethod === 'static_token') {
85
+ newProps.authentication = updateStaticTokenAuth(newProps.authentication);
86
+ } else if (newAuthMethod === 'request_token') {
87
+ newProps.authentication = updateRequestToken(newProps.authentication);
88
+ }
89
+ console.log('Connectivity and authentication properties have been configured');
90
+ console.log('If you want to make changes, rerun this script to reinstall the adapter');
91
+ return newProps;
92
+ };
93
+
94
+ module.exports = { addAuthInfo };
package/utils/basicGet.js CHANGED
@@ -4,6 +4,7 @@
4
4
  /* eslint import/no-extraneous-dependencies: warn */
5
5
  /* eslint global-require: warn */
6
6
  /* eslint import/no-unresolved: warn */
7
+ /* eslint import/no-dynamic-require: warn */
7
8
 
8
9
  const winston = require('winston');
9
10
 
@@ -43,20 +44,6 @@ const basicGet = {
43
44
  adapter.id,
44
45
  adapterProps
45
46
  );
46
- },
47
-
48
- /**
49
- * @summary connect to mongodb
50
- *
51
- * @function connect
52
- * @param {Object} properties - pronghornProps
53
- */
54
- connect: async function connect(properties) {
55
- // Connect to Mongo
56
- const { MongoDBConnection } = require('@itential/database');
57
- const connection = new MongoDBConnection(properties.mongoProps);
58
- const database = await connection.connect(true);
59
- return database;
60
47
  }
61
48
  };
62
49