@itentialopensource/adapter-netbox 0.6.1 → 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.
@@ -112,6 +112,7 @@
112
112
  "enum": [
113
113
  "basic user_password",
114
114
  "static_token",
115
+ "jwt_token",
115
116
  "request_token",
116
117
  "no_authentication"
117
118
  ]
@@ -198,7 +199,10 @@
198
199
  ]
199
200
  },
200
201
  "auth_field": {
201
- "type": "string",
202
+ "type": [
203
+ "string",
204
+ "array"
205
+ ],
202
206
  "description": "The field in which to pass the token",
203
207
  "default": "header.headers.X-AUTH-TOKEN",
204
208
  "examples": [
@@ -210,7 +214,10 @@
210
214
  ]
211
215
  },
212
216
  "auth_field_format": {
213
- "type": "string",
217
+ "type": [
218
+ "string",
219
+ "array"
220
+ ],
214
221
  "description": "The format used to pass the authentication -- variables {token}, {username}, {password} will be replaced with the proper values. {b64}...{/b64} will base64 encode everything between the start and end tag.",
215
222
  "default": "{token}",
216
223
  "examples": [
@@ -220,6 +227,26 @@
220
227
  "Basic {b64}{username}:{password}{/b64}",
221
228
  "token={token}"
222
229
  ]
230
+ },
231
+ "auth_logging": {
232
+ "type": "boolean",
233
+ "description": "This property turns on logging of Authentication Information and should only be true when debugging authentication and connectivity",
234
+ "default": false
235
+ },
236
+ "client_id": {
237
+ "type": "string",
238
+ "description": "The client id for OAuth requests - can also use username depending on schema",
239
+ "default": ""
240
+ },
241
+ "client_secret": {
242
+ "type": "string",
243
+ "description": "The client secret for OAuth requests - can also use password depending on schema",
244
+ "default": ""
245
+ },
246
+ "grant_type": {
247
+ "type": "string",
248
+ "description": "The grant type for OAuth requests - can also provide in schema",
249
+ "default": ""
223
250
  }
224
251
  },
225
252
  "required": [
@@ -319,6 +346,10 @@
319
346
  "examples": [
320
347
  "/api/version/ping"
321
348
  ]
349
+ },
350
+ "query_object": {
351
+ "type": "object",
352
+ "description": "Query object { device: xxxxx } to be placed into the healthcheck, will be converted to query string by the adapter"
322
353
  }
323
354
  },
324
355
  "required": [
@@ -378,7 +409,7 @@
378
409
  "type": "integer",
379
410
  "description": "defines the number of request that Pronghorn can send netbox at one time",
380
411
  "default": 1,
381
- "minimum": 1,
412
+ "minimum": 0,
382
413
  "maximum": 1000
383
414
  },
384
415
  "expire_timeout": {
@@ -515,6 +546,11 @@
515
546
  "type": "boolean",
516
547
  "description": "Archives each request/response and corresponding metrics",
517
548
  "default": false
549
+ },
550
+ "return_request": {
551
+ "type": "boolean",
552
+ "description": "This property turns on returning the response information - need to be carefull in case credentials are in the path",
553
+ "default": false
518
554
  }
519
555
  },
520
556
  "required": [
@@ -555,8 +591,19 @@
555
591
  "http",
556
592
  "https",
557
593
  "socks4",
558
- "socks5"
594
+ "socks5",
595
+ "tls"
559
596
  ]
597
+ },
598
+ "username": {
599
+ "type": "string",
600
+ "description": "username for proxy authentication",
601
+ "default": ""
602
+ },
603
+ "password": {
604
+ "type": "string",
605
+ "description": "password for proxy authentication",
606
+ "default": ""
560
607
  }
561
608
  },
