@itentialopensource/adapter-nokia_altiplano 0.5.1 → 0.5.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,7 +1,15 @@
1
1
 
2
+ ## 0.5.2 [05-15-2022]
3
+
4
+ * Migration to the latest Adapter Foundation
5
+
6
+ See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!8
7
+
8
+ ---
9
+
2
10
  ## 0.5.1 [05-10-2022]
3
11
 
4
- * Fix issue with DeleteIbnIntent
12
+ - Fix issue with DeleteIbnIntent
5
13
 
6
14
  See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!7
7
15
 
@@ -9,7 +17,7 @@ See merge request itentialopensource/adapters/controller-orchestrator/adapter-no
9
17
 
10
18
  ## 0.5.0 [05-02-2022]
11
19
 
12
- * Add calls for ema entity
20
+ - Add calls for ema entity
13
21
 
14
22
  See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!6
15
23
 
@@ -17,7 +25,7 @@ See merge request itentialopensource/adapters/controller-orchestrator/adapter-no
17
25
 
18
26
  ## 0.4.0 [03-30-2022]
19
27
 
20
- * added ibn intent calls
28
+ - added ibn intent calls
21
29
 
22
30
  See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!5
23
31
 
@@ -25,7 +33,7 @@ See merge request itentialopensource/adapters/controller-orchestrator/adapter-no
25
33
 
26
34
  ## 0.3.0 [03-25-2022]
27
35
 
28
- * add new call createOntWithQuery
36
+ - add new call createOntWithQuery
29
37
 
30
38
  See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!4
31
39
 
@@ -33,7 +41,7 @@ See merge request itentialopensource/adapters/controller-orchestrator/adapter-no
33
41
 
34
42
  ## 0.2.0 [03-18-2022]
35
43
 
36
- * Migration and creation of md files
44
+ - Migration and creation of md files
37
45
 
38
46
  See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!3
39
47
 
@@ -41,7 +49,7 @@ See merge request itentialopensource/adapters/controller-orchestrator/adapter-no
41
49
 
42
50
  ## 0.1.3 [10-24-2021]
43
51
 
44
- * Fix the registry url
52
+ - Fix the registry url
45
53
 
46
54
  See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!2
47
55
 
@@ -49,7 +57,7 @@ See merge request itentialopensource/adapters/controller-orchestrator/adapter-no
49
57
 
50
58
  ## 0.1.2 [10-24-2021]
51
59
 
52
- * change paths and add headers
60
+ - change paths and add headers
53
61
 
54
62
  See merge request itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano!1
55
63
 
@@ -57,7 +65,7 @@ See merge request itentialopensource/adapters/controller-orchestrator/adapter-no
57
65
 
58
66
  ## 0.1.1 [07-29-2021]
59
67
 
60
- * Bug fixes and performance improvements
68
+ - Initial Commit
61
69
 
62
70
  See commit bff31d3
63
71
 
package/adapter.js CHANGED
@@ -89,7 +89,8 @@ class NokiaAltiplano 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-nokia_altiplano",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "This adapter integrates with system described as: Nokia Altiplano.",
5
5
  "main": "adapter.js",
6
6
  "systemName": "Nokia Altiplano",
7
7
  "wizardVersion": "2.44.7",
8
- "engineVersion": "1.61.4",
8
+ "engineVersion": "1.61.6",
9
9
  "adapterType": "http",
10
10
  "scripts": {
11
11
  "artifactize": "npm i && node utils/packModificationScript.js",
@@ -55,11 +55,12 @@
55
55
  "author": "Itential",
56
56
  "homepage": "https://gitlab.com/itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano#readme",
57
57
  "dependencies": {
58
- "@itentialopensource/adapter-utils": "^4.45.4",
58
+ "@itentialopensource/adapter-utils": "^4.45.5",
59
59
  "ajv": "^6.12.0",
60
60
  "axios": "^0.21.0",
61
61
  "commander": "^2.20.0",
62
62
  "fs-extra": "^8.1.0",
63
+ "json-query": "^2.2.2",
63
64
  "mocha": "^9.0.1",
64
65
  "mocha-param": "^2.0.1",
65
66
  "mongodb": "^4.1.0",