ibm-cloud-sdk-core 4.0.0 → 4.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 +20 -30
- package/CHANGELOG.md +16 -4
- package/MIGRATION-V4.md +54 -0
- package/auth/authenticators/authenticator-interface.d.ts +3 -4
- package/auth/authenticators/authenticator-interface.js +1 -1
- package/auth/authenticators/authenticator.d.ts +5 -9
- package/auth/authenticators/authenticator.js +4 -8
- package/auth/authenticators/basic-authenticator.d.ts +12 -12
- package/auth/authenticators/basic-authenticator.js +12 -12
- package/auth/authenticators/bearer-token-authenticator.d.ts +11 -14
- package/auth/authenticators/bearer-token-authenticator.js +11 -14
- package/auth/authenticators/cloud-pak-for-data-authenticator.d.ts +15 -15
- package/auth/authenticators/cloud-pak-for-data-authenticator.js +15 -15
- package/auth/authenticators/container-authenticator.d.ts +23 -23
- package/auth/authenticators/container-authenticator.js +23 -23
- package/auth/authenticators/iam-authenticator.d.ts +20 -20
- package/auth/authenticators/iam-authenticator.js +20 -20
- package/auth/authenticators/iam-request-based-authenticator.d.ts +23 -25
- package/auth/authenticators/iam-request-based-authenticator.js +23 -25
- package/auth/authenticators/token-request-based-authenticator.d.ts +19 -24
- package/auth/authenticators/token-request-based-authenticator.js +19 -24
- package/auth/authenticators/vpc-instance-authenticator.d.ts +17 -16
- package/auth/authenticators/vpc-instance-authenticator.js +17 -16
- package/auth/token-managers/container-token-manager.d.ts +23 -25
- package/auth/token-managers/container-token-manager.js +23 -25
- package/auth/token-managers/cp4d-token-manager.d.ts +13 -13
- package/auth/token-managers/cp4d-token-manager.js +13 -13
- package/auth/token-managers/iam-request-based-token-manager.d.ts +26 -31
- package/auth/token-managers/iam-request-based-token-manager.js +26 -31
- package/auth/token-managers/iam-token-manager.d.ts +17 -16
- package/auth/token-managers/iam-token-manager.js +17 -16
- package/auth/token-managers/jwt-token-manager.d.ts +10 -13
- package/auth/token-managers/jwt-token-manager.js +13 -16
- package/auth/token-managers/token-manager.d.ts +23 -35
- package/auth/token-managers/token-manager.js +22 -34
- package/auth/token-managers/vpc-instance-token-manager.d.ts +15 -15
- package/auth/token-managers/vpc-instance-token-manager.js +15 -15
- package/auth/utils/get-authenticator-from-environment.d.ts +2 -2
- package/auth/utils/get-authenticator-from-environment.js +2 -2
- package/auth/utils/helpers.d.ts +34 -32
- package/auth/utils/helpers.js +34 -32
- package/auth/utils/read-external-sources.d.ts +2 -1
- package/auth/utils/read-external-sources.js +5 -4
- package/build/docs/ibm-cloud-sdk-core.atleastone.md +4 -4
- package/build/docs/ibm-cloud-sdk-core.atmostone.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.authenticator._constructor_.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.authenticator.authenticate.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.authenticator.authenticationtype.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.authenticator.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.authenticatorinterface.authenticate.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.baseservice._constructor_.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.baseservice.configureservice.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.baseservice.createrequest.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.baseservice.enableretries.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.baseservice.getauthenticator.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.baseservice.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.baseservice.setdefaultheaders.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.baseservice.setserviceurl.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator._constructor_.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.authenticate.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator._constructor_.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.authenticate.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.buildrequestfileobject.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.checkcredentials.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator._constructor_.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator.md +5 -5
- package/build/docs/ibm-cloud-sdk-core.computebasicauthheader.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.constructserviceurl.md +4 -4
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator._constructor_.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.md +4 -4
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setcrtokenfilename.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setiamprofileid.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setiamprofilename.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager._constructor_.md +6 -2
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.md +5 -5
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.requesttoken.md +0 -2
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setcrtokenfilename.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setiamprofileid.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setiamprofilename.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager._constructor_.md +6 -2
- package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.fileobject.md +5 -5
- package/build/docs/ibm-cloud-sdk-core.fileoptions.md +4 -4
- package/build/docs/ibm-cloud-sdk-core.filestream.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.filewithmetadata.md +5 -5
- package/build/docs/ibm-cloud-sdk-core.getauthenticatorfromenvironment.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.getcontenttype.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.getcurrenttime.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.getformat.md +0 -2
- package/build/docs/ibm-cloud-sdk-core.getmissingparams.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.getnewlogger.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.getqueryparam.md +1 -5
- package/build/docs/ibm-cloud-sdk-core.iamauthenticator._constructor_.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.iamauthenticator.md +5 -5
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator._constructor_.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.getrefreshtoken.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.md +7 -7
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.setclientidandsecret.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.setscope.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager._constructor_.md +6 -2
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.getrefreshtoken.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.md +8 -8
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.requesttoken.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.savetokeninfo.md +1 -3
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.setclientidandsecret.md +3 -5
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.setscope.md +2 -4
- package/build/docs/ibm-cloud-sdk-core.iamrequestoptions.md +5 -5
- package/build/docs/ibm-cloud-sdk-core.iamtokenmanager._constructor_.md +6 -2
- package/build/docs/ibm-cloud-sdk-core.iamtokenmanager.md +3 -3
- package/build/docs/ibm-cloud-sdk-core.ishtml.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager._constructor_.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.md +5 -5
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.requesttoken.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.savetokeninfo.md +1 -3
- package/build/docs/ibm-cloud-sdk-core.md +24 -24
- package/build/docs/ibm-cloud-sdk-core.onlyone.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.qs.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.readexternalsources.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.removesuffix.md +4 -4
- package/build/docs/ibm-cloud-sdk-core.sdklogger.md +7 -7
- package/build/docs/ibm-cloud-sdk-core.streamtopromise.md +3 -1
- package/build/docs/ibm-cloud-sdk-core.striptrailingslash.md +4 -2
- package/build/docs/ibm-cloud-sdk-core.tokenmanager._constructor_.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.gettoken.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.md +15 -15
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.pacedrequesttoken.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.requesttoken.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.savetokeninfo.md +1 -3
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.setdisablesslverification.md +1 -3
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.setheaders.md +2 -4
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator._constructor_.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.authenticate.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.md +9 -9
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.setdisablesslverification.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.setheaders.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.tolowerkeys.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkforsuccessfulexecution.md +0 -2
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkmediaheaders.md +0 -2
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkurlandmethod.md +1 -3
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkuserheader.md +0 -2
- package/build/docs/ibm-cloud-sdk-core.unittestutils.expecttobepromise.md +0 -2
- package/build/docs/ibm-cloud-sdk-core.unittestutils.getoptions.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.useroptions.md +9 -9
- package/build/docs/ibm-cloud-sdk-core.validateinput.md +8 -2
- package/build/docs/ibm-cloud-sdk-core.validateparams.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator._constructor_.md +6 -2
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.md +6 -6
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.setiamprofilecrn.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.setiamprofileid.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager._constructor_.md +6 -2
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.md +4 -4
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofilecrn.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofileid.md +2 -2
- package/docs/ibm-cloud-sdk-core.api.json +516 -241
- package/es/auth/authenticators/authenticator-interface.d.ts +3 -4
- package/es/auth/authenticators/authenticator-interface.js +1 -1
- package/es/auth/authenticators/authenticator.d.ts +5 -9
- package/es/auth/authenticators/authenticator.js +4 -8
- package/es/auth/authenticators/basic-authenticator.d.ts +12 -12
- package/es/auth/authenticators/basic-authenticator.js +12 -12
- package/es/auth/authenticators/bearer-token-authenticator.d.ts +11 -14
- package/es/auth/authenticators/bearer-token-authenticator.js +11 -14
- package/es/auth/authenticators/cloud-pak-for-data-authenticator.d.ts +15 -15
- package/es/auth/authenticators/cloud-pak-for-data-authenticator.js +15 -15
- package/es/auth/authenticators/container-authenticator.d.ts +23 -23
- package/es/auth/authenticators/container-authenticator.js +23 -23
- package/es/auth/authenticators/iam-authenticator.d.ts +20 -20
- package/es/auth/authenticators/iam-authenticator.js +20 -20
- package/es/auth/authenticators/iam-request-based-authenticator.d.ts +23 -25
- package/es/auth/authenticators/iam-request-based-authenticator.js +23 -25
- package/es/auth/authenticators/token-request-based-authenticator.d.ts +19 -24
- package/es/auth/authenticators/token-request-based-authenticator.js +19 -24
- package/es/auth/authenticators/vpc-instance-authenticator.d.ts +17 -16
- package/es/auth/authenticators/vpc-instance-authenticator.js +17 -16
- package/es/auth/token-managers/container-token-manager.d.ts +23 -25
- package/es/auth/token-managers/container-token-manager.js +23 -25
- package/es/auth/token-managers/cp4d-token-manager.d.ts +13 -13
- package/es/auth/token-managers/cp4d-token-manager.js +13 -13
- package/es/auth/token-managers/iam-request-based-token-manager.d.ts +26 -31
- package/es/auth/token-managers/iam-request-based-token-manager.js +26 -31
- package/es/auth/token-managers/iam-token-manager.d.ts +17 -16
- package/es/auth/token-managers/iam-token-manager.js +17 -16
- package/es/auth/token-managers/jwt-token-manager.d.ts +10 -13
- package/es/auth/token-managers/jwt-token-manager.js +13 -16
- package/es/auth/token-managers/token-manager.d.ts +23 -35
- package/es/auth/token-managers/token-manager.js +22 -34
- package/es/auth/token-managers/vpc-instance-token-manager.d.ts +15 -15
- package/es/auth/token-managers/vpc-instance-token-manager.js +15 -15
- package/es/auth/utils/get-authenticator-from-environment.d.ts +2 -2
- package/es/auth/utils/get-authenticator-from-environment.js +2 -2
- package/es/auth/utils/helpers.d.ts +34 -32
- package/es/auth/utils/helpers.js +34 -32
- package/es/auth/utils/read-external-sources.d.ts +2 -1
- package/es/auth/utils/read-external-sources.js +5 -4
- package/es/lib/base-service.d.ts +31 -32
- package/es/lib/base-service.js +31 -32
- package/es/lib/content-type.js +5 -5
- package/es/lib/get-new-logger.d.ts +2 -2
- package/es/lib/get-new-logger.js +2 -2
- package/es/lib/helper.d.ts +24 -31
- package/es/lib/helper.js +25 -32
- package/es/lib/querystring.d.ts +1 -1
- package/es/lib/querystring.js +3 -3
- package/es/lib/request-wrapper.d.ts +4 -6
- package/es/lib/request-wrapper.js +17 -23
- package/es/lib/sdk-test-helpers.d.ts +14 -19
- package/es/lib/sdk-test-helpers.js +14 -19
- package/es/lib/stream-to-promise.d.ts +3 -3
- package/es/lib/stream-to-promise.js +3 -3
- package/es/tsdoc-metadata.json +1 -1
- package/etc/ibm-cloud-sdk-core.api.md +12 -12
- package/ibm-cloud-sdk-core.d.ts +1402 -1449
- package/lib/base-service.d.ts +31 -32
- package/lib/base-service.js +31 -32
- package/lib/content-type.js +5 -5
- package/lib/get-new-logger.d.ts +2 -2
- package/lib/get-new-logger.js +2 -2
- package/lib/helper.d.ts +24 -31
- package/lib/helper.js +25 -32
- package/lib/querystring.d.ts +1 -1
- package/lib/querystring.js +3 -3
- package/lib/request-wrapper.d.ts +4 -6
- package/lib/request-wrapper.js +17 -23
- package/lib/sdk-test-helpers.d.ts +14 -19
- package/lib/sdk-test-helpers.js +14 -19
- package/lib/stream-to-promise.d.ts +3 -3
- package/lib/stream-to-promise.js +3 -3
- package/package.json +2 -2
- package/temp/ibm-cloud-sdk-core.api.json +516 -241
- package/temp/ibm-cloud-sdk-core.api.md +12 -12
- package/MIGRATION-V1.md +0 -42
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable class-methods-use-this */
|
|
2
2
|
/**
|
|
3
|
-
* (C) Copyright IBM Corp. 2019,
|
|
3
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
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.
|
|
@@ -25,15 +25,14 @@ import { TokenManager } from './token-manager';
|
|
|
25
25
|
*/
|
|
26
26
|
export class JwtTokenManager extends TokenManager {
|
|
27
27
|
/**
|
|
28
|
-
* Create a new
|
|
29
|
-
*
|
|
30
|
-
* @param
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* outbound HTTP requests to token services.
|
|
28
|
+
* Create a new JwtTokenManager instance.
|
|
29
|
+
*
|
|
30
|
+
* @param options - Configuration options.
|
|
31
|
+
* This should be an object containing these fields:
|
|
32
|
+
* - url: (optional) the endpoint URL for the token service
|
|
33
|
+
* - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
|
|
34
|
+
* should be disabled or not
|
|
35
|
+
* - headers: (optional) a set of HTTP headers to be sent with each request to the token service
|
|
37
36
|
*/
|
|
38
37
|
constructor(options) {
|
|
39
38
|
// all parameters are optional
|
|
@@ -45,7 +44,7 @@ export class JwtTokenManager extends TokenManager {
|
|
|
45
44
|
/**
|
|
46
45
|
* Request a JWT using an API key.
|
|
47
46
|
*
|
|
48
|
-
* @returns
|
|
47
|
+
* @returns Promise
|
|
49
48
|
*/
|
|
50
49
|
requestToken() {
|
|
51
50
|
const errMsg = '`requestToken` MUST be overridden by a subclass of JwtTokenManagerV1.';
|
|
@@ -56,9 +55,7 @@ export class JwtTokenManager extends TokenManager {
|
|
|
56
55
|
/**
|
|
57
56
|
* Save the JWT service response and the calculated expiration time to the object's state.
|
|
58
57
|
*
|
|
59
|
-
* @param tokenResponse -
|
|
60
|
-
* @protected
|
|
61
|
-
* @returns {void}
|
|
58
|
+
* @param tokenResponse - the response object from JWT service request
|
|
62
59
|
*/
|
|
63
60
|
saveTokenInfo(tokenResponse) {
|
|
64
61
|
const responseBody = tokenResponse.result || {};
|
|
@@ -68,14 +65,14 @@ export class JwtTokenManager extends TokenManager {
|
|
|
68
65
|
logger.error(err);
|
|
69
66
|
throw new Error(err);
|
|
70
67
|
}
|
|
71
|
-
// the time of expiration is found by decoding the JWT access token
|
|
72
|
-
// exp is the time of expire and iat is the time of token retrieval
|
|
73
68
|
const decodedResponse = decode(this.accessToken);
|
|
74
69
|
if (!decodedResponse) {
|
|
75
70
|
const err = 'Access token recieved is not a valid JWT';
|
|
76
71
|
logger.error(err);
|
|
77
72
|
throw new Error(err);
|
|
78
73
|
}
|
|
74
|
+
// the time of expiration is found by decoding the JWT access token
|
|
75
|
+
// 'exp' is the time of expire and 'iat' is the time of token retrieval
|
|
79
76
|
const { exp, iat } = decodedResponse;
|
|
80
77
|
// There are no required claims in JWT
|
|
81
78
|
if (!exp || !iat) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/**
|
|
3
|
-
* (C) Copyright IBM Corp. 2020,
|
|
3
|
+
* (C) Copyright IBM Corp. 2020, 2022.
|
|
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.
|
|
@@ -33,8 +33,8 @@ export type TokenManagerOptions = {
|
|
|
33
33
|
/**
|
|
34
34
|
* A class for shared functionality for storing, and requesting tokens.
|
|
35
35
|
* Intended to be used as a parent to be extended for token request management.
|
|
36
|
-
* Child classes should implement
|
|
37
|
-
* from intended sources and
|
|
36
|
+
* Child classes should implement "requestToken()" to retrieve the token
|
|
37
|
+
* from intended sources and "saveTokenInfo(tokenResponse)" to parse and save
|
|
38
38
|
* token information from the response.
|
|
39
39
|
*/
|
|
40
40
|
export declare class TokenManager {
|
|
@@ -48,40 +48,36 @@ export declare class TokenManager {
|
|
|
48
48
|
private requestTime;
|
|
49
49
|
private pendingRequests;
|
|
50
50
|
/**
|
|
51
|
-
* Create a new
|
|
52
|
-
*
|
|
53
|
-
* @param
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* outbound HTTP requests to token services.
|
|
51
|
+
* Create a new TokenManager instance.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Configuration options.
|
|
54
|
+
* This should be an object containing these fields:
|
|
55
|
+
* - url: (optional) the endpoint URL for the token service
|
|
56
|
+
* - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
|
|
57
|
+
* should be disabled or not
|
|
58
|
+
* - headers: (optional) a set of HTTP headers to be sent with each request to the token service
|
|
60
59
|
*/
|
|
61
60
|
constructor(options: TokenManagerOptions);
|
|
62
61
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
62
|
+
* Retrieves a new token using "requestToken()" if there is not a
|
|
63
|
+
* currently stored token from a previous call, or the previous token
|
|
64
|
+
* has expired.
|
|
66
65
|
*/
|
|
67
66
|
getToken(): Promise<any>;
|
|
68
67
|
/**
|
|
69
|
-
*
|
|
68
|
+
* Sets the "disableSslVerification" property.
|
|
70
69
|
*
|
|
71
|
-
* @param
|
|
72
|
-
* property
|
|
73
|
-
* @returns {void}
|
|
70
|
+
* @param value - the new value for the disableSslVerification property
|
|
74
71
|
*/
|
|
75
72
|
setDisableSslVerification(value: boolean): void;
|
|
76
73
|
/**
|
|
77
|
-
*
|
|
74
|
+
* Sets the headers to be included with each outbound request to the token server.
|
|
78
75
|
*
|
|
79
|
-
* @param
|
|
80
|
-
* @returns {void}
|
|
76
|
+
* @param headers - the set of headers to send with each request to the token server
|
|
81
77
|
*/
|
|
82
78
|
setHeaders(headers: OutgoingHttpHeaders): void;
|
|
83
79
|
/**
|
|
84
|
-
* Paces requests to
|
|
80
|
+
* Paces requests to requestToken().
|
|
85
81
|
*
|
|
86
82
|
* This method pseudo-serializes requests for an access_token
|
|
87
83
|
* when the current token is undefined or expired.
|
|
@@ -95,7 +91,7 @@ export declare class TokenManager {
|
|
|
95
91
|
/**
|
|
96
92
|
* Request a token using an API endpoint.
|
|
97
93
|
*
|
|
98
|
-
* @returns
|
|
94
|
+
* @returns Promise
|
|
99
95
|
*/
|
|
100
96
|
protected requestToken(): Promise<any>;
|
|
101
97
|
/**
|
|
@@ -104,24 +100,16 @@ export declare class TokenManager {
|
|
|
104
100
|
* Calculate expiration and refresh time from the received info
|
|
105
101
|
* and store them in fields `expireTime` and `refreshTime`.
|
|
106
102
|
*
|
|
107
|
-
* @param tokenResponse -
|
|
108
|
-
* @protected
|
|
109
|
-
* @returns {void}
|
|
103
|
+
* @param tokenResponse - the response object from a token service request
|
|
110
104
|
*/
|
|
111
105
|
protected saveTokenInfo(tokenResponse: any): void;
|
|
112
106
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @private
|
|
116
|
-
* @returns {boolean}
|
|
107
|
+
* Checks if currently-stored token is expired
|
|
117
108
|
*/
|
|
118
109
|
private isTokenExpired;
|
|
119
110
|
/**
|
|
120
|
-
*
|
|
111
|
+
* Checks if currently-stored token should be refreshed
|
|
121
112
|
* i.e. past the window to request a new token
|
|
122
|
-
*
|
|
123
|
-
* @private
|
|
124
|
-
* @returns {boolean}
|
|
125
113
|
*/
|
|
126
114
|
private tokenNeedsRefresh;
|
|
127
115
|
}
|
|
@@ -6,21 +6,20 @@ import { getCurrentTime } from '../utils';
|
|
|
6
6
|
/**
|
|
7
7
|
* A class for shared functionality for storing, and requesting tokens.
|
|
8
8
|
* Intended to be used as a parent to be extended for token request management.
|
|
9
|
-
* Child classes should implement
|
|
10
|
-
* from intended sources and
|
|
9
|
+
* Child classes should implement "requestToken()" to retrieve the token
|
|
10
|
+
* from intended sources and "saveTokenInfo(tokenResponse)" to parse and save
|
|
11
11
|
* token information from the response.
|
|
12
12
|
*/
|
|
13
13
|
export class TokenManager {
|
|
14
14
|
/**
|
|
15
|
-
* Create a new
|
|
16
|
-
*
|
|
17
|
-
* @param
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* outbound HTTP requests to token services.
|
|
15
|
+
* Create a new TokenManager instance.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Configuration options.
|
|
18
|
+
* This should be an object containing these fields:
|
|
19
|
+
* - url: (optional) the endpoint URL for the token service
|
|
20
|
+
* - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
|
|
21
|
+
* should be disabled or not
|
|
22
|
+
* - headers: (optional) a set of HTTP headers to be sent with each request to the token service
|
|
24
23
|
*/
|
|
25
24
|
constructor(options) {
|
|
26
25
|
// all parameters are optional
|
|
@@ -37,9 +36,9 @@ export class TokenManager {
|
|
|
37
36
|
this.pendingRequests = [];
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
39
|
+
* Retrieves a new token using "requestToken()" if there is not a
|
|
40
|
+
* currently stored token from a previous call, or the previous token
|
|
41
|
+
* has expired.
|
|
43
42
|
*/
|
|
44
43
|
getToken() {
|
|
45
44
|
if (!this.accessToken || this.isTokenExpired()) {
|
|
@@ -56,11 +55,9 @@ export class TokenManager {
|
|
|
56
55
|
return Promise.resolve(this.accessToken);
|
|
57
56
|
}
|
|
58
57
|
/**
|
|
59
|
-
*
|
|
58
|
+
* Sets the "disableSslVerification" property.
|
|
60
59
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* property
|
|
63
|
-
* @returns {void}
|
|
60
|
+
* @param value - the new value for the disableSslVerification property
|
|
64
61
|
*/
|
|
65
62
|
setDisableSslVerification(value) {
|
|
66
63
|
// if they try to pass in a non-boolean value,
|
|
@@ -68,10 +65,9 @@ export class TokenManager {
|
|
|
68
65
|
this.disableSslVerification = Boolean(value);
|
|
69
66
|
}
|
|
70
67
|
/**
|
|
71
|
-
*
|
|
68
|
+
* Sets the headers to be included with each outbound request to the token server.
|
|
72
69
|
*
|
|
73
|
-
* @param
|
|
74
|
-
* @returns {void}
|
|
70
|
+
* @param headers - the set of headers to send with each request to the token server
|
|
75
71
|
*/
|
|
76
72
|
setHeaders(headers) {
|
|
77
73
|
if (typeof headers !== 'object') {
|
|
@@ -81,7 +77,7 @@ export class TokenManager {
|
|
|
81
77
|
this.headers = headers;
|
|
82
78
|
}
|
|
83
79
|
/**
|
|
84
|
-
* Paces requests to
|
|
80
|
+
* Paces requests to requestToken().
|
|
85
81
|
*
|
|
86
82
|
* This method pseudo-serializes requests for an access_token
|
|
87
83
|
* when the current token is undefined or expired.
|
|
@@ -119,7 +115,7 @@ export class TokenManager {
|
|
|
119
115
|
/**
|
|
120
116
|
* Request a token using an API endpoint.
|
|
121
117
|
*
|
|
122
|
-
* @returns
|
|
118
|
+
* @returns Promise
|
|
123
119
|
*/
|
|
124
120
|
requestToken() {
|
|
125
121
|
const errMsg = '`requestToken` MUST be overridden by a subclass of TokenManagerV1.';
|
|
@@ -133,19 +129,14 @@ export class TokenManager {
|
|
|
133
129
|
* Calculate expiration and refresh time from the received info
|
|
134
130
|
* and store them in fields `expireTime` and `refreshTime`.
|
|
135
131
|
*
|
|
136
|
-
* @param tokenResponse -
|
|
137
|
-
* @protected
|
|
138
|
-
* @returns {void}
|
|
132
|
+
* @param tokenResponse - the response object from a token service request
|
|
139
133
|
*/
|
|
140
134
|
saveTokenInfo(tokenResponse) {
|
|
141
135
|
const errMsg = '`saveTokenInfo` MUST be overridden by a subclass of TokenManager.';
|
|
142
136
|
logger.error(errMsg);
|
|
143
137
|
}
|
|
144
138
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* @private
|
|
148
|
-
* @returns {boolean}
|
|
139
|
+
* Checks if currently-stored token is expired
|
|
149
140
|
*/
|
|
150
141
|
isTokenExpired() {
|
|
151
142
|
const { expireTime } = this;
|
|
@@ -156,11 +147,8 @@ export class TokenManager {
|
|
|
156
147
|
return expireTime <= currentTime;
|
|
157
148
|
}
|
|
158
149
|
/**
|
|
159
|
-
*
|
|
150
|
+
* Checks if currently-stored token should be refreshed
|
|
160
151
|
* i.e. past the window to request a new token
|
|
161
|
-
*
|
|
162
|
-
* @private
|
|
163
|
-
* @returns {boolean}
|
|
164
152
|
*/
|
|
165
153
|
tokenNeedsRefresh() {
|
|
166
154
|
const { refreshTime } = this;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2021.
|
|
2
|
+
* (C) Copyright IBM Corp. 2021, 2022.
|
|
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.
|
|
@@ -28,27 +28,27 @@ export declare class VpcInstanceTokenManager extends JwtTokenManager {
|
|
|
28
28
|
private iamProfileCrn;
|
|
29
29
|
private iamProfileId;
|
|
30
30
|
/**
|
|
31
|
-
* Create a new
|
|
31
|
+
* Create a new VpcInstanceTokenManager instance.
|
|
32
32
|
*
|
|
33
|
-
* @param
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
33
|
+
* @param options - Configuration options.
|
|
34
|
+
* This should be an object containing these fields:
|
|
35
|
+
* - url: (optional) the endpoint URL for the VPC Instance Metadata Service (default value: "http://169.254.169.254")
|
|
36
|
+
* - iamProfileCrn: (optional) the CRN of the linked IAM trusted profile to be used to obtain the IAM access token
|
|
37
|
+
* - iamProfileId: (optional) the ID of the linked IAM trusted profile to be used to obtain the IAM access token
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* At most one of "iamProfileCrn" or "iamProfileId" may be specified. If neither one is specified,
|
|
41
|
+
* then the default IAM profile defined for the compute resource will be used.
|
|
42
42
|
*/
|
|
43
43
|
constructor(options: Options);
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param
|
|
45
|
+
* Sets the CRN of the IAM trusted profile to use when fetching the access token from the IAM token server.
|
|
46
|
+
* @param iamProfileCrn - the CRN of the IAM trusted profile
|
|
47
47
|
*/
|
|
48
48
|
setIamProfileCrn(iamProfileCrn: string): void;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
* @param
|
|
50
|
+
* Sets the Id of the IAM trusted profile to use when fetching the access token from the IAM token server.
|
|
51
|
+
* @param iamProfileId - the ID of the IAM trusted profile
|
|
52
52
|
*/
|
|
53
53
|
setIamProfileId(iamProfileId: string): void;
|
|
54
54
|
protected requestToken(): Promise<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2021.
|
|
2
|
+
* (C) Copyright IBM Corp. 2021, 2022.
|
|
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.
|
|
@@ -32,17 +32,17 @@ const METADATA_SERVICE_VERSION = '2021-09-20';
|
|
|
32
32
|
*/
|
|
33
33
|
export class VpcInstanceTokenManager extends JwtTokenManager {
|
|
34
34
|
/**
|
|
35
|
-
* Create a new
|
|
35
|
+
* Create a new VpcInstanceTokenManager instance.
|
|
36
36
|
*
|
|
37
|
-
* @param
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
37
|
+
* @param options - Configuration options.
|
|
38
|
+
* This should be an object containing these fields:
|
|
39
|
+
* - url: (optional) the endpoint URL for the VPC Instance Metadata Service (default value: "http://169.254.169.254")
|
|
40
|
+
* - iamProfileCrn: (optional) the CRN of the linked IAM trusted profile to be used to obtain the IAM access token
|
|
41
|
+
* - iamProfileId: (optional) the ID of the linked IAM trusted profile to be used to obtain the IAM access token
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* At most one of "iamProfileCrn" or "iamProfileId" may be specified. If neither one is specified,
|
|
45
|
+
* then the default IAM profile defined for the compute resource will be used.
|
|
46
46
|
*/
|
|
47
47
|
constructor(options) {
|
|
48
48
|
// all parameters are optional
|
|
@@ -60,15 +60,15 @@ export class VpcInstanceTokenManager extends JwtTokenManager {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @param
|
|
63
|
+
* Sets the CRN of the IAM trusted profile to use when fetching the access token from the IAM token server.
|
|
64
|
+
* @param iamProfileCrn - the CRN of the IAM trusted profile
|
|
65
65
|
*/
|
|
66
66
|
setIamProfileCrn(iamProfileCrn) {
|
|
67
67
|
this.iamProfileCrn = iamProfileCrn;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @param
|
|
70
|
+
* Sets the Id of the IAM trusted profile to use when fetching the access token from the IAM token server.
|
|
71
|
+
* @param iamProfileId - the ID of the IAM trusted profile
|
|
72
72
|
*/
|
|
73
73
|
setIamProfileId(iamProfileId) {
|
|
74
74
|
this.iamProfileId = iamProfileId;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2019,
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
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.
|
|
@@ -22,7 +22,7 @@ import { Authenticator } from '../authenticators';
|
|
|
22
22
|
* 2. Environment variables
|
|
23
23
|
* 3. VCAP Services (Cloud Foundry)
|
|
24
24
|
*
|
|
25
|
-
* @param
|
|
25
|
+
* @param serviceName - the service name prefix.
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
28
|
export declare function getAuthenticatorFromEnvironment(serviceName: string): Authenticator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2019,
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
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.
|
|
@@ -23,7 +23,7 @@ import { readExternalSources } from './read-external-sources';
|
|
|
23
23
|
* 2. Environment variables
|
|
24
24
|
* 3. VCAP Services (Cloud Foundry)
|
|
25
25
|
*
|
|
26
|
-
* @param
|
|
26
|
+
* @param serviceName - the service name prefix.
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
29
|
export function getAuthenticatorFromEnvironment(serviceName) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2019,
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
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,66 +16,68 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* Compute and return a Basic Authorization header from a username and password.
|
|
18
18
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @returns
|
|
19
|
+
* @param username - The username or client id
|
|
20
|
+
* @param password - The password or client secret
|
|
21
|
+
* @returns a Basic Auth header with format "Basic <encoded-credentials>"
|
|
22
22
|
*/
|
|
23
23
|
export declare function computeBasicAuthHeader(username: string, password: string): string;
|
|
24
24
|
/**
|
|
25
|
-
* Checks credentials for common user mistakes of copying {, }, or " characters from the documentation
|
|
25
|
+
* Checks credentials for common user mistakes of copying \{, \}, or \" characters from the documentation
|
|
26
26
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @returns
|
|
27
|
+
* @param obj - the options object holding credentials
|
|
28
|
+
* @param credsToCheck - an array containing the keys of the credentials to check for problems
|
|
29
|
+
* @returns a string with the error message if there were problems, null if not
|
|
30
30
|
*/
|
|
31
31
|
export declare function checkCredentials(obj: any, credsToCheck: string[]): Error | null;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param
|
|
33
|
+
* Validates "options".
|
|
34
|
+
* @param options - a configuration options object
|
|
35
|
+
* @param requiredOptions - the list of properties that must be present in "options"
|
|
36
|
+
*
|
|
37
|
+
* @throws Error: "options" failed validation
|
|
35
38
|
*/
|
|
36
39
|
export declare function validateInput(options: any, requiredOptions: string[]): void;
|
|
37
40
|
/**
|
|
38
|
-
*
|
|
41
|
+
* Gets the current time.
|
|
39
42
|
*
|
|
40
|
-
* @returns
|
|
43
|
+
* @returns the current time in seconds.
|
|
41
44
|
*/
|
|
42
45
|
export declare function getCurrentTime(): number;
|
|
43
46
|
/**
|
|
44
|
-
*
|
|
47
|
+
* Checks for only one of two elements being defined.
|
|
45
48
|
* Returns true if a is defined and b is undefined,
|
|
46
49
|
* or vice versa. Returns false if both are defined
|
|
47
50
|
* or both are undefined.
|
|
48
51
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @returns
|
|
52
|
+
* @param a - The first object
|
|
53
|
+
* @param b - The second object
|
|
54
|
+
* @returns true if and only if exactly one of a or b is defined
|
|
52
55
|
*/
|
|
53
56
|
export declare function onlyOne(a: any, b: any): boolean;
|
|
54
57
|
/**
|
|
55
|
-
*
|
|
58
|
+
* Removes a given suffix if it exists.
|
|
59
|
+
*
|
|
60
|
+
* @param str - the base string to operate on
|
|
61
|
+
* @param suffix - the suffix to remove, if present
|
|
56
62
|
*
|
|
57
|
-
* @
|
|
58
|
-
* @param {string} suffix - The suffix to remove, if present
|
|
59
|
-
* @returns {string}
|
|
63
|
+
* @returns the substring of "str" that remains after the suffix is removed
|
|
60
64
|
*/
|
|
61
65
|
export declare function removeSuffix(str: string, suffix: string): string;
|
|
62
66
|
/**
|
|
63
|
-
*
|
|
64
|
-
* Returns true if a or b is defined. Returns false if
|
|
65
|
-
* both are undefined.
|
|
67
|
+
* Checks for at least one of two elements being defined.
|
|
66
68
|
*
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @returns
|
|
69
|
+
* @param a - the first object
|
|
70
|
+
* @param b - the second object
|
|
71
|
+
* @returns true if a or b is defined; false if both are undefined
|
|
70
72
|
*/
|
|
71
73
|
export declare function atLeastOne(a: any, b: any): boolean;
|
|
72
74
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
75
|
+
* Verifies that both properties are not specified.
|
|
76
|
+
*
|
|
77
|
+
* @param a - The first object
|
|
78
|
+
* @param b - The second object
|
|
76
79
|
*
|
|
77
|
-
* @
|
|
78
|
-
|
|
79
|
-
* @returns {boolean}
|
|
80
|
+
* @returns false if a and b are both defined, true otherwise
|
|
81
|
+
|
|
80
82
|
*/
|
|
81
83
|
export declare function atMostOne(a: any, b: any): boolean;
|