562
609
  "required": [
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": 29
18
+ },
19
+ {
20
+ "owner": "packageJson",
21
+ "description": "Number of production dependencies",
22
+ "value": 12
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": 21
33
+ },
34
+ {
35
+ "owner": "packageJson",
36
+ "description": "Runtime Library dependency",
37
+ "value": "^4.39.1"
38
+ },
39
+ {
40
+ "owner": "propertiesSchemaJson",
41
+ "description": "Adapter properties defined in the propertiesSchema file",
42
+ "value": 61
43
+ },
44
+ {
45
+ "owner": "readmeMd",
46
+ "description": "Number of lines in the README.md",
47
+ "value": 615
48
+ },
49
+ {
50
+ "owner": "unitTestJS",
51
+ "description": "Number of lines of code in unit tests",
52
+ "value": 12804
53
+ },
54
+ {
55
+ "owner": "unitTestJS",
56
+ "description": "Number of unit tests",
57
+ "value": 851
58
+ },
59
+ {
60
+ "owner": "integrationTestJS",
61
+ "description": "Number of lines of code in integration tests",
62
+ "value": 12299
63
+ },
64
+ {
65
+ "owner": "integrationTestJS",
66
+ "description": "Number of integration tests",
67
+ "value": 389
68
+ },
69
+ {
70
+ "owner": "staticFile",
71
+ "description": "Number of lines of code in adapterBase.js",
72
+ "value": 1007
73
+ },
74
+ {
75
+ "owner": "staticFile",
76
+ "description": "Number of static files added",
77
+ "value": 30
78
+ },
79
+ {
80
+ "owner": "Overall",
81
+ "description": "Total lines of Code",
82
+ "value": 26110
83
+ },
84
+ {
85
+ "owner": "Overall",
86
+ "description": "Total Tests",
87
+ "value": 1240
88
+ },
89
+ {
90
+ "owner": "Overall",
91
+ "description": "Total Files",
92
+ "value": 6
93
+ }
94
+ ]
95
+ }
@@ -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": 13450
53
+ },
54
+ {
55
+ "owner": "unitTestJS",
56
+ "description": "Number of unit tests",
57
+ "value": 879
58
+ },
59
+ {
60
+ "owner": "integrationTestJS",
61
+ "description": "Number of lines of code in integration tests",
62
+ "value": 12334
63
+ },
64
+ {
65
+ "owner": "integrationTestJS",
66
+ "description": "Number of integration tests",
67
+ "value": 390
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": 26813
83
+ },
84
+ {
85
+ "owner": "Overall",
86
+ "description": "Total Tests",
87
+ "value": 1269
88
+ },
89
+ {
90
+ "owner": "Overall",
91
+ "description": "Total Files",
92
+ "value": 6
93
+ }
94
+ ]
95
+ }
@@ -20,11 +20,16 @@
20
20
  "token_cache": "local",
21
21
  "invalid_token_error": 401,
22
22
  "auth_field": "header.headers.Authorization",
23
- "auth_field_format": "Basic {b64}{username}:{password}{/b64}"
23
+ "auth_field_format": "Basic {b64}{username}:{password}{/b64}",
24
+ "auth_logging": false,
25
+ "client_id": "",
26
+ "client_secret": "",
27
+ "grant_type": ""
24
28
  },
25
29
  "healthcheck": {
26
30
  "type": "startup",
27
- "frequency": 300000
31
+ "frequency": 300000,
32
+ "query_object": {}
28
33
  },
29
34
  "throttle": {
30
35
  "throttle_enabled": false,
@@ -55,13 +60,16 @@
55
60
  },
56
61
  "healthcheck_on_timeout": true,
57
62
  "return_raw": false,
58
- "archiving": false
63
+ "archiving": false,
64
+ "return_request": false
59
65
  },
60
66
  "proxy": {
61
67
  "enabled": false,
62
68
  "host": "",
63
69
  "port": 1,
64
- "protocol": "http"
70
+ "protocol": "http",
71
+ "username": "",
72
+ "password": ""
65
73
  },
