@itentialopensource/adapter-utils 5.7.2 → 5.9.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,20 @@
1
1
 
2
+ ## 5.9.0 [09-23-2024]
3
+
4
+ * Cache ssl file contents in memory
5
+
6
+ See merge request itentialopensource/adapter-utils!303
7
+
8
+ ---
9
+
10
+ ## 5.8.0 [09-09-2024]
11
+
12
+ * Add support for RESTCONF endpoints
13
+
14
+ See merge request itentialopensource/adapter-utils!298
15
+
16
+ ---
17
+
2
18
  ## 5.7.2 [09-06-2024]
3
19
 
4
20
  * Update lock file
@@ -127,6 +127,9 @@ let crest = null;
127
127
  let cacheHHead = null;
128
128
  let cacheHSchema = null;
129
129
  let cacheHPay = null;
130
+ let sslCAFilePath = null;
131
+ let sslKeyFilePath = null;
132
+ let sslCertFilePath = null;
130
133
 
131
134
  const mfaStepsResults = []; // keeps requested result for each step
132
135
 
@@ -2028,34 +2031,32 @@ async function buildTokenRequest(reqPath, reqBody, callProperties, callback) {
2028
2031
  options.rejectUnauthorized = false;
2029
2032
  } else {
2030
2033
  // if we are not accepting invalid certs, need the ca file in the options
2031
- try {
2032
- options.rejectUnauthorized = true;
2033
- if (sslCAFileContent && sslCAFileContent !== '') {
2034
- options.ca = [sslCAFileContent];
2035
- } else {
2036
- options.ca = [fs.readFileSync(sslCAFile)];
2037
- }
2038
- } catch (e) {
2039
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCAFile], null, null, null);
2034
+ options.rejectUnauthorized = true;
2035
+ if (sslCAFileContent && sslCAFileContent !== '') {
2036
+ options.ca = [sslCAFileContent];
2037
+ } else if (sslCAFile) {
2038
+ options.ca = sslCAFile;
2039
+ } else {
2040
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCAFilePath], null, null, null);
2040
2041
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2041
2042
  return reject(errorObj);
2042
2043
  }
2043
2044
  // if there is a cert file, try to read in a cert file in the options
2044
- if (sslCertFile) {
2045
- try {
2046
- options.cert = [fs.readFileSync(sslCertFile)];
2047
- } catch (e) {
2048
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCertFile], null, null, null);
2045
+ if (sslCertFilePath) {
2046
+ if (sslCertFile) {
2047
+ options.cert = sslCertFile;
2048
+ } else {
2049
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCertFilePath], null, null, null);
2049
2050
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2050
2051
  return reject(errorObj);
2051
2052
  }
2052
2053
  }
2053
2054
  // if there is a key file, try to read in a key file in the options
2054
- if (sslKeyFile) {
2055
- try {
2056
- options.key = [fs.readFileSync(sslKeyFile)];
2057
- } catch (e) {
2058
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslKeyFile], null, null, null);
2055
+ if (sslKeyFilePath) {
2056
+ if (sslKeyFile) {
2057
+ options.key = sslKeyFile;
2058
+ } else {
2059
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslKeyFilePath], null, null, null);
2059
2060
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2060
2061
  return reject(errorObj);
2061
2062
  }
@@ -4453,22 +4454,40 @@ class ConnectorRest {
4453
4454
  }
4454
4455
 
4455
4456
  // set the ssl ca file (optional - default is null)
