@itentialopensource/adapter-kubernetes 0.6.3 → 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.
Files changed (42) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +169 -0
  4. package/CHANGELOG.md +43 -24
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +88 -74
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +225 -502
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +349 -58
  14. package/adapterBase.js +1022 -246
  15. package/entities/.generic/action.json +110 -5
  16. package/entities/.generic/schema.json +6 -1
  17. package/error.json +12 -0
  18. package/package.json +20 -13
  19. package/pronghorn.json +642 -378
  20. package/propertiesDecorators.json +14 -0
  21. package/propertiesSchema.json +436 -0
  22. package/refs?service=git-upload-pack +0 -0
  23. package/report/adapterInfo.json +10 -0
  24. package/report/updateReport1653089036005.json +120 -0
  25. package/sampleProperties.json +94 -2
  26. package/test/integration/adapterTestBasicGet.js +2 -2
  27. package/test/integration/adapterTestIntegration.js +29 -103
  28. package/test/unit/adapterBaseTestUnit.js +35 -27
  29. package/test/unit/adapterTestUnit.js +641 -113
  30. package/utils/adapterInfo.js +206 -0
  31. package/utils/addAuth.js +94 -0
  32. package/utils/basicGet.js +1 -14
  33. package/utils/entitiesToDB.js +179 -0
  34. package/utils/modify.js +1 -1
  35. package/utils/packModificationScript.js +1 -1
  36. package/utils/patches2bundledDeps.js +90 -0
  37. package/utils/pre-commit.sh +3 -0
  38. package/utils/removeHooks.js +20 -0
  39. package/utils/tbScript.js +43 -22
  40. package/utils/tbUtils.js +126 -29
  41. package/utils/testRunner.js +16 -16
  42. package/utils/troubleshootingAdapter.js +2 -26
@@ -8,7 +8,8 @@
8
8
  "version": "v1.16.0",
9
9
  "cache_location": "none",
10
10
  "encode_pathvars": true,
11
- "save_metric": true,
11
+ "encode_queryvars": true,
12
+ "save_metric": false,
12
13
  "stub": true,
13
14
  "protocol": "https",
14
15
  "authentication": {
@@ -21,7 +22,10 @@
21
22
  "invalid_token_error": 401,
22
23
  "auth_field": "header.headers.X-AUTH-TOKEN",
23
24
  "auth_field_format": "{token}",
24
- "auth_logging":false
25
+ "auth_logging": false,
26
+ "client_id": "",
27
+ "client_secret": "",
28
+ "grant_type": ""
25
29
  },
26
30
  "healthcheck": {
27
31
  "type": "none",
@@ -92,6 +96,94 @@
92
96
  "key_file": "",
93
97
  "cert_file": ""
94
98
  }
99
+ },
100
+ "devicebroker": {
101
+ "getDevice": [
102
+ {
103
+ "path": "/get/devices/{id}",
104
+ "method": "GET",
105
+ "query": {},
106
+ "body": {},
107
+ "headers": {},
108
+ "handleFailure": "ignore",
109
+ "requestFields": {
110
+ "id": "name"
111
+ },
112
+ "responseDatakey": "",
113
+ "responseFields": {
114
+ "name": "host",
115
+ "ostype": "os",
116
+ "ostypePrefix": "system-",
117
+ "ipaddress": "attributes.ipaddr",
118
+ "port": "443"
119
+ }
120
+ }
121
+ ],
122
+ "getDevicesFiltered": [
123
+ {
124
+ "path": "/get/devices",
125
+ "method": "GET",
126
+ "query": {},
127
+ "body": {},
128
+ "headers": {},
129
+ "handleFailure": "ignore",
130
+ "requestFields": {},
131
+ "responseDatakey": "",
132
+ "responseFields": {
133
+ "name": "host",
134
+ "ostype": "os",
135
+ "ostypePrefix": "system-",
136
+ "ipaddress": "attributes.ipaddr",
137
+ "port": "443"
138
+ }
139
+ }
140
+ ],
141
+ "isAlive": [
142
+ {
143
+ "path": "/get/devices/{id}/status",
144
+ "method": "GET",
145
+ "query": {},
146
+ "body": {},
147
+ "headers": {},
148
+ "handleFailure": "ignore",
149
+ "requestFields": {
150
+ "id": "name"
151
+ },
152
+ "responseDatakey": "",
153
+ "responseFields": {
154
+ "status": "status",
155
+ "statusValue": "online"
156
+ }
157
+ }
158
+ ],
159
+ "getConfig": [
160
+ {
161
+ "path": "/get/devices/{id}/configPart1",
162
+ "method": "GET",
163
+ "query": {},
164
+ "body": {},
165
+ "headers": {},
166
+ "handleFailure": "ignore",
167
+ "requestFields": {
168
+ "id": "name"
169
+ },
170
+ "responseDatakey": "",
171
+ "responseFields": {}
172
+ }
173
+ ],
174
+ "getCount": [
175
+ {
176
+ "path": "/get/devices",
177
+ "method": "GET",
178
+ "query": {},
179
+ "body": {},
180
+ "headers": {},
181
+ "handleFailure": "ignore",
182
+ "requestFields": {},
183
+ "responseDatakey": "",
184
+ "responseFields": {}
185
+ }
186
+ ]
95
187
  }
