ibm-cloud-sdk-core 5.0.1 → 5.1.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/.secrets.baseline +128 -24
- package/Authentication.md +146 -21
- package/CHANGELOG.md +14 -0
- package/README.md +3 -2
- package/auth/authenticators/authenticator.d.ts +1 -0
- package/auth/authenticators/authenticator.js +1 -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/container-authenticator.d.ts +6 -0
- package/auth/authenticators/container-authenticator.js +8 -0
- package/auth/authenticators/iam-assume-authenticator.d.ts +82 -0
- package/auth/authenticators/iam-assume-authenticator.js +92 -0
- package/auth/authenticators/iam-authenticator.d.ts +6 -0
- package/auth/authenticators/iam-authenticator.js +8 -0
- package/auth/authenticators/iam-request-based-authenticator-immutable.d.ts +64 -0
- package/auth/authenticators/iam-request-based-authenticator-immutable.js +74 -0
- package/auth/authenticators/iam-request-based-authenticator.d.ts +19 -47
- package/auth/authenticators/iam-request-based-authenticator.js +28 -36
- package/auth/authenticators/index.d.ts +4 -1
- package/auth/authenticators/index.js +3 -1
- package/auth/authenticators/token-request-based-authenticator-immutable.d.ts +71 -0
- package/auth/authenticators/token-request-based-authenticator-immutable.js +91 -0
- package/auth/authenticators/token-request-based-authenticator.d.ts +4 -42
- package/auth/authenticators/token-request-based-authenticator.js +5 -40
- package/auth/token-managers/container-token-manager.d.ts +6 -0
- package/auth/token-managers/container-token-manager.js +18 -50
- package/auth/token-managers/cp4d-token-manager.js +6 -1
- package/auth/token-managers/iam-assume-token-manager.d.ts +101 -0
- package/auth/token-managers/iam-assume-token-manager.js +220 -0
- package/auth/token-managers/iam-request-based-token-manager.d.ts +3 -9
- package/auth/token-managers/iam-request-based-token-manager.js +5 -9
- package/auth/token-managers/iam-token-manager.d.ts +8 -2
- package/auth/token-managers/iam-token-manager.js +10 -2
- package/auth/token-managers/index.d.ts +4 -2
- package/auth/token-managers/index.js +6 -3
- 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/get-authenticator-from-environment.js +3 -0
- package/auth/utils/helpers.d.ts +18 -23
- package/auth/utils/helpers.js +50 -30
- package/auth/utils/read-external-sources.js +2 -0
- package/docs/ibm-cloud-sdk-core.api.json +787 -404
- package/es/auth/authenticators/authenticator.d.ts +1 -0
- package/es/auth/authenticators/authenticator.js +1 -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/container-authenticator.d.ts +6 -0
- package/es/auth/authenticators/container-authenticator.js +8 -0
- package/es/auth/authenticators/iam-assume-authenticator.d.ts +82 -0
- package/es/auth/authenticators/iam-assume-authenticator.js +70 -0
- package/es/auth/authenticators/iam-authenticator.d.ts +6 -0
- package/es/auth/authenticators/iam-authenticator.js +8 -0
- package/es/auth/authenticators/iam-request-based-authenticator-immutable.d.ts +64 -0
- package/es/auth/authenticators/iam-request-based-authenticator-immutable.js +51 -0
- package/es/auth/authenticators/iam-request-based-authenticator.d.ts +19 -47
- package/es/auth/authenticators/iam-request-based-authenticator.js +26 -35
- package/es/auth/authenticators/index.d.ts +4 -1
- package/es/auth/authenticators/index.js +1 -0
- package/es/auth/authenticators/token-request-based-authenticator-immutable.d.ts +71 -0
- package/es/auth/authenticators/token-request-based-authenticator-immutable.js +65 -0
- package/es/auth/authenticators/token-request-based-authenticator.d.ts +4 -42
- package/es/auth/authenticators/token-request-based-authenticator.js +3 -37
- package/es/auth/token-managers/container-token-manager.d.ts +6 -0
- package/es/auth/token-managers/container-token-manager.js +18 -24
- package/es/auth/token-managers/cp4d-token-manager.js +6 -1
- package/es/auth/token-managers/iam-assume-token-manager.d.ts +101 -0
- package/es/auth/token-managers/iam-assume-token-manager.js +164 -0
- package/es/auth/token-managers/iam-request-based-token-manager.d.ts +3 -9
- package/es/auth/token-managers/iam-request-based-token-manager.js +5 -9
- package/es/auth/token-managers/iam-token-manager.d.ts +8 -2
- package/es/auth/token-managers/iam-token-manager.js +10 -2
- package/es/auth/token-managers/index.d.ts +4 -2
- package/es/auth/token-managers/index.js +4 -2
- 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/get-authenticator-from-environment.js +4 -1
- package/es/auth/utils/helpers.d.ts +18 -23
- package/es/auth/utils/helpers.js +35 -27
- 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/etc/ibm-cloud-sdk-core.api.md +46 -28
- package/ibm-cloud-sdk-core.d.ts +306 -68
- 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 +5 -4
- package/sdk-test-utilities/package-lock.json +8 -5
- package/sdk-test-utilities/package.json +3 -0
|
@@ -96,14 +96,6 @@ export class IamRequestBasedTokenManager extends JwtTokenManager {
|
|
|
96
96
|
logger.warn(CLIENT_ID_SECRET_WARNING);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns the most recently stored refresh token.
|
|
101
|
-
*
|
|
102
|
-
* @returns the refresh token
|
|
103
|
-
*/
|
|
104
|
-
getRefreshToken() {
|
|
105
|
-
return this.refreshToken;
|
|
106
|
-
}
|
|
107
99
|
/**
|
|
108
100
|
* Extend this method from the parent class to extract the refresh token from
|
|
109
101
|
* the request and save it.
|
|
@@ -144,7 +136,11 @@ export class IamRequestBasedTokenManager extends JwtTokenManager {
|
|
|
144
136
|
rejectUnauthorized: !this.disableSslVerification,
|
|
145
137
|
},
|
|
146
138
|
};
|
|
147
|
-
|
|
139
|
+
logger.debug(`Invoking IAM get_token operation: ${parameters.options.url}`);
|
|
140
|
+
return this.requestWrapperInstance.sendRequest(parameters).then((response) => {
|
|
141
|
+
logger.debug('Returned from IAM get_token operation');
|
|
142
|
+
return response;
|
|
143
|
+
});
|
|
148
144
|
}
|
|
149
145
|
/**
|
|
150
146
|
* Returns true iff the currently-cached IAM access token is expired.
|
|
@@ -19,8 +19,8 @@ interface Options extends IamRequestOptions {
|
|
|
19
19
|
apikey: string;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* The
|
|
23
|
-
* the IAM token service to obtain and store a suitable bearer token. Additionally, the
|
|
22
|
+
* The IamTokenManager takes an api key and performs the necessary interactions with
|
|
23
|
+
* the IAM token service to obtain and store a suitable bearer token. Additionally, the IamTokenManager
|
|
24
24
|
* will retrieve bearer tokens via basic auth using a supplied "clientId" and "clientSecret" pair.
|
|
25
25
|
*/
|
|
26
26
|
export declare class IamTokenManager extends IamRequestBasedTokenManager {
|
|
@@ -46,5 +46,11 @@ export declare class IamTokenManager extends IamRequestBasedTokenManager {
|
|
|
46
46
|
* @throws Error: the configuration options are not valid.
|
|
47
47
|
*/
|
|
48
48
|
constructor(options: Options);
|
|
49
|
+
/**
|
|
50
|
+
* Returns the most recently stored refresh token.
|
|
51
|
+
*
|
|
52
|
+
* @returns the refresh token
|
|
53
|
+
*/
|
|
54
|
+
getRefreshToken(): string;
|
|
49
55
|
}
|
|
50
56
|
export {};
|
|
@@ -17,8 +17,8 @@ import { validateInput } from '../utils/helpers';
|
|
|
17
17
|
import { buildUserAgent } from '../../lib/build-user-agent';
|
|
18
18
|
import { IamRequestBasedTokenManager } from './iam-request-based-token-manager';
|
|
19
19
|
/**
|
|
20
|
-
* The
|
|
21
|
-
* the IAM token service to obtain and store a suitable bearer token. Additionally, the
|
|
20
|
+
* The IamTokenManager takes an api key and performs the necessary interactions with
|
|
21
|
+
* the IAM token service to obtain and store a suitable bearer token. Additionally, the IamTokenManager
|
|
22
22
|
* will retrieve bearer tokens via basic auth using a supplied "clientId" and "clientSecret" pair.
|
|
23
23
|
*/
|
|
24
24
|
export class IamTokenManager extends IamRequestBasedTokenManager {
|
|
@@ -52,4 +52,12 @@ export class IamTokenManager extends IamRequestBasedTokenManager {
|
|
|
52
52
|
this.formData.response_type = 'cloud_iam';
|
|
53
53
|
this.userAgent = buildUserAgent('iam-authenticator');
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the most recently stored refresh token.
|
|
57
|
+
*
|
|
58
|
+
* @returns the refresh token
|
|
59
|
+
*/
|
|
60
|
+
getRefreshToken() {
|
|
61
|
+
return this.refreshToken;
|
|
62
|
+
}
|
|
55
63
|
}
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* @module token-managers
|
|
18
18
|
* The ibm-cloud-sdk-core module supports the following types of token authentication:
|
|
19
|
-
*
|
|
20
|
-
* Identity and Access Management (IAM)
|
|
19
|
+
* Identity and Access Management (IAM, grant type: apikey)
|
|
20
|
+
* Identity and Access Management (IAM, grant type: assume)
|
|
21
21
|
* Cloud Pak for Data
|
|
22
22
|
* Container (IKS, etc)
|
|
23
23
|
* VPC Instance
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*
|
|
29
29
|
* classes:
|
|
30
30
|
* IamTokenManager: Token Manager of IAM via apikey.
|
|
31
|
+
* IamAssumeTokenManager: Token Manager of IAM via apikey and trusted profile.
|
|
31
32
|
* Cp4dTokenManager: Token Manager of CloudPak for data.
|
|
32
33
|
* ContainerTokenManager: Token manager of IAM via compute resource token.
|
|
33
34
|
* VpcInstanceTokenManager: Token manager of VPC Instance Metadata Service API tokens.
|
|
@@ -42,3 +43,4 @@ export { JwtTokenManager, JwtTokenManagerOptions } from './jwt-token-manager';
|
|
|
42
43
|
export { TokenManager, TokenManagerOptions } from './token-manager';
|
|
43
44
|
export { VpcInstanceTokenManager } from './vpc-instance-token-manager';
|
|
44
45
|
export { McspTokenManager } from './mcsp-token-manager';
|
|
46
|
+
export { IamAssumeTokenManager } from './iam-assume-token-manager';
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* @module token-managers
|
|
18
18
|
* The ibm-cloud-sdk-core module supports the following types of token authentication:
|
|
19
|
-
*
|
|
20
|
-
* Identity and Access Management (IAM)
|
|
19
|
+
* Identity and Access Management (IAM, grant type: apikey)
|
|
20
|
+
* Identity and Access Management (IAM, grant type: assume)
|
|
21
21
|
* Cloud Pak for Data
|
|
22
22
|
* Container (IKS, etc)
|
|
23
23
|
* VPC Instance
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*
|
|
29
29
|
* classes:
|
|
30
30
|
* IamTokenManager: Token Manager of IAM via apikey.
|
|
31
|
+
* IamAssumeTokenManager: Token Manager of IAM via apikey and trusted profile.
|
|
31
32
|
* Cp4dTokenManager: Token Manager of CloudPak for data.
|
|
32
33
|
* ContainerTokenManager: Token manager of IAM via compute resource token.
|
|
33
34
|
* VpcInstanceTokenManager: Token manager of VPC Instance Metadata Service API tokens.
|
|
@@ -42,3 +43,4 @@ export { JwtTokenManager } from './jwt-token-manager';
|
|
|
42
43
|
export { TokenManager } from './token-manager';
|
|
43
44
|
export { VpcInstanceTokenManager } from './vpc-instance-token-manager';
|
|
44
45
|
export { McspTokenManager } from './mcsp-token-manager';
|
|
46
|
+
export { IamAssumeTokenManager } from './iam-assume-token-manager';
|
|
@@ -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() {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { Authenticator, BasicAuthenticator, BearerTokenAuthenticator, CloudPakForDataAuthenticator, IamAuthenticator, ContainerAuthenticator, NoAuthAuthenticator, VpcInstanceAuthenticator, McspAuthenticator, } from '../authenticators';
|
|
16
|
+
import { Authenticator, BasicAuthenticator, BearerTokenAuthenticator, CloudPakForDataAuthenticator, IamAuthenticator, IamAssumeAuthenticator, ContainerAuthenticator, NoAuthAuthenticator, VpcInstanceAuthenticator, McspAuthenticator, } from '../authenticators';
|
|
17
17
|
import { readExternalSources } from './read-external-sources';
|
|
18
18
|
/**
|
|
19
19
|
* Look for external configuration of authenticator.
|
|
@@ -78,6 +78,9 @@ export function getAuthenticatorFromEnvironment(serviceName) {
|
|
|
78
78
|
else if (authType === Authenticator.AUTHTYPE_IAM.toLowerCase()) {
|
|
79
79
|
authenticator = new IamAuthenticator(credentials);
|
|
80
80
|
}
|
|
81
|
+
else if (authType === Authenticator.AUTHTYPE_IAM_ASSUME.toLowerCase()) {
|
|
82
|
+
authenticator = new IamAssumeAuthenticator(credentials);
|
|
83
|
+
}
|
|
81
84
|
else if (authType === Authenticator.AUTHTYPE_CONTAINER.toLowerCase()) {
|
|
82
85
|
authenticator = new ContainerAuthenticator(credentials);
|
|
83
86
|
}
|
|
@@ -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.
|
|
@@ -43,17 +43,6 @@ export declare function validateInput(options: any, requiredOptions: string[]):
|
|
|
43
43
|
* @returns the current time in seconds.
|
|
44
44
|
*/
|
|
45
45
|
export declare function getCurrentTime(): number;
|
|
46
|
-
/**
|
|
47
|
-
* Checks for only one of two elements being defined.
|
|
48
|
-
* Returns true if a is defined and b is undefined,
|
|
49
|
-
* or vice versa. Returns false if both are defined
|
|
50
|
-
* or both are undefined.
|
|
51
|
-
*
|
|
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
|
|
55
|
-
*/
|
|
56
|
-
export declare function onlyOne(a: any, b: any): boolean;
|
|
57
46
|
/**
|
|
58
47
|
* Removes a given suffix if it exists.
|
|
59
48
|
*
|
|
@@ -64,20 +53,26 @@ export declare function onlyOne(a: any, b: any): boolean;
|
|
|
64
53
|
*/
|
|
65
54
|
export declare function removeSuffix(str: string, suffix: string): string;
|
|
66
55
|
/**
|
|
67
|
-
* Checks
|
|
56
|
+
* Checks that exactly one of the arguments provided is defined.
|
|
57
|
+
* Returns true if one argument is defined. Returns false if no
|
|
58
|
+
* argument are defined or if 2 or more are defined.
|
|
68
59
|
*
|
|
69
|
-
* @param
|
|
70
|
-
* @
|
|
71
|
-
* @returns true if a or b is defined; false if both are undefined
|
|
60
|
+
* @param args - The spread of arguments to check
|
|
61
|
+
* @returns true if and only if exactly one argument is defined
|
|
72
62
|
*/
|
|
73
|
-
export declare function
|
|
63
|
+
export declare function onlyOne(...args: any): boolean;
|
|
74
64
|
/**
|
|
75
|
-
*
|
|
65
|
+
* Checks for at least one of the given elements being defined.
|
|
76
66
|
*
|
|
77
|
-
* @param
|
|
78
|
-
* @
|
|
67
|
+
* @param args - The spread of arguments to check
|
|
68
|
+
* @returns true if one or more are defined; false if all are undefined
|
|
69
|
+
*/
|
|
70
|
+
export declare function atLeastOne(...args: any): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Verifies that no more than one of the given elements are defined.
|
|
73
|
+
* Returns true if one or none are defined, and false otherwise.
|
|
79
74
|
*
|
|
80
|
-
* @
|
|
81
|
-
|
|
75
|
+
* @param args - The spread of arguments to check
|
|
76
|
+
* @returns false if more than one elements are defined, true otherwise
|
|
82
77
|
*/
|
|
83
|
-
export declare function atMostOne(
|
|
78
|
+
export declare function atMostOne(...args: any): boolean;
|
package/es/auth/utils/helpers.js
CHANGED
|
@@ -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.
|
|
@@ -80,19 +80,6 @@ export function validateInput(options, requiredOptions) {
|
|
|
80
80
|
export function getCurrentTime() {
|
|
81
81
|
return Math.floor(Date.now() / 1000);
|
|
82
82
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Checks for only one of two elements being defined.
|
|
85
|
-
* Returns true if a is defined and b is undefined,
|
|
86
|
-
* or vice versa. Returns false if both are defined
|
|
87
|
-
* or both are undefined.
|
|
88
|
-
*
|
|
89
|
-
* @param a - The first object
|
|
90
|
-
* @param b - The second object
|
|
91
|
-
* @returns true if and only if exactly one of a or b is defined
|
|
92
|
-
*/
|
|
93
|
-
export function onlyOne(a, b) {
|
|
94
|
-
return Boolean((a && !b) || (b && !a));
|
|
95
|
-
}
|
|
96
83
|
/**
|
|
97
84
|
* Removes a given suffix if it exists.
|
|
98
85
|
*
|
|
@@ -108,24 +95,45 @@ export function removeSuffix(str, suffix) {
|
|
|
108
95
|
return str;
|
|
109
96
|
}
|
|
110
97
|
/**
|
|
111
|
-
* Checks
|
|
98
|
+
* Checks that exactly one of the arguments provided is defined.
|
|
99
|
+
* Returns true if one argument is defined. Returns false if no
|
|
100
|
+
* argument are defined or if 2 or more are defined.
|
|
112
101
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @
|
|
115
|
-
* @returns true if a or b is defined; false if both are undefined
|
|
102
|
+
* @param args - The spread of arguments to check
|
|
103
|
+
* @returns true if and only if exactly one argument is defined
|
|
116
104
|
*/
|
|
117
|
-
export function
|
|
118
|
-
return
|
|
105
|
+
export function onlyOne(...args) {
|
|
106
|
+
return countDefinedArgs(args) === 1;
|
|
119
107
|
}
|
|
120
108
|
/**
|
|
121
|
-
*
|
|
109
|
+
* Checks for at least one of the given elements being defined.
|
|
122
110
|
*
|
|
123
|
-
* @param
|
|
124
|
-
* @
|
|
111
|
+
* @param args - The spread of arguments to check
|
|
112
|
+
* @returns true if one or more are defined; false if all are undefined
|
|
113
|
+
*/
|
|
114
|
+
export function atLeastOne(...args) {
|
|
115
|
+
return countDefinedArgs(args) >= 1;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Verifies that no more than one of the given elements are defined.
|
|
119
|
+
* Returns true if one or none are defined, and false otherwise.
|
|
125
120
|
*
|
|
126
|
-
* @
|
|
127
|
-
|
|
121
|
+
* @param args - The spread of arguments to check
|
|
122
|
+
* @returns false if more than one elements are defined, true otherwise
|
|
128
123
|
*/
|
|
129
|
-
export function atMostOne(
|
|
130
|
-
return
|
|
124
|
+
export function atMostOne(...args) {
|
|
125
|
+
return countDefinedArgs(args) <= 1;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Takes a list of anything (intended to be the arguments passed to one of the
|
|
129
|
+
* argument checking functions above) and returns how many elements in that
|
|
130
|
+
* list are not undefined.
|
|
131
|
+
*/
|
|
132
|
+
function countDefinedArgs(args) {
|
|
133
|
+
return args.reduce((total, arg) => {
|
|
134
|
+
if (arg) {
|
|
135
|
+
total += 1;
|
|
136
|
+
}
|
|
137
|
+
return total;
|
|
138
|
+
}, 0);
|
|
131
139
|
}
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2014,
|
|
2
|
+
* (C) Copyright IBM Corp. 2014, 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.
|
|
@@ -33,6 +33,42 @@ export declare class RequestWrapper {
|
|
|
33
33
|
private retryInterceptorId;
|
|
34
34
|
private raxConfig;
|
|
35
35
|
constructor(axiosOptions?: any);
|
|
36
|
+
/**
|
|
37
|
+
* Formats the specified Axios request for debug logging.
|
|
38
|
+
* @param request - the request to be logged
|
|
39
|
+
* @returns the string representation of the request
|
|
40
|
+
*/
|
|
41
|
+
private formatAxiosRequest;
|
|
42
|
+
/**
|
|
43
|
+
* Formats the specified Axios response for debug logging.
|
|
44
|
+
* @param response - the response to be logged
|
|
45
|
+
* @returns the string representation of the response
|
|
46
|
+
*/
|
|
47
|
+
private formatAxiosResponse;
|
|
48
|
+
/**
|
|
49
|
+
* Formats the specified Axios error for debug logging.
|
|
50
|
+
* @param error - the error to be logged
|
|
51
|
+
* @returns the string representation of the error
|
|
52
|
+
*/
|
|
53
|
+
private formatAxiosError;
|
|
54
|
+
/**
|
|
55
|
+
* Formats 'headers' to be included in the debug output
|
|
56
|
+
* like this:
|
|
57
|
+
* Accept: application/json
|
|
58
|
+
* Content-Type: application/json
|
|
59
|
+
* My-Header: my-value
|
|
60
|
+
* ...
|
|
61
|
+
* @param headers - the headers associated with an Axios request or response
|
|
62
|
+
* @returns the formatted output to be included in the HTTP message traces
|
|
63
|
+
*/
|
|
64
|
+
private formatAxiosHeaders;
|
|
65
|
+
/**
|
|
66
|
+
* Formats 'body' (either a string or object/array) to be included in the debug output
|
|
67
|
+
*
|
|
68
|
+
* @param body - a string, object or array that contains the request or response body
|
|
69
|
+
* @returns the formatted output to be included in the HTTP message traces
|
|
70
|
+
*/
|
|
71
|
+
private formatAxiosBody;
|
|
36
72
|
setCompressRequestData(setting: boolean): void;
|
|
37
73
|
/**
|
|
38
74
|
* Creates the request.
|
|
@@ -54,5 +90,11 @@ export declare class RequestWrapper {
|
|
|
54
90
|
private static getRaxConfig;
|
|
55
91
|
enableRetries(retryOptions?: RetryOptions): void;
|
|
56
92
|
disableRetries(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Returns true iff the previously-failed request contained in "error" should be retried.
|
|
95
|
+
* @param error - an AxiosError instance that contains a previously-failed request
|
|
96
|
+
* @returns true iff the request should be retried
|
|
97
|
+
*/
|
|
98
|
+
private static retryPolicy;
|
|
57
99
|
private gzipRequestBody;
|
|
58
100
|
}
|