4456
- if (typeof props.ssl.ca_file === 'string') {
4457
- sslCAFile = props.ssl.ca_file;
4457
+ if (typeof props.ssl.ca_file === 'string' && props.ssl.ca_file.trim() !== '') {
4458
+ sslCAFilePath = props.ssl.ca_file;
4459
+ try {
4460
+ sslCAFile = [fs.readFileSync(props.ssl.ca_file)];
4461
+ } catch (err) {
4462
+ log.error(`Failed to read CA file: ${err.message}`);
4463
+ sslCAFile = null;
4464
+ }
4458
4465
  }
4459
4466
 
4460
- if (typeof props.ssl.ca_file_content === 'string') {
4467
+ if (typeof props.ssl.ca_file_content === 'string' && props.ssl.ca_file_content.trim() !== '') {
4461
4468
  sslCAFileContent = props.ssl.ca_file_content;
4462
4469
  }
4463
4470
 
4464
4471
  // set the ssl key file (optional - default is null)
4465
- if (typeof props.ssl.key_file === 'string') {
4466
- sslKeyFile = props.ssl.key_file;
4472
+ if (typeof props.ssl.key_file === 'string' && props.ssl.key_file.trim() !== '') {
4473
+ sslKeyFilePath = props.ssl.key_file;
4474
+ try {
4475
+ sslKeyFile = [fs.readFileSync(props.ssl.key_file)];
4476
+ } catch (err) {
4477
+ log.error(`Failed to read SSL file: ${err.message}`);
4478
+ sslKeyFile = null;
4479
+ }
4467
4480
  }
4468
4481
 
4469
4482
  // set the ssl cert file (optional - default is null)
4470
- if (typeof props.ssl.cert_file === 'string') {
4471
- sslCertFile = props.ssl.cert_file;
4483
+ if (typeof props.ssl.cert_file === 'string' && props.ssl.cert_file.trim() !== '') {
4484
+ sslCertFilePath = props.ssl.cert_file;
4485
+ try {
4486
+ sslCertFile = [fs.readFileSync(props.ssl.cert_file)];
4487
+ } catch (err) {
4488
+ log.error(`Failed to read SSL Cert file: ${err.message}`);
4489
+ sslCertFile = null;
4490
+ }
4472
4491
  }
4473
4492
 
4474
4493
  // set the ssl ciphers (optional - default is null)
@@ -4741,34 +4760,32 @@ class ConnectorRest {
4741
4760
  options.rejectUnauthorized = false;
4742
4761
  } else {
4743
4762
  // if we are not accepting invalid certs, need the ca file in the options
4744
- try {
4745
- options.rejectUnauthorized = true;
4746
- if (sslCAFileContent && sslCAFileContent !== '') {
4747
- options.ca = [sslCAFileContent];
4748
- } else {
4749
- options.ca = [fs.readFileSync(sslCAFile)];
4750
- }
4751
- } catch (e) {
4752
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCAFile], null, null, null);
4763
+ options.rejectUnauthorized = true;
4764
+ if (sslCAFileContent && sslCAFileContent !== '') {
4765
+ options.ca = [sslCAFileContent];
4766
+ } else if (sslCAFile) {
4767
+ options.ca = sslCAFile;
4768
+ } else {
4769
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCAFilePath], null, null, null);
4753
4770
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
4754
4771
  return callback(null, errorObj);
4755
4772
  }
4756
4773
  // if there is a cert file, try to read in a cert file in the options
4757
- if (sslCertFile) {
4758
- try {
4759
- options.cert = [fs.readFileSync(sslCertFile)];
4760
- } catch (e) {
4761
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCertFile], null, null, null);
4774
+ if (sslCertFilePath) {
4775
+ if (sslCertFile) {
4776
+ options.cert = sslCertFile;
4777
+ } else {
4778
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCertFilePath], null, null, null);
4762
4779
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
4763
4780
  return callback(null, errorObj);
4764
4781
  }
4765
4782
  }
4766
4783
  // if there is a key file, try to read in a key file in the options
4767
- if (sslKeyFile) {
4768
- try {
4769
- options.key = [fs.readFileSync(sslKeyFile)];
4770
- } catch (e) {
4771
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslKeyFile], null, null, null);
4784
+ if (sslKeyFilePath) {
4785
+ if (sslKeyFile) {
4786
+ options.key = sslKeyFile;
4787
+ } else {
4788
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslKeyFilePath], null, null, null);
4772
4789
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
4773
4790
  return callback(null, errorObj);
4774
4791
  }
@@ -4938,34 +4955,32 @@ class ConnectorRest {
4938
4955
  options.rejectUnauthorized = false;
4939
4956
  } else {
4940
4957
  // if we are not accepting invalid certs, need the ca file in the options
4941
- try {
4942
- options.rejectUnauthorized = true;
4943
- if (sslCAFileContent && sslCAFileContent !== '') {
4944
- options.ca = [sslCAFileContent];
4945
- } else {
4946
- options.ca = [fs.readFileSync(sslCAFile)];
4947
- }
4948
- } catch (e) {
4949
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCAFile], null, null, null);
4958
+ options.rejectUnauthorized = true;
4959
+ if (sslCAFileContent && sslCAFileContent !== '') {
4960
+ options.ca = [sslCAFileContent];
4961
+ } else if (sslCAFile) {
4962
+ options.ca = sslCAFile;
4963
+ } else {
4964
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCAFilePath], null, null, null);
4950
4965
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
4951
4966
  return callback(null, errorObj);
