@itentialopensource/adapter-viptela 0.10.1 → 0.10.2

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/BROKER.md CHANGED
@@ -170,9 +170,11 @@ Below is an example of how you may set up the properties for this call.
170
170
  ```json
171
171
  "getDevice": [
172
172
  {
173
- "path": "/{org}/get/devices/{id}",
173
+ "path": "/{org}/get/device",
174
174
  "method": "GET",
175
- "query": {},
175
+ "query": {
176
+ "id": "{id}"
177
+ },
176
178
  "body": {},
177
179
  "headers": {},
178
180
  "handleFailure": "ignore",
@@ -192,4 +194,6 @@ Below is an example of how you may set up the properties for this call.
192
194
  ]
193
195
  ```
194
196
 
197
+ In this example, we show a query parameter being used. Notice that the value is still provided via the requestFields and then like with the path, we use curly braces in the query to denote a variable. The body and header variables work in this same manner.
198
+
195
199
  You could have multiple calls here if needed but generally that will not be the case.
package/CHANGELOG.md CHANGED
@@ -1,31 +1,61 @@
1
1
 
2
- ## 0.10.1 [05-08-2022]
2
+ ## 0.10.2 [05-14-2022]
3
3
 
4
- * more broker changes
4
+ * Migration to the latest Adapter Foundation
5
5
 
6
- See merge request itentialopensource/adapters/sd-wan/adapter-viptela!13
6
+ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!14
7
7
 
8
8
  ---
9
9
 
10
- ## 0.10.0 [05-01-2022]
10
+ ## 0.10.1 [05-08-2022] & 0.10.0 [05-01-2022] & 0.9.0 [01-21-2022]
11
11
 
12
- * Minor/adapt 1969
12
+ - Added dabout 415 calls
13
13
 