96
188
  },
97
189
  "groups": [],
@@ -14,7 +14,7 @@ const itParam = require('mocha-param');
14
14
 
15
15
  const utils = require('../../utils/tbUtils');
16
16
  const basicGet = require('../../utils/basicGet');
17
- const { name } = require('../../package');
17
+ const { name } = require('../../package.json');
18
18
  const { methods } = require('../../pronghorn.json');
19
19
 
20
20
  const getPronghornProps = (iapDir) => {
@@ -34,7 +34,7 @@ describe('[integration] Adapter BasicGET Test', () => {
34
34
  context('Testing GET calls without query parameters', () => {
35
35
  before(async () => {
36
36
  const iapDir = path.join(__dirname, '../../../../../');
37
- if (!utils.withinIAP(iapDir)) {
37
+ if (!utils.areWeUnderIAPinstallationDirectory()) {
38
38
  const sampleProperties = require('../../sampleProperties.json');
39
39
  const adapter = { properties: sampleProperties };
40
40
  a = basicGet.getAdapterInstance(adapter);
@@ -3,6 +3,8 @@
3
3
  // Set globals
4
4
  /* global describe it log pronghornProps */
5
5
  /* eslint no-unused-vars: warn */
6
+ /* eslint no-underscore-dangle: warn */
7
+ /* eslint import/no-dynamic-require:warn */
6
8
 
7
9
  // include required items for testing & logging
8
10
  const assert = require('assert');
@@ -13,25 +15,39 @@ const winston = require('winston');
13
15
  const { expect } = require('chai');
14
16
  const { use } = require('chai');
15
17
  const td = require('testdouble');
18
+ const util = require('util');
16
19
 
17
20
  const anything = td.matchers.anything();
18
21
 
19
22
  // stub and attemptTimeout are used throughout the code so set them here
20
23
  let logLevel = 'none';
21
- const stub = true;
22
24
  const isRapidFail = false;
23
25
  const isSaveMockData = false;
24
- const attemptTimeout = 5000;
26
+
27
+ // read in the properties from the sampleProperties files
28
+ let adaptdir = __dirname;
29
+ if (adaptdir.endsWith('/test/integration')) {
30
+ adaptdir = adaptdir.substring(0, adaptdir.length - 17);
31
+ } else if (adaptdir.endsWith('/test/unit')) {
32
+ adaptdir = adaptdir.substring(0, adaptdir.length - 10);
33
+ }
34
+ const samProps = require(`${adaptdir}/sampleProperties.json`).properties;
25
35
 
26
36
  // these variables can be changed to run in integrated mode so easier to set them here
27
37
  // always check these in with bogus data!!!
28
- const host = 'replace.hostorip.here';
29
- const username = 'username';
30
- const password = 'password';
31
- const protocol = 'http';
32
- const port = 80;
33
- const sslenable = false;
34
- const sslinvalid = false;
38
+ samProps.stub = true;
39
+ samProps.host = 'replace.hostorip.here';
40
+ samProps.authentication.username = 'username';
41
+ samProps.authentication.password = 'password';
42
+ samProps.protocol = 'http';
43
+ samProps.port = 80;
44
+ samProps.ssl.enabled = false;
45
+ samProps.ssl.accept_invalid_cert = false;
46
+ if (samProps.request.attempt_timeout < 30000) {
47
+ samProps.request.attempt_timeout = 30000;
48
+ }
49
+ const attemptTimeout = samProps.request.attempt_timeout;
50
+ const { stub } = samProps;
35
51
 
36
52
  // these are the adapter properties. You generally should not need to alter
37
53
  // any of these after they are initially set up
@@ -43,99 +59,7 @@ global.pronghornProps = {
43
59
  adapters: [{
44
60
  id: 'Test-kubernetes',
45
61
  type: 'Kubernetes',
46
- properties: {
47
- host,
48
- port,
49
- base_path: '//api',
50
- version: 'vv1.16.0',
51
- cache_location: 'none',
52
- encode_pathvars: true,
53
- save_metric: false,
54
- protocol,
55
- stub,
56
- authentication: {
57
- auth_method: 'no_authentication',
58
- username,
59
- password,
60
- token: '',
61
- token_timeout: -1,
62
- token_cache: 'local',
63
- invalid_token_error: 401,
64
- auth_field: 'header.headers.Authorization',
65
- auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
66
- auth_logging: false
67
- },
68
- healthcheck: {
69
- type: 'none',
70
- frequency: 60000,
71
- query_object: {}
72
- },
73
- throttle: {
74
- throttle_enabled: false,
75
- number_pronghorns: 1,
76
- sync_async: 'sync',
77
- max_in_queue: 1000,
78
- concurrent_max: 1,
79
- expire_timeout: 0,
80
- avg_runtime: 200,
81
- priorities: [
82
- {
83
- value: 0,
84
- percent: 100
85
- }
86
- ]
87
- },
88
- request: {
89
- number_redirects: 0,
90
- number_retries: 3,
91
- limit_retry_error: 0,
92
- failover_codes: [],
93
- attempt_timeout: attemptTimeout,
94
- global_request: {
95
- payload: {},
96
- uriOptions: {},
97
- addlHeaders: {},
98
- authData: {}
99
- },
100
- healthcheck_on_timeout: true,
101
- return_raw: true,
102
- archiving: false,
103
- return_request: false
104
- },
105
- proxy: {
106
- enabled: false,
107
- host: '',
108
- port: 1,
109
- protocol: 'http',
110
- username: '',
111
- password: ''
112
- },
113
- ssl: {
114
- ecdhCurve: '',
115
- enabled: sslenable,
116
- accept_invalid_cert: sslinvalid,
117
- ca_file: '',
118
- key_file: '',
119
- cert_file: '',
120
- secure_protocol: '',
121
- ciphers: ''
122
- },
123
- mongo: {
124
- host: '',
125
- port: 0,
126
- database: '',
127
- username,
128
- password: '',
129
- replSet: '',
130
- db_ssl: {
131
- enabled: false,
132
- accept_invalid_cert: false,
133
- ca_file: '',
134
- key_file: '',
135
- cert_file: ''
136
- }
137
- }
138
- }
62
+ properties: samProps
139
63
  }]
140
64
  }
141
65
  };
@@ -310,7 +234,7 @@ function saveMockData(entityName, actionName, descriptor, responseData) {
310
234
  }
311
235
 
312
236
  // require the adapter that we are going to be using
313
- const Kubernetes = require('../../adapter.js');
237
+ const Kubernetes = require('../../adapter');
314
238
 
315
239
  // begin the testing - these should be pretty well defined between the describe and the it!
316
240
  describe('[integration] Kubernetes Adapter Test', () => {
@@ -341,6 +265,8 @@ describe('[integration] Kubernetes Adapter Test', () => {
341
265
  try {
342
266
  assert.notEqual(null, a);
343
267
  assert.notEqual(undefined, a);
268
+ const checkId = global.pronghornProps.adapterProps.adapters[0].id;
269
+ assert.equal(checkId, a.id);
344
270
  assert.notEqual(null, a.allProps);
345
271
  const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
346
272
  assert.equal(check, a.healthcheckType);
@@ -61,7 +61,10 @@ global.pronghornProps = {
61
61
  token_cache: 'local',
62
62
  auth_field: 'header.headers.Authorization',
63
63
  auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
64
- auth_logging: false
64
+ auth_logging: false,
65
+ client_id: '',
66
+ client_secret: '',
67
+ grant_type: ''
65
68
  },
66
69
  healthcheck: {
67
70
  type: 'none',
@@ -194,7 +197,7 @@ function runErrorAsserts(data, error, code, origin, displayStr) {
194
197
  }
195
198
 
196
199
  // require the adapter that we are going to be using
197
- const AdapterBase = require('../../adapterBase.js');
200
+ const AdapterBase = require('../../adapterBase');
198
201
 
199
202
  // delete the .DS_Store directory in entities -- otherwise this will cause errors
200
203
  const dirPath = path.join(__dirname, '../../entities/.DS_Store');
@@ -314,8 +317,10 @@ describe('[unit] Adapter Base Test', () => {
314
317
  });
315
318
  it('should return a list of functions', (done) => {
316
319
  const returnedFunctions = ['addEntityCache', 'capabilityResults', 'checkActionFiles', 'checkProperties', 'connect', 'encryptProperty',
317
- 'entityInList', 'findPath', 'getAllCapabilities', 'getAllFunctions', 'getQueue', 'getWorkflowFunctions', 'healthCheck',
318
- 'refreshProperties', 'runBasicGet', 'runConnectivity', 'runHealthcheck', 'suspend', 'troubleshoot', 'unsuspend', 'updateAdapterConfiguration', 'addListener',
320
+ 'entityInList', 'getAllCapabilities', 'getAllFunctions', 'getConfig', 'getDevice', 'getDevicesFiltered', 'hasDevices', 'hasEntities',
321
+ 'healthCheck', 'iapFindAdapterPath', 'iapGetAdapterQueue', 'iapGetAdapterWorkflowFunctions', 'iapGetDeviceCount', 'iapMakeBrokerCall',
322
+ 'iapMoveAdapterEntitiesToDB', 'iapRunAdapterBasicGet', 'iapRunAdapterConnectivity', 'iapRunAdapterHealthcheck', 'iapSuspendAdapter',
323
+ 'iapTroubleshootAdapter', 'iapUnsuspendAdapter', 'iapUpdateAdapterConfiguration', 'isAlive', 'refreshProperties', 'addListener',
319
324
  'emit', 'eventNames', 'getMaxListeners', 'listenerCount', 'listeners', 'off', 'on', 'once', 'prependListener',
320
325
  'prependOnceListener', 'rawListeners', 'removeAllListeners', 'removeListener', 'setMaxListeners'];
321
326
  try {
@@ -334,10 +339,10 @@ describe('[unit] Adapter Base Test', () => {
334
339
  }).timeout(attemptTimeout);
335
340
  });
336
341
 
337
- describe('#getWorkflowFunctions', () => {
338
- it('should have a getWorkflowFunctions function', (done) => {
342
+ describe('#iapGetAdapterWorkflowFunctions', () => {
343
+ it('should have a iapGetAdapterWorkflowFunctions function', (done) => {
339
344
  try {
340
- assert.equal(true, typeof a.getWorkflowFunctions === 'function');
345
+ assert.equal(true, typeof a.iapGetAdapterWorkflowFunctions === 'function');
341
346
  done();
342
347
  } catch (error) {
343
348
  log.error(`Test Failure: ${error}`);
@@ -346,7 +351,7 @@ describe('[unit] Adapter Base Test', () => {
346
351
  });
347
352
  it('should retrieve workflow functions', (done) => {
348
353
  try {
349
- const expectedFunctions = a.getWorkflowFunctions([]);
354
+ const expectedFunctions = a.iapGetAdapterWorkflowFunctions([]);
350
355
  try {
351
356
  assert.equal(0, expectedFunctions.length);
352
357
  done();
@@ -423,10 +428,10 @@ describe('[unit] Adapter Base Test', () => {
423
428
  }).timeout(attemptTimeout);
424
429
  });
425
430
 
426
- describe('#getQueue', () => {
427
- it('should have a getQueue function', (done) => {
431
+ describe('#iapGetAdapterQueue', () => {
432
+ it('should have a iapGetAdapterQueue function', (done) => {
428
433
  try {
429
- assert.equal(true, typeof a.getQueue === 'function');
434
+ assert.equal(true, typeof a.iapGetAdapterQueue === 'function');
430
435
  done();
431
436
  } catch (error) {
432
437
  log.error(`Test Failure: ${error}`);
@@ -435,7 +440,7 @@ describe('[unit] Adapter Base Test', () => {
435
440
  });
436
441
  it('should get information for all of the requests currently in the queue', (done) => {
437
442
  try {
438
- const expectedFunctions = a.getQueue();
443
+ const expectedFunctions = a.iapGetAdapterQueue();
439
444
  try {
440
445
  assert.equal(0, expectedFunctions.length);
441
446
  done();
@@ -814,12 +819,17 @@ describe('[unit] Adapter Base Test', () => {
814
819
  try {
815
820
  assert.notEqual(0, expectedCapabilities.length);
816
821
  assert.equal('.generic', expectedCapabilities[0].entity);
817
- assert.equal(5, expectedCapabilities[0].actions.length);
822
+ assert.equal(10, expectedCapabilities[0].actions.length);
818
823
  assert.equal('getGenerics', expectedCapabilities[0].actions[0]);
819
824
  assert.equal('createGeneric', expectedCapabilities[0].actions[1]);
820
825
  assert.equal('updateGeneric', expectedCapabilities[0].actions[2]);
821
826
  assert.equal('patchGeneric', expectedCapabilities[0].actions[3]);
822
827
  assert.equal('deleteGeneric', expectedCapabilities[0].actions[4]);
828
+ assert.equal('getGenericsNoBase', expectedCapabilities[0].actions[5]);
829
+ assert.equal('createGenericNoBase', expectedCapabilities[0].actions[6]);
830
+ assert.equal('updateGenericNoBase', expectedCapabilities[0].actions[7]);
831
+ assert.equal('patchGenericNoBase', expectedCapabilities[0].actions[8]);
832
+ assert.equal('deleteGenericNoBase', expectedCapabilities[0].actions[9]);
823
833
  assert.equal('.system', expectedCapabilities[1].entity);
824
834
  assert.equal(2, expectedCapabilities[1].actions.length);
825
835
  assert.equal('getToken', expectedCapabilities[1].actions[0]);
@@ -840,12 +850,10 @@ describe('[unit] Adapter Base Test', () => {
840
850
  }).timeout(attemptTimeout);
841
851
  });
842
852
 
843
- // const returnedFunctions = ['updateAdapterConfiguration'];
844
-
845
- describe('#updateAdapterConfiguration', () => {
846
- it('should have a updateAdapterConfiguration function', (done) => {
853
+ describe('#iapUpdateAdapterConfiguration', () => {
854
+ it('should have a iapUpdateAdapterConfiguration function', (done) => {
847
855
  try {
848
- assert.equal(true, typeof a.updateAdapterConfiguration === 'function');
856
+ assert.equal(true, typeof a.iapUpdateAdapterConfiguration === 'function');
849
857
  done();
850
858
  } catch (error) {
851
859
  log.error(`Test Failure: ${error}`);
@@ -854,7 +862,7 @@ describe('[unit] Adapter Base Test', () => {
854
862
  });
855
863
  it('should return no updated if no changes are provided', (done) => {
856
864
  try {
857
- a.updateAdapterConfiguration(null, null, null, null, null, (data, error) => {
865
+ a.iapUpdateAdapterConfiguration(null, null, null, null, null, (data, error) => {
858
866
  try {
859
867
  assert.equal('No configuration updates to make', data.response);
860
868
  done();
@@ -870,10 +878,10 @@ describe('[unit] Adapter Base Test', () => {
870
878
  }).timeout(attemptTimeout);
871
879
  it('should throw an error if missing configuration file', (done) => {
872
880
  try {
873
- a.updateAdapterConfiguration(null, { name: 'fakeChange' }, null, null, null, (data, error) => {
881
+ a.iapUpdateAdapterConfiguration(null, { name: 'fakeChange' }, null, null, null, (data, error) => {
874
882
  try {
875
883
  const displayE = 'configFile is required';
876
- runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
884
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
877
885
  done();
878
886
  } catch (err) {
879
887
  log.error(`Test Failure: ${err}`);
@@ -887,10 +895,10 @@ describe('[unit] Adapter Base Test', () => {
887
895
  }).timeout(attemptTimeout);
888
896
  it('if not package.json, entity is required', (done) => {
889
897
  try {
890
- a.updateAdapterConfiguration('notPackage', { name: 'fakeChange' }, null, null, null, (data, error) => {
898
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, null, null, null, (data, error) => {
891
899
  try {
892
900
  const displayE = 'Unsupported Configuration Change or Missing Entity';
893
- runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
901
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
894
902
  done();
895
903
  } catch (err) {
896
904
  log.error(`Test Failure: ${err}`);
@@ -904,10 +912,10 @@ describe('[unit] Adapter Base Test', () => {
904
912
  }).timeout(attemptTimeout);
905
913
  it('if not package.json, type is required', (done) => {
906
914
  try {
907
- a.updateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'entity', null, null, (data, error) => {
915
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'entity', null, null, (data, error) => {
908
916
  try {
909
917
  const displayE = 'type is required';
910
- runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
918
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
911
919
  done();
912
920
  } catch (err) {
913
921
  log.error(`Test Failure: ${err}`);
@@ -921,10 +929,10 @@ describe('[unit] Adapter Base Test', () => {
921
929
  }).timeout(attemptTimeout);
922
930
  it('if not package.json, entity must be valid', (done) => {
923
931
  try {
924
- a.updateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'fakeEntity', 'fakeType', null, (data, error) => {
932
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'fakeEntity', 'fakeType', null, (data, error) => {
925
933
  try {
926
934
  const displayE = 'Incomplete Configuration Change: Invalid Entity - fakeEntity';
927
- runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
935
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
928
936
  done();
929
937
  } catch (err) {
930
938
  log.error(`Test Failure: ${err}`);