@itentialopensource/adapter-meraki 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
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,39 +1,48 @@
1
1
 
2
- ## 0.8.3 [05-08-2022]
3
-
4
- * Patch/broker cleanup
2
+ ## 0.8.4 [05-14-2022]
3
+
4
+ * Migrate the adapter to the latest foundation
5
+
6
+ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!19
7
+
8
+ ---
9
+
10
+ ## 0.8.3 [05-08-2022] & 0.8.2 [05-02-2022] & 0.8.1 [04-13-2022] & 0.8.0 [01-21-2022]
11
+
12
+ - Multiple versions and releases due to this being one of the adapters heavily involved in the new addapter/broker integration effort.
13
+ - Add some items to .gitignore (e.g. DS_Store) to keep them out of the repos.
14
+ - 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)
15
+ - Fix the issues with Confluence in the markdowns (Tables, Lists, Links)
16
+ - Add scripts for easier authentication, removing hooks, etc
17
+ - Script changes (install script as well as database changes in other scripts)
18
+ - Double # of path vars on generic call
19
+ - Update versions of foundation (e.g. adapter-utils)
20
+ - Update npm publish so it supports https
21
+ - Update dependencies
22
+ - Add preinstall for minimist
23
+ - Fix new lint issues that came from eslint dependency change
24
+ - Add more thorough Unit tests for standard files (Package, Pronghorn, Properties (Schema and Sample)
25
+ - Add the adapter type in the package.json
26
+ - Add AdapterInfo.js script
27
+ - Add json-query dependency
28
+ - Add the propertiesDecorators.json for product encryption
29
+ - 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
30
+ - Add the adapter config in the database support - iapMoveAdapterEntitiesToDB
31
+ - Add standard broker calls - hasEntities, getDevice, getDevicesFiltered, isAlive, getConfig and iapGetDeviceCount
32
+ - Add genericAdapterRequest that does not use the base_path and version so that the path can be unique - genericAdapterRequestNoBasePath
33
+ - Add AdapterInfo.json
34
+ - Add systemName for documentation
5
35
 
6
36
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!18
7
-
8
- ---
9
-
10
- ## 0.8.2 [05-02-2022]
11
-
12
- * Patch/broker fix
13
-
14
37
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!17
15
-
16
- ---
17
-
18
- ## 0.8.1 [04-13-2022]
19
-
20
- * added properties for broker calls and new documentation
21
-
22
38
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!16
23
-
24
- ---
25
-
26
- ## 0.8.0 [01-21-2022]
27
-
28
- * migration to the latest foundation and broker ready
29
-
30
39
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!15
31
40
 
32
41
  ---
33
42
 
34
43
  ## 0.7.3 [06-08-2021]
35
44
 
36
- * Update Pronghorn.json and adapter.js for passing body directly to api call
45
+ - Update pronghorn.json and adpater.js for sending api call body directly
37
46
 
38
47
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!14
39
48
 
@@ -41,7 +50,19 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!14
41
50
 
42
51
  ## 0.7.2 [03-10-2021]
43
52
 
44
- * migration to the latest adapter foundation
53
+ - migration to bring up to the latest foundation
54
+ - Change to .eslintignore (adapter_modification directory)
55
+ - Change to README.md (new properties, new scripts, new processes)
56
+ - Changes to adapterBase.js (new methods)
57
+ - Changes to package.json (new scripts, dependencies)
58
+ - Changes to propertiesSchema.json (new properties and changes to existing)
59
+ - Changes to the Unit test
60
+ - Adding several test files, utils files and .generic entity
61
+ - Fix order of scripts and dependencies in package.json
62
+ - Fix order of properties in propertiesSchema.json
63
+ - Update sampleProperties, unit and integration tests to have all new properties.
64
+ - Add all new calls to adapter.js and pronghorn.json
65
+ - Add suspend piece to older methods
45
66
 
46
67
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!13
47
68
 
@@ -49,7 +70,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!13
49
70
 
50
71
  ## 0.7.1 [07-08-2020]
51
72
 
52
- * migration
73
+ - Update to the latest adapter foundation
53
74
 
54
75
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!12
55
76
 
@@ -57,7 +78,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!12
57
78
 
58
79
  ## 0.7.0 [03-02-2020]
59
80
 
60
- * Minor/add new version calls
81
+ - Add new version calls based on additional query parameters that Meraki has made available.
61
82
 
62
83
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!11
63
84
 
@@ -65,7 +86,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!11
65
86
 
66
87
  ## 0.6.0 [02-03-2020]
67
88
 
68
- * Minor/adapt 32
89
+ - Add new calls to the adapter that were in the new Postman Collection for Meraki (built swagger and put in report)
69
90
 
70
91
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!10
71
92
 
@@ -73,7 +94,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!10
73
94
 
74
95
  ## 0.5.2 [01-13-2020]
75
96
 
76
- * december migration
97
+ - Bring the adapter up to the latest adapter foundation
77
98
 
78
99
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!8
79
100
 
@@ -81,7 +102,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!8
81
102
 
82
103
  ## 0.5.1 [11-19-2019]
83
104
 
84
- * update healthcheck url
105
+ - Update the healthcheck url to one that was used in the lab
85
106
 
86
107
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!7
87
108
 
@@ -89,7 +110,18 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!7
89
110
 
90
111
  ## 0.5.0 [11-08-2019]
91
112
 
92
- * update the adapter to the latest foundation
113
+ - Update the adapter to the latest adapter foundation.
114
+ - Updating to adapter-utils 4.24.3 (automatic)
115
+ - Add sample token schemas (manual)
116
+ - Adding placement property to getToken response schema (manual - before encrypt)
117
+ - Adding sso default into action.json for getToken (manual - before response object)
118
+ - Add new adapter properties for metrics & mock (save_metric, mongo and return_raw) (automatic - check place manual before stub)
119
+ - Update sample properties to include new properties (manual)
120
+ - Update integration test for raw mockdata (automatic)
121
+ - Update test properties (manual)
122
+ - Changes to artifactize (automatic)
123
+ - Update type in sampleProperties so it is correct for the adapter (manual)
124
+ - Update the readme (automatic)
93
125
 
94
126
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!6
95
127
 
@@ -97,7 +129,7 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!6
97
129
 
98
130
  ## 0.4.0 [09-17-2019]
99
131
 
100
- * september migration
132
+ - Update the adapter to the latest adapter foundation
101
133
 
102
134
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!5
103
135
 
@@ -105,27 +137,21 @@ See merge request itentialopensource/adapters/sd-wan/adapter-meraki!5
105
137
 
106
138
  ## 0.3.1 [08-30-2019]
107
139
 
108
- * Resolves PH-40143 - fix the missing slash in the entity paths
140
+ - Added the slash into the entity paths. Migrator does not currently update action files. This was fixed in the adapter builder a while ago but needed to be manually fixed in this adapter.
109
141
 
110
142
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!4
111
143
 
112
- ---
113
- ## 0.3.0 [07-30-2019]
114
- * migratation, categorization and artifactize
115
-
116
- See merge request itentialopensource/adapters/sd-wan/adapter-meraki!3
117
-
118
144
  ---
119
145
 
120
- ## 0.2.0 [07-18-2019]
121
- * migratation, categorization and artifactize
146
+ ## 0.3.0 [07-30-2019] & 0.2.0 [07-18-2019]
147
+ - Migrate to the latest adapter foundation, categorize and prepare for app artifact
122
148
 
123
149
  See merge request itentialopensource/adapters/sd-wan/adapter-meraki!3
124
150
 
125
151
  ---
126
152
 
127
153
  ## 0.1.1 [06-18-2019]
128
- * Initial Commit
154
+ - Initial Commit
129
155
 
130
156
  See merge request itentialopensource/adapters/adapter-meraki!2
131
157
 
package/adapter.js CHANGED
@@ -89,7 +89,8 @@ class Meraki extends AdapterBaseCl {
89
89
  'iapHasAdapterEntity',
90
90
  'iapVerifyAdapterCapability',
91
91
  'iapUpdateAdapterEntityCache',
92
- 'hasEntities'
92
+ 'hasEntities',
93
+ 'getAuthorization'
93
94
  ];
94
95
  if (!inIgnore && Array.isArray(inIgnore)) {
95
96
  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-meraki",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "This adapter integrates with system described as: merakiDashboardApi.",
5
5
  "main": "adapter.js",
6
6
  "systemName": "Meraki",
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",
@@ -58,6 +58,7 @@
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",