@itentialopensource/adapter-utils 5.2.0 → 5.3.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ ## 5.3.0 [10-19-2023]
3
+
4
+ * ADAPT-485: AWS Auth
5
+
6
+ Closes ADAPT-485
7
+
8
+ See merge request itentialopensource/adapter-utils!278
9
+
10
+ ---
11
+
2
12
  ## 5.2.0 [10-04-2023]
3
13
 
4
14
  * Broker Changes
@@ -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()}`;
@@ -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`;
@@ -864,7 +864,7 @@ function mergeHeaders(addlHeaders, entitySchema) {
864
864
  if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'PLAIN') {
865
865
  // add the Plain headers if they were not set already
866
866
  thisAHdata.Accept = 'text/plain';
867
- } else if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'XML') {
867
+ } else if (entitySchema && entitySchema.responseDatatype && (entitySchema.responseDatatype.toUpperCase() === 'XML' || entitySchema.responseDatatype.toUpperCase() === 'XML2JSON')) {
868
868
  // add the XML headers if they were not set already
869
869
  thisAHdata.Accept = 'application/xml';
870
870
  } else if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'URLENCODE') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "postinstall": "node utils/setup.js",
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": {