ibm-cloud-sdk-core 5.0.1 → 5.0.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/.secrets.baseline +15 -15
- package/CHANGELOG.md +7 -0
- package/auth/authenticators/basic-authenticator.d.ts +1 -1
- package/auth/authenticators/basic-authenticator.js +3 -1
- package/auth/authenticators/bearer-token-authenticator.js +2 -0
- package/auth/authenticators/token-request-based-authenticator.js +3 -0
- package/auth/token-managers/cp4d-token-manager.js +6 -1
- package/auth/token-managers/iam-request-based-token-manager.js +5 -1
- package/auth/token-managers/mcsp-token-manager.js +6 -1
- package/auth/token-managers/token-manager.js +7 -3
- package/auth/token-managers/vpc-instance-token-manager.js +4 -1
- package/auth/utils/read-external-sources.js +2 -0
- package/es/auth/authenticators/basic-authenticator.d.ts +1 -1
- package/es/auth/authenticators/basic-authenticator.js +3 -1
- package/es/auth/authenticators/bearer-token-authenticator.js +2 -0
- package/es/auth/authenticators/token-request-based-authenticator.js +2 -0
- package/es/auth/token-managers/cp4d-token-manager.js +6 -1
- package/es/auth/token-managers/iam-request-based-token-manager.js +5 -1
- package/es/auth/token-managers/mcsp-token-manager.js +6 -1
- package/es/auth/token-managers/token-manager.js +7 -3
- package/es/auth/token-managers/vpc-instance-token-manager.js +4 -1
- package/es/auth/utils/read-external-sources.js +2 -0
- package/es/lib/base-service.js +2 -0
- package/es/lib/private-helpers.d.ts +22 -0
- package/es/lib/private-helpers.js +58 -0
- package/es/lib/request-wrapper.d.ts +43 -1
- package/es/lib/request-wrapper.js +113 -14
- package/ibm-cloud-sdk-core.d.ts +42 -0
- package/lib/base-service.js +2 -0
- package/lib/private-helpers.d.ts +22 -0
- package/lib/private-helpers.js +62 -0
- package/lib/request-wrapper.d.ts +43 -1
- package/lib/request-wrapper.js +113 -14
- package/package.json +4 -3
- package/sdk-test-utilities/package-lock.json +8 -5
- package/sdk-test-utilities/package.json +3 -0
package/.secrets.baseline
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"files": "package-lock.json|^.secrets.baseline$",
|
|
4
4
|
"lines": null
|
|
5
5
|
},
|
|
6
|
-
"generated_at": "2024-
|
|
6
|
+
"generated_at": "2024-08-29T14:54:57Z",
|
|
7
7
|
"plugins_used": [
|
|
8
8
|
{
|
|
9
9
|
"name": "AWSKeyDetector"
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"hashed_secret": "bc2f74c22f98f7b6ffbc2f67453dbfa99bce9a32",
|
|
97
97
|
"is_secret": false,
|
|
98
98
|
"is_verified": false,
|
|
99
|
-
"line_number":
|
|
99
|
+
"line_number": 207,
|
|
100
100
|
"type": "Secret Keyword",
|
|
101
101
|
"verified_result": null
|
|
102
102
|
}
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"hashed_secret": "32e8612d8ca77c7ea8374aa7918db8e5df9252ed",
|
|
107
107
|
"is_secret": false,
|
|
108
108
|
"is_verified": false,
|
|
109
|
-
"line_number":
|
|
109
|
+
"line_number": 62,
|
|
110
110
|
"type": "Secret Keyword",
|
|
111
111
|
"verified_result": null
|
|
112
112
|
}
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
|
|
127
127
|
"is_secret": false,
|
|
128
128
|
"is_verified": false,
|
|
129
|
-
"line_number":
|
|
129
|
+
"line_number": 53,
|
|
130
130
|
"type": "Secret Keyword",
|
|
131
131
|
"verified_result": null
|
|
132
132
|
}
|
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
"hashed_secret": "d5ff02fa48e492fac0a245ad63d1ae608e705c05",
|
|
211
211
|
"is_secret": false,
|
|
212
212
|
"is_verified": false,
|
|
213
|
-
"line_number":
|
|
213
|
+
"line_number": 99,
|
|
214
214
|
"type": "Secret Keyword",
|
|
215
215
|
"verified_result": null
|
|
216
216
|
},
|
|
@@ -218,7 +218,7 @@
|
|
|
218
218
|
"hashed_secret": "8f4bfc22c4fd7cb884f94ec175ff4a3284a174a1",
|
|
219
219
|
"is_secret": false,
|
|
220
220
|
"is_verified": false,
|
|
221
|
-
"line_number":
|
|
221
|
+
"line_number": 100,
|
|
222
222
|
"type": "Secret Keyword",
|
|
223
223
|
"verified_result": null
|
|
224
224
|
},
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
"hashed_secret": "45a15668db917c293f16e8add0f5d801889e5923",
|
|
227
227
|
"is_secret": false,
|
|
228
228
|
"is_verified": false,
|
|
229
|
-
"line_number":
|
|
229
|
+
"line_number": 117,
|
|
230
230
|
"type": "Secret Keyword",
|
|
231
231
|
"verified_result": null
|
|
232
232
|
},
|
|
@@ -234,7 +234,7 @@
|
|
|
234
234
|
"hashed_secret": "65e622227634e8876cfa733000233fb80c6f0473",
|
|
235
235
|
"is_secret": false,
|
|
236
236
|
"is_verified": false,
|
|
237
|
-
"line_number":
|
|
237
|
+
"line_number": 118,
|
|
238
238
|
"type": "Secret Keyword",
|
|
239
239
|
"verified_result": null
|
|
240
240
|
}
|
|
@@ -296,7 +296,7 @@
|
|
|
296
296
|
"hashed_secret": "8f4bfc22c4fd7cb884f94ec175ff4a3284a174a1",
|
|
297
297
|
"is_secret": false,
|
|
298
298
|
"is_verified": false,
|
|
299
|
-
"line_number":
|
|
299
|
+
"line_number": 80,
|
|
300
300
|
"type": "Secret Keyword",
|
|
301
301
|
"verified_result": null
|
|
302
302
|
},
|
|
@@ -304,7 +304,7 @@
|
|
|
304
304
|
"hashed_secret": "65e622227634e8876cfa733000233fb80c6f0473",
|
|
305
305
|
"is_secret": false,
|
|
306
306
|
"is_verified": false,
|
|
307
|
-
"line_number":
|
|
307
|
+
"line_number": 96,
|
|
308
308
|
"type": "Secret Keyword",
|
|
309
309
|
"verified_result": null
|
|
310
310
|
}
|
|
@@ -442,7 +442,7 @@
|
|
|
442
442
|
"hashed_secret": "1572bd30ac06678a82df42b5913e5e52e27f9a12",
|
|
443
443
|
"is_secret": false,
|
|
444
444
|
"is_verified": false,
|
|
445
|
-
"line_number":
|
|
445
|
+
"line_number": 32,
|
|
446
446
|
"type": "Secret Keyword",
|
|
447
447
|
"verified_result": null
|
|
448
448
|
},
|
|
@@ -450,7 +450,7 @@
|
|
|
450
450
|
"hashed_secret": "16856d955c788df03735a24feb2e3ffefd91f3dc",
|
|
451
451
|
"is_secret": false,
|
|
452
452
|
"is_verified": false,
|
|
453
|
-
"line_number":
|
|
453
|
+
"line_number": 33,
|
|
454
454
|
"type": "Secret Keyword",
|
|
455
455
|
"verified_result": null
|
|
456
456
|
}
|
|
@@ -522,7 +522,7 @@
|
|
|
522
522
|
"hashed_secret": "a7ef1be18bb8d37af79f3d87761a203378bf26a2",
|
|
523
523
|
"is_secret": false,
|
|
524
524
|
"is_verified": false,
|
|
525
|
-
"line_number":
|
|
525
|
+
"line_number": 158,
|
|
526
526
|
"type": "Secret Keyword",
|
|
527
527
|
"verified_result": null
|
|
528
528
|
}
|
|
@@ -542,7 +542,7 @@
|
|
|
542
542
|
"hashed_secret": "f2e7745f43b0ef0e2c2faf61d6c6a28be2965750",
|
|
543
543
|
"is_secret": false,
|
|
544
544
|
"is_verified": false,
|
|
545
|
-
"line_number":
|
|
545
|
+
"line_number": 31,
|
|
546
546
|
"type": "Secret Keyword",
|
|
547
547
|
"verified_result": null
|
|
548
548
|
}
|
|
@@ -582,7 +582,7 @@
|
|
|
582
582
|
}
|
|
583
583
|
]
|
|
584
584
|
},
|
|
585
|
-
"version": "0.13.1+ibm.
|
|
585
|
+
"version": "0.13.1+ibm.62.dss",
|
|
586
586
|
"word_list": {
|
|
587
587
|
"file": null,
|
|
588
588
|
"hash": null
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [5.0.2](https://github.com/IBM/node-sdk-core/compare/v5.0.1...v5.0.2) (2024-09-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **logging:** improve node core's debug logging ([#286](https://github.com/IBM/node-sdk-core/issues/286)) ([7bcb404](https://github.com/IBM/node-sdk-core/commit/7bcb404fa88592079571149c4b4224f97798f47d))
|
|
7
|
+
|
|
1
8
|
## [5.0.1](https://github.com/IBM/node-sdk-core/compare/v5.0.0...v5.0.1) (2024-08-14)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* (C) Copyright IBM Corp. 2019,
|
|
3
|
+
* (C) Copyright IBM Corp. 2019, 2024.
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -37,6 +37,7 @@ exports.BasicAuthenticator = void 0;
|
|
|
37
37
|
var extend_1 = __importDefault(require("extend"));
|
|
38
38
|
var helpers_1 = require("../utils/helpers");
|
|
39
39
|
var authenticator_1 = require("./authenticator");
|
|
40
|
+
var logger_1 = __importDefault(require("../../lib/logger"));
|
|
40
41
|
/**
|
|
41
42
|
* The BasicAuthenticator is used to add basic authentication information to
|
|
42
43
|
* requests.
|
|
@@ -79,6 +80,7 @@ var BasicAuthenticator = /** @class */ (function (_super) {
|
|
|
79
80
|
var _this = this;
|
|
80
81
|
return new Promise(function (resolve) {
|
|
81
82
|
requestOptions.headers = (0, extend_1.default)(true, {}, requestOptions.headers, _this.authHeader);
|
|
83
|
+
logger_1.default.debug("Authenticated outbound request (type=".concat(_this.authenticationType(), ")"));
|
|
82
84
|
resolve();
|
|
83
85
|
});
|
|
84
86
|
};
|
|
@@ -37,6 +37,7 @@ exports.BearerTokenAuthenticator = void 0;
|
|
|
37
37
|
var extend_1 = __importDefault(require("extend"));
|
|
38
38
|
var helpers_1 = require("../utils/helpers");
|
|
39
39
|
var authenticator_1 = require("./authenticator");
|
|
40
|
+
var logger_1 = __importDefault(require("../../lib/logger"));
|
|
40
41
|
/**
|
|
41
42
|
* The BearerTokenAuthenticator will set a user-provided bearer token
|
|
42
43
|
* in requests.
|
|
@@ -84,6 +85,7 @@ var BearerTokenAuthenticator = /** @class */ (function (_super) {
|
|
|
84
85
|
return new Promise(function (resolve) {
|
|
85
86
|
var authHeader = { Authorization: "Bearer ".concat(_this.bearerToken) };
|
|
86
87
|
requestOptions.headers = (0, extend_1.default)(true, {}, requestOptions.headers, authHeader);
|
|
88
|
+
logger_1.default.debug("Authenticated outbound request (type=".concat(_this.authenticationType(), ")"));
|
|
87
89
|
resolve();
|
|
88
90
|
});
|
|
89
91
|
};
|
|
@@ -37,6 +37,7 @@ exports.TokenRequestBasedAuthenticator = void 0;
|
|
|
37
37
|
var extend_1 = __importDefault(require("extend"));
|
|
38
38
|
var jwt_token_manager_1 = require("../token-managers/jwt-token-manager");
|
|
39
39
|
var authenticator_1 = require("./authenticator");
|
|
40
|
+
var logger_1 = __importDefault(require("../../lib/logger"));
|
|
40
41
|
/**
|
|
41
42
|
* Class for common functionality shared by token-request authenticators.
|
|
42
43
|
* TokenRequestBasedAuthenticators use token managers to retrieve, store,
|
|
@@ -105,9 +106,11 @@ var TokenRequestBasedAuthenticator = /** @class */ (function (_super) {
|
|
|
105
106
|
* @param requestOptions - The request to augment with authentication information.
|
|
106
107
|
*/
|
|
107
108
|
TokenRequestBasedAuthenticator.prototype.authenticate = function (requestOptions) {
|
|
109
|
+
var _this = this;
|
|
108
110
|
return this.tokenManager.getToken().then(function (token) {
|
|
109
111
|
var authHeader = { Authorization: "Bearer ".concat(token) };
|
|
110
112
|
requestOptions.headers = (0, extend_1.default)(true, {}, requestOptions.headers, authHeader);
|
|
113
|
+
logger_1.default.debug("Authenticated outbound request (type=".concat(_this.authenticationType(), ")"));
|
|
111
114
|
});
|
|
112
115
|
};
|
|
113
116
|
return TokenRequestBasedAuthenticator;
|
|
@@ -38,6 +38,7 @@ var extend_1 = __importDefault(require("extend"));
|
|
|
38
38
|
var helpers_1 = require("../utils/helpers");
|
|
39
39
|
var build_user_agent_1 = require("../../lib/build-user-agent");
|
|
40
40
|
var jwt_token_manager_1 = require("./jwt-token-manager");
|
|
41
|
+
var logger_1 = __importDefault(require("../../lib/logger"));
|
|
41
42
|
/**
|
|
42
43
|
* Token Manager of CloudPak for data.
|
|
43
44
|
*
|
|
@@ -99,7 +100,11 @@ var Cp4dTokenManager = /** @class */ (function (_super) {
|
|
|
99
100
|
rejectUnauthorized: !this.disableSslVerification,
|
|
100
101
|
},
|
|
101
102
|
};
|
|
102
|
-
|
|
103
|
+
logger_1.default.debug("Invoking CP4D token service operation: ".concat(parameters.options.url));
|
|
104
|
+
return this.requestWrapperInstance.sendRequest(parameters).then(function (response) {
|
|
105
|
+
logger_1.default.debug('Returned from CP4D token service operation');
|
|
106
|
+
return response;
|
|
107
|
+
});
|
|
103
108
|
};
|
|
104
109
|
return Cp4dTokenManager;
|
|
105
110
|
}(jwt_token_manager_1.JwtTokenManager));
|
|
@@ -168,7 +168,11 @@ var IamRequestBasedTokenManager = /** @class */ (function (_super) {
|
|
|
168
168
|
rejectUnauthorized: !this.disableSslVerification,
|
|
169
169
|
},
|
|
170
170
|
};
|
|
171
|
-
|
|
171
|
+
logger_1.default.debug("Invoking IAM get_token operation: ".concat(parameters.options.url));
|
|
172
|
+
return this.requestWrapperInstance.sendRequest(parameters).then(function (response) {
|
|
173
|
+
logger_1.default.debug('Returned from IAM get_token operation');
|
|
174
|
+
return response;
|
|
175
|
+
});
|
|
172
176
|
};
|
|
173
177
|
/**
|
|
174
178
|
* Returns true iff the currently-cached IAM access token is expired.
|
|
@@ -38,6 +38,7 @@ var extend_1 = __importDefault(require("extend"));
|
|
|
38
38
|
var helpers_1 = require("../utils/helpers");
|
|
39
39
|
var build_user_agent_1 = require("../../lib/build-user-agent");
|
|
40
40
|
var jwt_token_manager_1 = require("./jwt-token-manager");
|
|
41
|
+
var logger_1 = __importDefault(require("../../lib/logger"));
|
|
41
42
|
/**
|
|
42
43
|
* This is the path associated with the operation used to obtain
|
|
43
44
|
* an access token from the MCSP token service.
|
|
@@ -90,7 +91,11 @@ var McspTokenManager = /** @class */ (function (_super) {
|
|
|
90
91
|
rejectUnauthorized: !this.disableSslVerification,
|
|
91
92
|
},
|
|
92
93
|
};
|
|
93
|
-
|
|
94
|
+
logger_1.default.debug("Invoking MCSP token service operation: ".concat(parameters.options.url));
|
|
95
|
+
return this.requestWrapperInstance.sendRequest(parameters).then(function (response) {
|
|
96
|
+
logger_1.default.debug('Returned from MCSP token service operation');
|
|
97
|
+
return response;
|
|
98
|
+
});
|
|
94
99
|
};
|
|
95
100
|
return McspTokenManager;
|
|
96
101
|
}(jwt_token_manager_1.JwtTokenManager));
|
|
@@ -49,11 +49,13 @@ var TokenManager = /** @class */ (function () {
|
|
|
49
49
|
TokenManager.prototype.getToken = function () {
|
|
50
50
|
var _this = this;
|
|
51
51
|
if (!this.accessToken || this.isTokenExpired()) {
|
|
52
|
-
// 1.
|
|
52
|
+
// 1. Need a new token.
|
|
53
|
+
logger_1.default.debug('Performing synchronous token refresh');
|
|
53
54
|
return this.pacedRequestToken().then(function () { return _this.accessToken; });
|
|
54
55
|
}
|
|
55
|
-
// If refresh needed, kick one off
|
|
56
56
|
if (this.tokenNeedsRefresh()) {
|
|
57
|
+
// 2. Need to refresh the current (valid) token.
|
|
58
|
+
logger_1.default.debug('Performing background asynchronous token fetch');
|
|
57
59
|
this.requestToken().then(function (tokenResponse) {
|
|
58
60
|
_this.saveTokenInfo(tokenResponse);
|
|
59
61
|
}, function (err) {
|
|
@@ -67,7 +69,9 @@ var TokenManager = /** @class */ (function () {
|
|
|
67
69
|
logger_1.default.debug(err);
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
|
-
|
|
72
|
+
else {
|
|
73
|
+
logger_1.default.debug('Using cached access token');
|
|
74
|
+
}
|
|
71
75
|
return Promise.resolve(this.accessToken);
|
|
72
76
|
};
|
|
73
77
|
/**
|
|
@@ -162,7 +162,10 @@ var VpcInstanceTokenManager = /** @class */ (function (_super) {
|
|
|
162
162
|
},
|
|
163
163
|
};
|
|
164
164
|
logger_1.default.debug("Invoking VPC 'create_iam_token' operation: ".concat(parameters.options.url));
|
|
165
|
-
return [2 /*return*/, this.requestWrapperInstance.sendRequest(parameters)
|
|
165
|
+
return [2 /*return*/, this.requestWrapperInstance.sendRequest(parameters).then(function (response) {
|
|
166
|
+
logger_1.default.debug("Returned from VPC 'create_iam_token' operation");
|
|
167
|
+
return response;
|
|
168
|
+
})];
|
|
166
169
|
}
|
|
167
170
|
});
|
|
168
171
|
});
|
|
@@ -48,6 +48,7 @@ function getProperties(serviceName) {
|
|
|
48
48
|
// 3. VCAP Services (Cloud Foundry)
|
|
49
49
|
// only get properties from one source, return null if none found
|
|
50
50
|
var properties = null;
|
|
51
|
+
logger_1.default.debug("Retrieving config properties for service '".concat(serviceName, "'"));
|
|
51
52
|
properties = filterPropertiesByServiceName((0, file_reading_helpers_1.readCredentialsFile)(), serviceName);
|
|
52
53
|
if ((0, helper_1.isEmptyObject)(properties)) {
|
|
53
54
|
properties = filterPropertiesByServiceName(process.env, serviceName);
|
|
@@ -55,6 +56,7 @@ function getProperties(serviceName) {
|
|
|
55
56
|
if ((0, helper_1.isEmptyObject)(properties)) {
|
|
56
57
|
properties = getPropertiesFromVCAP(serviceName);
|
|
57
58
|
}
|
|
59
|
+
logger_1.default.debug("Retrieved ".concat(Object.keys(properties).length, " properties"));
|
|
58
60
|
return properties;
|
|
59
61
|
}
|
|
60
62
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2019,
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2024.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import extend from 'extend';
|
|
17
17
|
import { computeBasicAuthHeader, validateInput } from '../utils/helpers';
|
|
18
18
|
import { Authenticator } from './authenticator';
|
|
19
|
+
import logger from '../../lib/logger';
|
|
19
20
|
/**
|
|
20
21
|
* The BasicAuthenticator is used to add basic authentication information to
|
|
21
22
|
* requests.
|
|
@@ -55,6 +56,7 @@ export class BasicAuthenticator extends Authenticator {
|
|
|
55
56
|
authenticate(requestOptions) {
|
|
56
57
|
return new Promise((resolve) => {
|
|
57
58
|
requestOptions.headers = extend(true, {}, requestOptions.headers, this.authHeader);
|
|
59
|
+
logger.debug(`Authenticated outbound request (type=${this.authenticationType()})`);
|
|
58
60
|
resolve();
|
|
59
61
|
});
|
|
60
62
|
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import extend from 'extend';
|
|
17
17
|
import { validateInput } from '../utils/helpers';
|
|
18
18
|
import { Authenticator } from './authenticator';
|
|
19
|
+
import logger from '../../lib/logger';
|
|
19
20
|
/**
|
|
20
21
|
* The BearerTokenAuthenticator will set a user-provided bearer token
|
|
21
22
|
* in requests.
|
|
@@ -60,6 +61,7 @@ export class BearerTokenAuthenticator extends Authenticator {
|
|
|
60
61
|
return new Promise((resolve) => {
|
|
61
62
|
const authHeader = { Authorization: `Bearer ${this.bearerToken}` };
|
|
62
63
|
requestOptions.headers = extend(true, {}, requestOptions.headers, authHeader);
|
|
64
|
+
logger.debug(`Authenticated outbound request (type=${this.authenticationType()})`);
|
|
63
65
|
resolve();
|
|
64
66
|
});
|
|
65
67
|
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import extend from 'extend';
|
|
17
17
|
import { JwtTokenManager } from '../token-managers/jwt-token-manager';
|
|
18
18
|
import { Authenticator } from './authenticator';
|
|
19
|
+
import logger from '../../lib/logger';
|
|
19
20
|
/**
|
|
20
21
|
* Class for common functionality shared by token-request authenticators.
|
|
21
22
|
* TokenRequestBasedAuthenticators use token managers to retrieve, store,
|
|
@@ -85,6 +86,7 @@ export class TokenRequestBasedAuthenticator extends Authenticator {
|
|
|
85
86
|
return this.tokenManager.getToken().then((token) => {
|
|
86
87
|
const authHeader = { Authorization: `Bearer ${token}` };
|
|
87
88
|
requestOptions.headers = extend(true, {}, requestOptions.headers, authHeader);
|
|
89
|
+
logger.debug(`Authenticated outbound request (type=${this.authenticationType()})`);
|
|
88
90
|
});
|
|
89
91
|
}
|
|
90
92
|
}
|
|
@@ -17,6 +17,7 @@ import extend from 'extend';
|
|
|
17
17
|
import { validateInput } from '../utils/helpers';
|
|
18
18
|
import { buildUserAgent } from '../../lib/build-user-agent';
|
|
19
19
|
import { JwtTokenManager } from './jwt-token-manager';
|
|
20
|
+
import logger from '../../lib/logger';
|
|
20
21
|
/**
|
|
21
22
|
* Token Manager of CloudPak for data.
|
|
22
23
|
*
|
|
@@ -76,6 +77,10 @@ export class Cp4dTokenManager extends JwtTokenManager {
|
|
|
76
77
|
rejectUnauthorized: !this.disableSslVerification,
|
|
77
78
|
},
|
|
78
79
|
};
|
|
79
|
-
|
|
80
|
+
logger.debug(`Invoking CP4D token service operation: ${parameters.options.url}`);
|
|
81
|
+
return this.requestWrapperInstance.sendRequest(parameters).then((response) => {
|
|
82
|
+
logger.debug('Returned from CP4D token service operation');
|
|
83
|
+
return response;
|
|
84
|
+
});
|
|
80
85
|
}
|
|
81
86
|
}
|
|
@@ -144,7 +144,11 @@ export class IamRequestBasedTokenManager extends JwtTokenManager {
|
|
|
144
144
|
rejectUnauthorized: !this.disableSslVerification,
|
|
145
145
|
},
|
|
146
146
|
};
|
|
147
|
-
|
|
147
|
+
logger.debug(`Invoking IAM get_token operation: ${parameters.options.url}`);
|
|
148
|
+
return this.requestWrapperInstance.sendRequest(parameters).then((response) => {
|
|
149
|
+
logger.debug('Returned from IAM get_token operation');
|
|
150
|
+
return response;
|
|
151
|
+
});
|
|
148
152
|
}
|
|
149
153
|
/**
|
|
150
154
|
* Returns true iff the currently-cached IAM access token is expired.
|
|
@@ -17,6 +17,7 @@ import extend from 'extend';
|
|
|
17
17
|
import { validateInput } from '../utils/helpers';
|
|
18
18
|
import { buildUserAgent } from '../../lib/build-user-agent';
|
|
19
19
|
import { JwtTokenManager } from './jwt-token-manager';
|
|
20
|
+
import logger from '../../lib/logger';
|
|
20
21
|
/**
|
|
21
22
|
* This is the path associated with the operation used to obtain
|
|
22
23
|
* an access token from the MCSP token service.
|
|
@@ -67,6 +68,10 @@ export class McspTokenManager extends JwtTokenManager {
|
|
|
67
68
|
rejectUnauthorized: !this.disableSslVerification,
|
|
68
69
|
},
|
|
69
70
|
};
|
|
70
|
-
|
|
71
|
+
logger.debug(`Invoking MCSP token service operation: ${parameters.options.url}`);
|
|
72
|
+
return this.requestWrapperInstance.sendRequest(parameters).then((response) => {
|
|
73
|
+
logger.debug('Returned from MCSP token service operation');
|
|
74
|
+
return response;
|
|
75
|
+
});
|
|
71
76
|
}
|
|
72
77
|
}
|
|
@@ -42,11 +42,13 @@ export class TokenManager {
|
|
|
42
42
|
*/
|
|
43
43
|
getToken() {
|
|
44
44
|
if (!this.accessToken || this.isTokenExpired()) {
|
|
45
|
-
// 1.
|
|
45
|
+
// 1. Need a new token.
|
|
46
|
+
logger.debug('Performing synchronous token refresh');
|
|
46
47
|
return this.pacedRequestToken().then(() => this.accessToken);
|
|
47
48
|
}
|
|
48
|
-
// If refresh needed, kick one off
|
|
49
49
|
if (this.tokenNeedsRefresh()) {
|
|
50
|
+
// 2. Need to refresh the current (valid) token.
|
|
51
|
+
logger.debug('Performing background asynchronous token fetch');
|
|
50
52
|
this.requestToken().then((tokenResponse) => {
|
|
51
53
|
this.saveTokenInfo(tokenResponse);
|
|
52
54
|
}, (err) => {
|
|
@@ -60,7 +62,9 @@ export class TokenManager {
|
|
|
60
62
|
logger.debug(err);
|
|
61
63
|
});
|
|
62
64
|
}
|
|
63
|
-
|
|
65
|
+
else {
|
|
66
|
+
logger.debug('Using cached access token');
|
|
67
|
+
}
|
|
64
68
|
return Promise.resolve(this.accessToken);
|
|
65
69
|
}
|
|
66
70
|
/**
|
|
@@ -108,7 +108,10 @@ export class VpcInstanceTokenManager extends JwtTokenManager {
|
|
|
108
108
|
},
|
|
109
109
|
};
|
|
110
110
|
logger.debug(`Invoking VPC 'create_iam_token' operation: ${parameters.options.url}`);
|
|
111
|
-
return this.requestWrapperInstance.sendRequest(parameters)
|
|
111
|
+
return this.requestWrapperInstance.sendRequest(parameters).then((response) => {
|
|
112
|
+
logger.debug(`Returned from VPC 'create_iam_token' operation`);
|
|
113
|
+
return response;
|
|
114
|
+
});
|
|
112
115
|
});
|
|
113
116
|
}
|
|
114
117
|
getInstanceIdentityToken() {
|
|
@@ -41,6 +41,7 @@ function getProperties(serviceName) {
|
|
|
41
41
|
// 3. VCAP Services (Cloud Foundry)
|
|
42
42
|
// only get properties from one source, return null if none found
|
|
43
43
|
let properties = null;
|
|
44
|
+
logger.debug(`Retrieving config properties for service '${serviceName}'`);
|
|
44
45
|
properties = filterPropertiesByServiceName(readCredentialsFile(), serviceName);
|
|
45
46
|
if (isEmptyObject(properties)) {
|
|
46
47
|
properties = filterPropertiesByServiceName(process.env, serviceName);
|
|
@@ -48,6 +49,7 @@ function getProperties(serviceName) {
|
|
|
48
49
|
if (isEmptyObject(properties)) {
|
|
49
50
|
properties = getPropertiesFromVCAP(serviceName);
|
|
50
51
|
}
|
|
52
|
+
logger.debug(`Retrieved ${Object.keys(properties).length} properties`);
|
|
51
53
|
return properties;
|
|
52
54
|
}
|
|
53
55
|
/**
|
package/es/lib/base-service.js
CHANGED
|
@@ -90,6 +90,7 @@ export class BaseService {
|
|
|
90
90
|
setServiceUrl(url) {
|
|
91
91
|
if (url) {
|
|
92
92
|
this.baseOptions.serviceUrl = stripTrailingSlash(url);
|
|
93
|
+
logger.debug(`Set service URL: ${this.baseOptions.serviceUrl}`);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
@@ -164,6 +165,7 @@ export class BaseService {
|
|
|
164
165
|
* configuration.
|
|
165
166
|
*/
|
|
166
167
|
configureService(serviceName) {
|
|
168
|
+
logger.debug(`Configuring BaseService instance with service name: ${serviceName}`);
|
|
167
169
|
if (!serviceName) {
|
|
168
170
|
const err = 'Error configuring service. Service name is required.';
|
|
169
171
|
logger.error(err);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2024.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Redacts secrets found in "input" so that the resulting string
|
|
18
|
+
* is suitable for debug logging.
|
|
19
|
+
* @param input - the string that potentially contains secrets
|
|
20
|
+
* @returns the input string with secrets replaced with "[redacted]"
|
|
21
|
+
*/
|
|
22
|
+
export declare function redactSecrets(input: string): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2024.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
// Keywords that should be redacted.
|
|
17
|
+
const redactedKeywords = [
|
|
18
|
+
'apikey',
|
|
19
|
+
'api_key',
|
|
20
|
+
'passcode',
|
|
21
|
+
'password',
|
|
22
|
+
'token',
|
|
23
|
+
'aadClientId',
|
|
24
|
+
'aadClientSecret',
|
|
25
|
+
'auth',
|
|
26
|
+
'auth_provider_x509_cert_url',
|
|
27
|
+
'auth_uri',
|
|
28
|
+
'client_email',
|
|
29
|
+
'client_id',
|
|
30
|
+
'client_x509_cert_url',
|
|
31
|
+
'key',
|
|
32
|
+
'project_id',
|
|
33
|
+
'secret',
|
|
34
|
+
'subscriptionId',
|
|
35
|
+
'tenantId',
|
|
36
|
+
'thumbprint',
|
|
37
|
+
'token_uri',
|
|
38
|
+
];
|
|
39
|
+
const redactedTokens = redactedKeywords.join('|');
|
|
40
|
+
// Pre-compiled regular expressions used by redactSecrets().
|
|
41
|
+
const reAuthHeader = new RegExp(`^(Authorization|X-Auth\\S*): .*$`, 'gim');
|
|
42
|
+
const rePropertySetting = new RegExp(`(${redactedTokens})=[^&]*(&|$)`, 'gi');
|
|
43
|
+
const reJsonField = new RegExp(`"([^"]*(${redactedTokens})[^"_]*)":\\s*"[^\\,]*"`, 'gi');
|
|
44
|
+
// RedactSecrets() returns the input string with secrets redacted.
|
|
45
|
+
/**
|
|
46
|
+
* Redacts secrets found in "input" so that the resulting string
|
|
47
|
+
* is suitable for debug logging.
|
|
48
|
+
* @param input - the string that potentially contains secrets
|
|
49
|
+
* @returns the input string with secrets replaced with "[redacted]"
|
|
50
|
+
*/
|
|
51
|
+
export function redactSecrets(input) {
|
|
52
|
+
const redacted = '[redacted]';
|
|
53
|
+
let redactedString = input;
|
|
54
|
+
redactedString = redactedString.replace(reAuthHeader, `$1: ${redacted}`);
|
|
55
|
+
redactedString = redactedString.replace(rePropertySetting, `$1=${redacted}$2`);
|
|
56
|
+
redactedString = redactedString.replace(reJsonField, `"$1":"${redacted}"`);
|
|
57
|
+
return redactedString;
|
|
58
|
+
}
|