4952
4967
  }
4953
4968
  // if there is a cert file, try to read in a cert file in the options
4954
- if (sslCertFile) {
4955
- try {
4956
- options.cert = [fs.readFileSync(sslCertFile)];
4957
- } catch (e) {
4958
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCertFile], null, null, null);
4969
+ if (sslCertFilePath) {
4970
+ if (sslCertFile) {
4971
+ options.cert = sslCertFile;
4972
+ } else {
4973
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslCertFilePath], null, null, null);
4959
4974
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
4960
4975
  return callback(null, errorObj);
4961
4976
  }
4962
4977
  }
4963
4978
  // if there is a key file, try to read in a key file in the options
4964
- if (sslKeyFile) {
4965
- try {
4966
- options.key = [fs.readFileSync(sslKeyFile)];
4967
- } catch (e) {
4968
- const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslKeyFile], null, null, null);
4979
+ if (sslKeyFilePath) {
4980
+ if (sslKeyFile) {
4981
+ options.key = sslKeyFile;
4982
+ } else {
4983
+ const errorObj = this.transUtil.formatErrorObject(origin, 'Missing File', [sslKeyFilePath], null, null, null);
4969
4984
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
4970
4985
  return callback(null, errorObj);
4971
4986
  }
@@ -1023,7 +1023,7 @@ class AdapterPropertyUtil {
1023
1023
  errorObj.exception = e;
1024
1024
 
1025
1025
  // return the error message
1026
- log.info(`unable to get adapter config from database: ${e}`);
1026
+ log.info(`unable to get adapter config from database: ${e}, using config from file system`);
1027
1027
  return callback(null, errorObj);
1028
1028
  }
1029
1029
  }
@@ -683,6 +683,10 @@ function buildRequestPath(entity, action, entitySchema, reqPath, uriPathVars, ur
683
683
  // with the provided id
684
684
  let idString = '';
685
685
 
686
+ // if encoding is changed in call properties that overrides the default
687
+ if (callProperties && Object.hasOwnProperty.call(callProperties, 'encode_pathvars')) {
688
+ encodePath = callProperties.encode_pathvars;
689
+ }
686
690
  // check if the current URI path ends with a slash (may require
687
691
  // slash at end)
688
692
  if (uriPath[hindex - 2] === '/' || uriPath[hindex - 2] === ':') {
@@ -793,6 +797,10 @@ function buildRequestPath(entity, action, entitySchema, reqPath, uriPathVars, ur
793
797
  addquery = entitySchema.querykey;
794
798
  }
795
799
  if (systemQuery !== null) {
800
+ // if encoding is changed in call properties that overrides the default
801
+ if (callProperties && Object.hasOwnProperty.call(callProperties, 'encode_queryvars')) {
802
+ encodeUri = callProperties.encode_queryvars;
803
+ }
796
804
  // if we are encoding - use querystring since it does it all!
797
805
  if (encodeUri === true) {
798
806
  addquery += querystring.stringify(systemQuery);
@@ -847,6 +855,7 @@ function buildRequestPath(entity, action, entitySchema, reqPath, uriPathVars, ur
847
855
 
848
856
  // remove any double slashes that may be in the path - can happen if base path is / or ends in a /
849
857
  uriPath = uriPath.replace(/\/\//g, '/');
858
+ uriPath = uriPath.replace(/=\//g, '=');
850
859
 
851
860
  const result = {
852
861
  path: uriPath
@@ -892,6 +901,7 @@ function buildRequestPath(entity, action, entitySchema, reqPath, uriPathVars, ur
892
901
 
893
902
  // remove any double slashes that may be in the path - can happen if base path is / or ends in a /
894
903
  uriPath = uriPath.replace(/\/\//g, '/');
904
+ uriPath = uriPath.replace(/=\//g, '=');
895
905
 
896
906
  const result = {
897
907
  path: uriPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "5.7.2",
3
+ "version": "5.9.0",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "postinstall": "node utils/setup.js",
Binary file
@@ -1,9 +0,0 @@
1
- {
2
- "ComplianceEntries": [
3
- {
4
- "name": "Compliance Summary",
5
- "numInvalidProjects": 0,
6
- "numValidProjects": 0
7
- }
8
- ]
9
- }
@@ -1,5 +0,0 @@
1
- ---------------------------------------------------------------------------------------------
2
- **** Project Compliance Summary ****
3
- 0 project(s) are not valid
4
- 0 project(s) are valid
5
- ---------------------------------------------------------------------------------------------