66
74
  "ssl": {
67
75
  "ecdhCurve": "",
@@ -0,0 +1,85 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* global describe context before after */
4
+ /* eslint global-require: warn */
5
+ /* eslint no-unused-vars: warn */
6
+ /* eslint import/no-extraneous-dependencies: warn */
7
+ /* eslint import/no-dynamic-require: warn */
8
+ /* eslint import/no-unresolved: warn */
9
+
10
+ const mocha = require('mocha');
11
+ const path = require('path');
12
+ const assert = require('assert');
13
+ const itParam = require('mocha-param');
14
+
15
+ const utils = require('../../utils/tbUtils');
16
+ const basicGet = require('../../utils/basicGet');
17
+ const { name } = require('../../package.json');
18
+ const { methods } = require('../../pronghorn.json');
19
+
20
+ const getPronghornProps = (iapDir) => {
21
+ const { Discovery } = require('@itential/itential-utils');
22
+ console.log('Retrieving properties.json file...');
23
+ const rawProps = require(path.join(iapDir, 'properties.json'));
24
+ console.log('Decrypting properties...');
25
+ const discovery = new Discovery();
26
+ const pronghornProps = utils.decryptProperties(rawProps, path.join(__dirname, '..'), discovery);
27
+ console.log('Found properties.\n');
28
+ return pronghornProps;
29
+ };
30
+
31
+ let a;
32
+
33
+ describe('[integration] Adapter BasicGET Test', () => {
34
+ context('Testing GET calls without query parameters', () => {
35
+ before(async () => {
36
+ const iapDir = path.join(__dirname, '../../../../../');
37
+ if (!utils.withinIAP(iapDir)) {
38
+ const sampleProperties = require('../../sampleProperties.json');
39
+ const adapter = { properties: sampleProperties };
40
+ a = basicGet.getAdapterInstance(adapter);
41
+ } else {
42
+ const pronghornProps = getPronghornProps(iapDir);
43
+ console.log('Connecting to Database...');
44
+ const database = await basicGet.connect(pronghornProps);
45
+ console.log('Connection established.');
46
+ const adapter = await database.collection(utils.SERVICE_CONFIGS_COLLECTION).findOne(
47
+ { model: name }
48
+ );
49
+ a = basicGet.getAdapterInstance(adapter);
50
+ }
51
+ });
52
+
53
+ after((done) => {
54
+ done();
55
+ });
56
+
57
+ const basicGets = methods.filter((method) => (method.route.verb === 'GET' && method.input.length === 0));
58
+ if (basicGets.length === 0) {
59
+ console.log('No non-parameter GET calls found.');
60
+ process.exit(0);
61
+ }
62
+ const functionNames = basicGets.map((g) => g.name);
63
+ const request = function request(f, ad) {
64
+ return new Promise((resolve, reject) => {
65
+ const getRespCode = (resp) => {
66
+ if (resp) {
67
+ if (resp.metrics.code !== 200) {
68
+ console.log('\x1b[31m', `Testing ${f} \nResponseCode: ${resp.metrics.code}`);
69
+ }
70
+ resolve(resp.metrics.code);
71
+ } else {
72
+ console.log('\x1b[31m', `call ${f} results in failure`);
73
+ reject(new Error(`${f} failed`));
74
+ }
75
+ };
76
+ ad[f](getRespCode, console.log);
77
+ });
78
+ };
79
+
80
+ itParam('GET call should return 200', functionNames, (fname) => {
81
+ console.log(`\t ${fname}`);
82
+ return request(fname, a).then((result) => assert.equal(result, 200));
83
+ });
84
+ });
85
+ });
@@ -0,0 +1,93 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* global describe it context before after */
4
+ /* eslint no-unused-vars: warn */
5
+
6
+ const mocha = require('mocha');
7
+ const assert = require('assert');
8
+ const diagnostics = require('network-diagnostics');
9
+
10
+ let host;
11
+ process.argv.forEach((val) => {
12
+ if (val.indexOf('--HOST') === 0) {
13
+ [, host] = val.split('=');
14
+ }
15
+ });
16
+
17
+ describe('[integration] Adapter Test', () => {
18
+ context(`Testing network connection on ${host}`, () => {
19
+ before(() => {
20
+ diagnostics.setTestURL(host);
21
+ });
22
+
23
+ after((done) => {
24
+ done();
25
+ });
26
+
27
+ it('DNS resolve', (done) => {
28
+ diagnostics.haveDNS((result) => {
29
+ try {
30
+ assert.equal(result, true);
31
+ done();
32
+ } catch (error) {
33
+ done(error);
34
+ }
35
+ });
36
+ });
37
+
38
+ it('Responds to ping', (done) => {
39
+ diagnostics.havePing((result) => {
40
+ try {
41
+ assert.equal(result, true);
42
+ done();
43
+ } catch (error) {
44
+ done(error);
45
+ }
46
+ });
47
+ });
48
+
49
+ it('Support HTTP on port 80', (done) => {
50
+ diagnostics.haveHTTP((result) => {
51
+ try {
52
+ assert.equal(result, true);
53
+ done();
54
+ } catch (error) {
55
+ done(error);
56
+ }
57
+ });
58
+ });
59
+
60
+ it('Support HTTPS on port 443', (done) => {
61
+ diagnostics.haveHTTPS((result) => {
62
+ try {
63
+ assert.equal(result, true);
64
+ done();
65
+ } catch (error) {
66
+ done(error);
67
+ }
68
+ });
69
+ });
70
+
71
+ it('Support IPv4', (done) => {
72
+ diagnostics.haveIPv4Async((result) => {
73
+ try {
74
+ assert.equal(result, true);
75
+ done();
76
+ } catch (error) {
77
+ done(error);
78
+ }
79
+ });
80
+ });
81
+
82
+ it('Support IPv6', (done) => {
83
+ diagnostics.haveIPv6Async((result) => {
84
+ try {
85
+ assert.equal(result, true);
86
+ done();
87
+ } catch (error) {
88
+ done(error);
89
+ }
90
+ });
91
+ });
92
+ });
93
+ });
@@ -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
@@ -62,11 +65,16 @@ global.pronghornProps = {
62
65
  token_timeout: -1,
63
66
  token_cache: 'local',
64
67
  auth_field: 'header.headers.Authorization',
65
- auth_field_format: 'Basic {b64}{username}:{password}{/b64}'
68
+ auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
69
+ auth_logging: false,
70
+ client_id: '',
71
+ client_secret: '',
72
+ grant_type: ''
66
73
  },
67
74
  healthcheck: {
68
75
  type: 'startup',
69
- frequency: 60000
76
+ frequency: 60000,
77
+ query_object: {}
70
78
  },
71
79
  throttle: {
72
80
  throttle_enabled: false,
@@ -97,13 +105,16 @@ global.pronghornProps = {
97
105
  },
98
106
  healthcheck_on_timeout: true,
99
107
  return_raw: true,
100
- archiving: false
108
+ archiving: false,
109
+ return_request: false
101
110
  },
102
111
  proxy: {
103
112
  enabled: false,
104
113
  host: '',
105
114
  port: 1,
106
- protocol: 'http'
115
+ protocol: 'http',
116
+ username: '',
117
+ password: ''
107
118
  },
108
119
  ssl: {
109
120
  ecdhCurve: '',
@@ -305,7 +316,7 @@ function saveMockData(entityName, actionName, descriptor, responseData) {
305
316
  }
306
317
 
307
318
  // require the adapter that we are going to be using
308
- const Netbox = require('../../adapter.js');
319
+ const Netbox = require('../../adapter');
309
320
 
310
321
  // begin the testing - these should be pretty well defined between the describe and the it!
311
322
  describe('[integration] Netbox Adapter Test', () => {
@@ -336,6 +347,8 @@ describe('[integration] Netbox Adapter Test', () => {
336
347
  try {
337
348
  assert.notEqual(null, a);
338
349
  assert.notEqual(undefined, a);
350
+ const checkId = global.pronghornProps.adapterProps.adapters[0].id;
351
+ assert.equal(checkId, a.id);
339
352
  assert.notEqual(null, a.allProps);
340
353
  const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
341
354
  assert.equal(check, a.healthcheckType);
@@ -12294,5 +12307,30 @@ describe('[integration] Netbox Adapter Test', () => {
12294
12307
  }
12295
12308
  }).timeout(attemptTimeout);
12296
12309
  });
12310
+
12311
+ describe('#getGraphql - errors', () => {
12312
+ it('should work if integrated but since no mockdata should error when run standalone', (done) => {
12313
+ try {
12314
+ a.getGraphql({ query: 'fakeq' }, (data, error) => {
12315
+ try {
12316
+ if (stub) {
12317
+ const displayE = 'Error 400 received on request';
12318
+ runErrorAsserts(data, error, 'AD.500', 'Test-netbox-connectorRest-handleEndResponse', displayE);
12319
+ } else {
12320
+ runCommonAsserts(data, error);
12321
+ }
12322
+ saveMockData('Status', 'getGraphql', 'default', data);
12323
+ done();
12324
+ } catch (err) {
12325
+ log.error(`Test Failure: ${err}`);
12326
+ done(err);
12327
+ }
12328
+ });
12329
+ } catch (error) {
12330
+ log.error(`Adapter Exception: ${error}`);
12331
+ done(error);
12332
+ }
12333
+ }).timeout(attemptTimeout);
12334
+ });
12297
12335
  });
12298
12336
  });