14
- See merge request itentialopensource/adapters/sd-wan/adapter-viptela!12
14
+ - Multiple versions and releases due to this being one of the adapters heavily involved in the new addapter/broker integration effort.
15
+ - Add some items to .gitignore (e.g. DS_Store) to keep them out of the repos.
16
+ - Changes to the README (some typo fixes - Add how to extend the adapter). Split the README into various markdown files (AUTH, BROKER, CALLS, ENHANCE, PROPERTIES, SUMMARY, SYSTEMINFO, TROUBLESHOOT)
17
+ - Fix the issues with Confluence in the markdowns (Tables, Lists, Links)
18
+ - Add scripts for easier authentication, removing hooks, etc
19
+ - Script changes (install script as well as database changes in other scripts)
20
+ - Double # of path vars on generic call
21
+ - Update versions of foundation (e.g. adapter-utils)
22
+ - Update npm publish so it supports https
23
+ - Update dependencies
24
+ - Add preinstall for minimist
25
+ - Fix new lint issues that came from eslint dependency change
26
+ - Add more thorough Unit tests for standard files (Package, Pronghorn, Properties (Schema and Sample)
27
+ - Add the adapter type in the package.json
28
+ - Add AdapterInfo.js script
29
+ - Add json-query dependency
30
+ - Add the propertiesDecorators.json for product encryption
31
+ - Change the name of internal IAP/Adapter methods to avoid collisions and make more obvious in Workflow - iapRunAdapterBasicGet, iapRunAdapterConnectivity, iapRunAdapterHealthcheck, iapTroubleshootAdapter, iapGetAdapterQueue, iapUnsuspendAdapter, iapSuspendAdapter, iapFindAdapterPath, iapUpdateAdapterConfiguration, iapGetAdapterWorkflowFunctions
32
+ - Add the adapter config in the database support - iapMoveAdapterEntitiesToDB
33
+ - Add standard broker calls - hasEntities, getDevice, getDevicesFiltered, isAlive, getConfig and iapGetDeviceCount
34
+ - Add genericAdapterRequest that does not use the base_path and version so that the path can be unique - genericAdapterRequestNoBasePath
35
+ - Add AdapterInfo.json
36
+ - Add systemName for documentation
15
37
 
16
- ---
17
-
18
- ## 0.9.0 [01-21-2022]
19
-
20
- * migration to latest level and make broker ready
21
-
22
- See merge request itentialopensource/adapters/sd-wan/adapter-viptela!11
38
+ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!13
39
+ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!12
40
+ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!11
23
41
 
24
42
  ---
25
43
 
26
44
  ## 0.8.1 [03-16-2021]
27
45
 
28
- * final mar migration to the latest adapter foundation
46
+ - migration to bring up to the latest foundation
47
+ - Change to .eslintignore (adapter_modification directory)
48
+ - Change to README.md (new properties, new scripts, new processes)
49
+ - Changes to adapterBase.js (new methods)
50
+ - Changes to package.json (new scripts, dependencies)
51
+ - Changes to propertiesSchema.json (new properties and changes to existing)
52
+ - Changes to the Unit test
53
+ - Adding several test files, utils files and .generic entity
54
+ - Fix order of scripts and dependencies in package.json
55
+ - Fix order of properties in propertiesSchema.json
56
+ - Update sampleProperties, unit and integration tests to have all new properties.
57
+ - Add all new calls to adapter.js and pronghorn.json
58
+ - Add suspend piece to older methods
29
59
 
30
60
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!10
31
61
 
@@ -33,7 +63,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!10
33
63
 
34
64
  ## 0.8.0 [02-12-2021]
35
65
 
36
- * Minor/add new template calls
66
+ - Adding new calls to the viptela adapter - also migrated to the latest foundation
37
67
 
38
68
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!9
39
69
 
@@ -41,23 +71,15 @@ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!9
41
71
 
42
72
  ## 0.7.1 [08-21-2020]
43
73
 
44
- * add new call for get vsmart policy list
74
+ - Add new call for get vsmart policy list
45
75
 
46
76
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!8
47
77
 
48
78
  ---
49
79
 
50
- ## 0.7.0 [08-19-2020]
51
-
52
- * add new calls for vSmart
53
-
54
- See merge request itentialopensource/adapters/sd-wan/adapter-viptela!7
55
-
56
- ---
57
-
58
- ## 0.6.0 [08-14-2020]
80
+ ## 0.6.0 [08-14-2020] & 0.7.0 [08-19-2020]
59
81
 
60
- * add new calls for vSmart
82
+ - Add activate/deactivate vSmart policy as well as a way to get the status
61
83
 
62
84
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!7
63
85
 
@@ -65,7 +87,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!7
65
87
 
66
88
  ## 0.5.3 [08-04-2020]
67
89
 
68
- * update authentication
90
+ - Update the authentication in the adapter - request token where the token is returned in a cookie
69
91
 
70
92
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!6
71
93
 
@@ -73,7 +95,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!6
73
95
 
74
96
  ## 0.5.2 [07-09-2020]
75
97
 
76
- * migration
98
+ - Update to the latest adapter foundation
77
99
 
78
100
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!5
79
101
 
@@ -81,7 +103,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!5
81
103
 
82
104
  ## 0.5.1 [01-15-2020]
83
105
 
84
- * december migration
106
+ - Update the adapter to the latest foundation
85
107
 
86
108
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!4
87
109
 
@@ -89,7 +111,18 @@ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!4
89
111
 
90
112
  ## 0.5.0 [11-08-2019]
91
113
 
92
- * update the adapter to the latest foundation
114
+ - Update the adapter to the latest adapter foundation.
115
+ - Updating to adapter-utils 4.24.3 (automatic)
116
+ - Add sample token schemas (manual)
117
+ - Adding placement property to getToken response schema (manual - before encrypt)
118
+ - Adding sso default into action.json for getToken (manual - before response object)
119
+ - Add new adapter properties for metrics & mock (save_metric, mongo and return_raw) (automatic - check place manual before stub)
120
+ - Update sample properties to include new properties (manual)
121
+ - Update integration test for raw mockdata (automatic)
122
+ - Update test properties (manual)
123
+ - Changes to artifactize (automatic)
124
+ - Update type in sampleProperties so it is correct for the adapter (manual)
125
+ - Update the readme (automatic)
93
126
 
94
127
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!3
95
128
 
@@ -97,27 +130,23 @@ See merge request itentialopensource/adapters/sd-wan/adapter-viptela!3
97
130
 
98
131
  ## 0.4.0 [09-16-2019]
99
132
 
100
- * spetember migration
133
+ - Update the adapter to the latest adapter foundation
101
134
 
102
135
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!2
103
136
 
104
137
  ---
105
- ## 0.3.0 [07-30-2019]
106
- * mirgation, categorization and artifactize
107
138
 
108
- See merge request itentialopensource/adapters/sd-wan/adapter-viptela!1
139
+ ## 0.2.0 [07-17-2019] & 0.3.0 [07-30-2019]
109
140
 
110
- ---
111
-
112
- ## 0.2.0 [07-17-2019]
113
- * mirgation, categorization and artifactize
141
+ - Migrate to the latest adapter foundation, categorize the adapter and prepare for app artifact
114
142
 
115
143
  See merge request itentialopensource/adapters/sd-wan/adapter-viptela!1
116
144
 
117
145
  ---
118
146
 
119
147
  ## 0.1.1 [04-25-2019]
120
- * Bug fixes and performance improvements
148
+
149
+ - Initial Commit
121
150
 
122
151
  See commit 4a35c51
123
152
 
package/adapter.js CHANGED
@@ -91,7 +91,8 @@ class Viptela extends AdapterBaseCl {
91
91
  'iapHasAdapterEntity',
92
92
  'iapVerifyAdapterCapability',
93
93
  'iapUpdateAdapterEntityCache',
94
- 'hasEntities'
94
+ 'hasEntities',
95
+ 'getAuthorization'
95
96
  ];
96
97
  if (!inIgnore && Array.isArray(inIgnore)) {
97
98
  myIgnore = inIgnore;
package/adapterBase.js CHANGED
@@ -13,6 +13,7 @@
13
13
  /* Required libraries. */
14
14
  const fs = require('fs-extra');
15
15
  const path = require('path');
16
+ const jsonQuery = require('json-query');
16
17
  const EventEmitterCl = require('events').EventEmitter;
17
18
  const { execSync } = require('child_process');
18
19
 
@@ -148,32 +149,15 @@ function updatePackage(changes) {
148
149
  * INTERNAL FUNCTION: get data from source(s) - nested
149
150
  */
150
151
  function getDataFromSources(loopField, sources) {
151
- const loopArray = loopField.split('.');
152
152
  let fieldValue = loopField;
153
153
 
154
154
  // go through the sources to find the field
155
155
  for (let s = 0; s < sources.length; s += 1) {
156
- let nestedValue = sources[s];
157
- let found = false;
158
-
159
- // loops through incase the field is nested
160
- for (let i = 0; i < loopArray.length; i += 1) {
161
- // if not nested finds it first pass - otherwise set to new level and loop
162
- if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
163
- nestedValue = nestedValue[loopArray[i]];
164
-
165
- // set found if we are at the leaf (going to stop looping)
166
- if (i + 1 === loopArray.length) {
167
- found = true;
168
- }
169
- } else {
170
- // not found in source - check next one
171
- break;
172
- }
173
- }
156
+ // find the field value using jsonquery
157
+ const nestedValue = jsonQuery(loopField, { data: sources[s] }).value;
174
158
 
175
159
  // if we found in source - set and no need to check other sources
176
- if (found) {
160
+ if (nestedValue) {
177
161
  fieldValue = nestedValue;
178
162
  break;
179
163
  }
@@ -194,7 +178,7 @@ class AdapterBase extends EventEmitterCl {
194
178
  super();
195
179
 
196
180
  // IAP home directory injected by core when running the adapter within IAP
197
- process.env.iap_home = process.argv[3];
181
+ [, , , process.env.iap_home] = process.argv;
198
182
 
199
183
  try {
200
184
  // Capture the adapter id
@@ -899,17 +883,18 @@ class AdapterBase extends EventEmitterCl {
899
883
  *
900
884
  * @return {Callback} - containing the response from the mongo transaction
901
885
  */
902
- iapMoveAdapterEntitiesToDB(callback) {
886
+ async iapMoveAdapterEntitiesToDB(callback) {
903
887
  const meth = 'adapterBase-iapMoveAdapterEntitiesToDB';
904
888
  const origin = `${this.id}-${meth}`;
905
889
  log.trace(origin);
906
890
 
907
891
  try {
908
- return callback(entitiesToDB.iapMoveAdapterEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
892
+ const result = await entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id });
893
+ return callback(result, null);
909
894
  } catch (err) {
910
895
  const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
911
896
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
912
- return callback(null, errorObj);
897
+ return callback(null, err.message);
913
898
  }
914
899
  }
915
900
 
@@ -1195,9 +1180,51 @@ class AdapterBase extends EventEmitterCl {
1195
1180
  }
1196
1181
  if (callProps.body) {
1197
1182
  callBody = callProps.body;
1183
+
1184
+ // go through the body fields to check for variable values
1185
+ const cbKeys = Object.keys(callBody);
1186
+ for (let cb = 0; cb < cbKeys.length; cb += 1) {
1187
+ if (callBody[cbKeys[cb]].startsWith('{') && callBody[cbKeys[cb]].endsWith('}')) {
1188
+ // make any necessary changes to the query params
1189
+ if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1190
+ const rqKeys = Object.keys(callProps.requestFields);
1191
+
1192
+ // get the field from the provided device
1193
+ for (let rq = 0; rq < rqKeys.length; rq += 1) {
1194
+ if (cbKeys[cb] === rqKeys[rq]) {
1195
+ const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1196
+
1197
+ // put the value into the query - if it has been specified in the query
1198
+ callBody[cbKeys[cb]] = fieldValue;
1199
+ }
1200
+ }
1201
+ }
1202
+ }
1203
+ }
1198
1204
  }
1199
1205
  if (callProps.headers) {
1200
1206
  callHeaders = callProps.headers;
1207
+
1208
+ // go through the body fields to check for variable values
1209
+ const chKeys = Object.keys(callHeaders);
1210
+ for (let ch = 0; ch < chKeys.length; ch += 1) {
1211
+ if (callHeaders[chKeys[ch]].startsWith('{') && callHeaders[chKeys[ch]].endsWith('}')) {
1212
+ // make any necessary changes to the query params
1213
+ if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
1214
+ const rqKeys = Object.keys(callProps.requestFields);
1215
+
1216
+ // get the field from the provided device
1217
+ for (let rq = 0; rq < rqKeys.length; rq += 1) {
1218
+ if (chKeys[ch] === rqKeys[rq]) {
1219
+ const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
1220
+
1221
+ // put the value into the query - if it has been specified in the query
1222
+ callHeaders[chKeys[ch]] = fieldValue;
1223
+ }
1224
+ }
1225
+ }
1226
+ }
1227
+ }
1201
1228
  }
1202
1229
  if (callProps.handleFailure) {
1203
1230
  handleFail = callProps.handleFailure;
@@ -1228,6 +1255,12 @@ class AdapterBase extends EventEmitterCl {
1228
1255
  return callback({}, null);
1229
1256
  }
1230
1257
 
1258
+ // get the response piece we care about from the response
1259
+ const myResult = result;
1260
+ if (callProps.responseDatakey) {
1261
+ myResult.response = jsonQuery(callProps.responseDatakey, { data: myResult.response }).value;
1262
+ }
1263
+
1231
1264
  // get the keys for the response fields
1232
1265
  let rfKeys = [];
1233
1266
  if (callProps.responseFields && Object.keys(callProps.responseFields).length > 0) {
@@ -1235,10 +1268,10 @@ class AdapterBase extends EventEmitterCl {
1235
1268
  }
1236
1269
 
1237
1270
  // if we got an array returned (e.g. getDevicesFitered)
1238
- if (Array.isArray(result.response)) {
1271
+ if (Array.isArray(myResult.response)) {
1239
1272
  const listDevices = [];
1240
- for (let a = 0; a < result.response.length; a += 1) {
1241
- const thisDevice = result.response[a];
1273
+ for (let a = 0; a < myResult.response.length; a += 1) {
1274
+ const thisDevice = myResult.response[a];
1242
1275
  for (let rf = 0; rf < rfKeys.length; rf += 1) {
1243
1276
  if (rfKeys[rf] !== 'ostypePrefix') {
1244
1277
  let fieldValue = getDataFromSources(callProps.responseFields[rfKeys[rf]], [thisDevice, devResp, callProps.requestFields]);
@@ -1250,7 +1283,7 @@ class AdapterBase extends EventEmitterCl {
1250
1283
  // if there is a status to set, set it
1251
1284
  if (rfKeys[rf] === 'status') {
1252
1285
  // if really looking for just a good response
1253
- if (callProps.responseFields[rfKeys[rf]] === 'return2xx' && result.icode === statusValue.toString()) {
1286
+ if (callProps.responseFields[rfKeys[rf]] === 'return2xx' && myResult.icode === statusValue.toString()) {
1254
1287
  thisDevice.isAlive = true;
1255
1288
  } else if (fieldValue.toString() === statusValue.toString()) {
1256
1289
  thisDevice.isAlive = true;
@@ -1287,7 +1320,7 @@ class AdapterBase extends EventEmitterCl {
1287
1320
  }
1288
1321
 
1289
1322
  // if this is not an array - just about everything else, just handle as a single object
1290
- let thisDevice = result.response;
1323
+ let thisDevice = myResult.response;
1291
1324
  for (let rf = 0; rf < rfKeys.length; rf += 1) {
1292
1325
  // skip ostypePrefix since it is not a field
1293
1326
  if (rfKeys[rf] !== 'ostypePrefix') {
@@ -1300,7 +1333,7 @@ class AdapterBase extends EventEmitterCl {
1300
1333
  // if there is a status to set, set it
1301
1334
  if (rfKeys[rf] === 'status') {
1302
1335
  // if really looking for just a good response
1303
- if (callProps.responseFields[rfKeys[rf]] === 'return2xx' && result.icode === statusValue.toString()) {
1336
+ if (callProps.responseFields[rfKeys[rf]] === 'return2xx' && myResult.icode === statusValue.toString()) {
1304
1337
  thisDevice.isAlive = true;
1305
1338
  } else if (fieldValue.toString() === statusValue.toString()) {
1306
1339
  thisDevice.isAlive = true;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-viptela",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "This adapter integrates with system Viptela",
5
5
  "main": "adapter.js",
6
6
  "systemName": "Viptela",
7
7
  "wizardVersion": "2.44.7",
8
- "engineVersion": "1.61.3",
8
+ "engineVersion": "1.61.6",
9
9
  "adapterType": "http",
10
10
  "scripts": {
11
11
  "artifactize": "npm i && node utils/packModificationScript.js",
@@ -53,11 +53,12 @@
53
53
  "author": "Itential",
54
54
  "homepage": "https://gitlab.com/itentialopensource/adapters/sd-wan/adapter-viptela#readme",
55
55
  "dependencies": {
56
- "@itentialopensource/adapter-utils": "^4.45.4",
56
+ "@itentialopensource/adapter-utils": "^4.45.5",
57
57
  "ajv": "^6.12.0",
58
58
  "axios": "^0.21.0",
59
59
  "commander": "^2.20.0",
60
60
  "fs-extra": "^8.1.0",
61
+ "json-query": "^2.2.2",
61
62
  "mocha": "^9.0.1",
62
63
  "mocha-param": "^2.0.1",
63
64
  "mongodb": "^4.1.0",