@itentialopensource/adapter-utils 5.2.0 → 5.3.1
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/CHANGELOG.md +20 -0
- package/lib/connectorRest.js +29 -2
- package/lib/requestHandler.js +2 -2
- package/lib/restHandler.js +28 -1
- package/package.json +1 -1
- package/refs?service=git-upload-pack +0 -0
- package/schemas/propertiesSchema.json +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
|
|
2
|
+
## 5.3.1 [11-17-2023]
|
|
3
|
+
|
|
4
|
+
* logic to convert object to array when specified
|
|
5
|
+
|
|
6
|
+
Closes ADAPT-2943
|
|
7
|
+
|
|
8
|
+
See merge request itentialopensource/adapter-utils!280
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 5.3.0 [10-19-2023]
|
|
13
|
+
|
|
14
|
+
* ADAPT-485: AWS Auth
|
|
15
|
+
|
|
16
|
+
Closes ADAPT-485
|
|
17
|
+
|
|
18
|
+
See merge request itentialopensource/adapter-utils!278
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
2
22
|
## 5.2.0 [10-04-2023]
|
|
3
23
|
|
|
4
24
|
* Broker Changes
|
package/lib/connectorRest.js
CHANGED
|
@@ -40,6 +40,7 @@ const noFailover = 'AD.500';
|
|
|
40
40
|
let transUtilInst = null;
|
|
41
41
|
let propUtilInst = null;
|
|
42
42
|
let dbUtilInst = null;
|
|
43
|
+
let authUtilInst = null;
|
|
43
44
|
|
|
44
45
|
// Global Variables - From Properties
|
|
45
46
|
let props = {};
|
|
@@ -1701,7 +1702,7 @@ async function buildTokenRequest(reqPath, reqBody, callProperties, callback) {
|
|
|
1701
1702
|
if (tokenSchema && tokenSchema.responseDatatype && tokenSchema.responseDatatype.toUpperCase() === 'PLAIN') {
|
|
1702
1703
|
// add the Plain headers if they were not set already
|
|
1703
1704
|
thisAHdata.Accept = 'text/plain';
|
|
1704
|
-
} else if (tokenSchema && tokenSchema.responseDatatype && tokenSchema.responseDatatype.toUpperCase() === 'XML') {
|
|
1705
|
+
} else if (tokenSchema && tokenSchema.responseDatatype && (tokenSchema.responseDatatype.toUpperCase() === 'XML' || tokenSchema.responseDatatype.toUpperCase() === 'XML2JSON')) {
|
|
1705
1706
|
// add the XML headers if they were not set already
|
|
1706
1707
|
thisAHdata.Accept = 'application/xml';
|
|
1707
1708
|
} else if (tokenSchema && tokenSchema.responseDatatype && tokenSchema.responseDatatype.toUpperCase() === 'URLENCODE') {
|
|
@@ -3133,6 +3134,30 @@ function requestAuthenticate(request, entitySchema, invalidToken, callProperties
|
|
|
3133
3134
|
return makeRequest(request, entitySchema, callProperties, null, 0, callback);
|
|
3134
3135
|
});
|
|
3135
3136
|
}
|
|
3137
|
+
|
|
3138
|
+
if (authMethod === 'aws_authentication') {
|
|
3139
|
+
let stsParams = null; let roleName = null;
|
|
3140
|
+
if (request.authData) {
|
|
3141
|
+
stsParams = request.authData.stsParams;
|
|
3142
|
+
roleName = request.authData.roleName;
|
|
3143
|
+
}
|
|
3144
|
+
const { service } = props;
|
|
3145
|
+
if (request.header.headers['Content-length']) {
|
|
3146
|
+
delete request.header.headers['Content-length'];
|
|
3147
|
+
}
|
|
3148
|
+
const reqObjAWS = {
|
|
3149
|
+
payload: request.body,
|
|
3150
|
+
addlHeaders: request.header.headers,
|
|
3151
|
+
callProperties
|
|
3152
|
+
};
|
|
3153
|
+
return authUtilInst.getAWSAuthorization(request.header.method, reqObjAWS, request.header.path, service, stsParams, roleName, (signature, awsError) => {
|
|
3154
|
+
if (awsError) {
|
|
3155
|
+
return callback(awsError);
|
|
3156
|
+
}
|
|
3157
|
+
request.header.headers = { ...request.header.headers, ...signature };
|
|
3158
|
+
return makeRequest(request, entitySchema, callProperties, null, 0, callback);
|
|
3159
|
+
});
|
|
3160
|
+
}
|
|
3136
3161
|
// if no_authentication, there is no change to the request!
|
|
3137
3162
|
|
|
3138
3163
|
// actual call to make the request
|
|
@@ -3768,7 +3793,7 @@ class ConnectorRest {
|
|
|
3768
3793
|
* Connector
|
|
3769
3794
|
* @constructor
|
|
3770
3795
|
*/
|
|
3771
|
-
constructor(prongid, properties, transUtilCl, propUtilCl, dbUtilCl) {
|
|
3796
|
+
constructor(prongid, properties, transUtilCl, propUtilCl, dbUtilCl, authUtilCl) {
|
|
3772
3797
|
this.myid = prongid;
|
|
3773
3798
|
id = prongid;
|
|
3774
3799
|
|
|
@@ -3778,6 +3803,8 @@ class ConnectorRest {
|
|
|
3778
3803
|
propUtilInst = this.propUtil;
|
|
3779
3804
|
this.dbUtil = dbUtilCl;
|
|
3780
3805
|
dbUtilInst = this.dbUtil;
|
|
3806
|
+
this.authUtil = authUtilCl;
|
|
3807
|
+
authUtilInst = this.authUtil;
|
|
3781
3808
|
|
|
3782
3809
|
// this uniquely identifies this adapter on this pronghorn system
|
|
3783
3810
|
phInstance = `${id}-${os.hostname()}`;
|
package/lib/requestHandler.js
CHANGED
|
@@ -459,6 +459,7 @@ class RequestHandler {
|
|
|
459
459
|
this.transUtil = new TransUtilCl(prongId, this.propUtil);
|
|
460
460
|
transUtilInst = this.transUtil;
|
|
461
461
|
|
|
462
|
+
this.authHandler = new AuthHandlerCl(this.myid, this.props, this);
|
|
462
463
|
// validate the action files for the adapter
|
|
463
464
|
this.clean = walkThroughActionFiles(this.directory);
|
|
464
465
|
|
|
@@ -469,12 +470,11 @@ class RequestHandler {
|
|
|
469
470
|
this.refreshProperties(properties);
|
|
470
471
|
|
|
471
472
|
// instantiate other runtime components
|
|
472
|
-
this.connector = new ConnectorCl(this.myid, this.props, this.transUtil, this.propUtil, this.dbUtil);
|
|
473
|
+
this.connector = new ConnectorCl(this.myid, this.props, this.transUtil, this.propUtil, this.dbUtil, this.authHandler);
|
|
473
474
|
this.restHandler = new RestHandlerCl(this.myid, this.props, this.connector, this.transUtil);
|
|
474
475
|
this.brokerHandler = new BrokerHandlerCl(this.myid, this.props, this.directory, this);
|
|
475
476
|
this.genericHandler = new GenericHandlerCl(this.myid, this.props, this);
|
|
476
477
|
this.cacheHandler = new CacheHandlerCl(this.myid, this.props, this.directory, this);
|
|
477
|
-
this.authHandler = new AuthHandlerCl(this.myid, this.props, this);
|
|
478
478
|
} catch (e) {
|
|
479
479
|
// handle any exception
|
|
480
480
|
const origin = `${this.myid}-requestHandler-constructor`;
|
package/lib/restHandler.js
CHANGED
|
@@ -25,6 +25,7 @@ let encodeUri = true;
|
|
|
25
25
|
let stripEscapes = false;
|
|
26
26
|
let returnResponseHeaders = true;
|
|
27
27
|
let healthcheckHeaders = null;
|
|
28
|
+
let xmlArrayKeys = null;
|
|
28
29
|
// INTERNAL FUNCTIONS
|
|
29
30
|
/*
|
|
30
31
|
* INTERNAL FUNCTION: Get the best match for the mock data response
|
|
@@ -105,6 +106,24 @@ function checkBodyData(uriPath, method, reqBdObj, mockresponses) {
|
|
|
105
106
|
return specificResp;
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
/*
|
|
110
|
+
* INTERNAL FUNCTION: recursively convert objects to array at keys specified in keys array
|
|
111
|
+
*/
|
|
112
|
+
function setArrays(obj, keys) {
|
|
113
|
+
const currentObj = obj;
|
|
114
|
+
if (typeof currentObj === 'object') {
|
|
115
|
+
Object.keys(currentObj).forEach((key) => {
|
|
116
|
+
if (keys.includes(key)) {
|
|
117
|
+
if (!Array.isArray(currentObj[key])) {
|
|
118
|
+
currentObj[key] = [currentObj[key]];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Recurse for nested keys
|
|
122
|
+
setArrays(currentObj[key], keys);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
108
127
|
/**
|
|
109
128
|
* INTERNAL FUNCTION
|
|
110
129
|
*
|
|
@@ -405,6 +424,10 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
405
424
|
log.warn(`${origin}: Unable to parse xml to json ${error}`);
|
|
406
425
|
return callback(retObject);
|
|
407
426
|
}
|
|
427
|
+
// Logic to convert keys specified to array if object
|
|
428
|
+
if (xmlArrayKeys) {
|
|
429
|
+
setArrays(result, xmlArrayKeys);
|
|
430
|
+
}
|
|
408
431
|
retObject.response = result;
|
|
409
432
|
return callback(retObject);
|
|
410
433
|
});
|
|
@@ -864,7 +887,7 @@ function mergeHeaders(addlHeaders, entitySchema) {
|
|
|
864
887
|
if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'PLAIN') {
|
|
865
888
|
// add the Plain headers if they were not set already
|
|
866
889
|
thisAHdata.Accept = 'text/plain';
|
|
867
|
-
} else if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'XML') {
|
|
890
|
+
} else if (entitySchema && entitySchema.responseDatatype && (entitySchema.responseDatatype.toUpperCase() === 'XML' || entitySchema.responseDatatype.toUpperCase() === 'XML2JSON')) {
|
|
868
891
|
// add the XML headers if they were not set already
|
|
869
892
|
thisAHdata.Accept = 'application/xml';
|
|
870
893
|
} else if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'URLENCODE') {
|
|
@@ -1063,6 +1086,10 @@ class RestHandler {
|
|
|
1063
1086
|
if (properties.healthcheck && typeof properties.healthcheck.addlHeaders === 'object') {
|
|
1064
1087
|
healthcheckHeaders = properties.healthcheck.addlHeaders;
|
|
1065
1088
|
}
|
|
1089
|
+
|
|
1090
|
+
if (properties.xmlArrayKeys && typeof properties.xmlArrayKeys === 'object') {
|
|
1091
|
+
xmlArrayKeys = properties.xmlArrayKeys;
|
|
1092
|
+
}
|
|
1066
1093
|
}
|
|
1067
1094
|
|
|
1068
1095
|
/**
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -83,6 +83,14 @@
|
|
|
83
83
|
"https"
|
|
84
84
|
]
|
|
85
85
|
},
|
|
86
|
+
"service" : {
|
|
87
|
+
"type" : "string",
|
|
88
|
+
"description": "Service we are integrating with -- used with AWS Authentication",
|
|
89
|
+
"examples" : [
|
|
90
|
+
"ec2",
|
|
91
|
+
"route53"
|
|
92
|
+
]
|
|
93
|
+
},
|
|
86
94
|
"authentication": {
|
|
87
95
|
"$ref": "#/definitions/authentication"
|
|
88
96
|
},
|
|
@@ -131,7 +139,8 @@
|
|
|
131
139
|
"jwt_token",
|
|
132
140
|
"request_token",
|
|
133
141
|
"no_authentication",
|
|
134
|
-
"multi_step_authentication"
|
|
142
|
+
"multi_step_authentication",
|
|
143
|
+
"aws_authentication"
|
|
135
144
|
]
|
|
136
145
|
},
|
|
137
146
|
"username": {
|