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.
Files changed (98) hide show
  1. package/.secrets.baseline +128 -24
  2. package/Authentication.md +146 -21
  3. package/CHANGELOG.md +14 -0
  4. package/README.md +3 -2
  5. package/auth/authenticators/authenticator.d.ts +1 -0
  6. package/auth/authenticators/authenticator.js +1 -0
  7. package/auth/authenticators/basic-authenticator.d.ts +1 -1
  8. package/auth/authenticators/basic-authenticator.js +3 -1
  9. package/auth/authenticators/bearer-token-authenticator.js +2 -0
  10. package/auth/authenticators/container-authenticator.d.ts +6 -0
  11. package/auth/authenticators/container-authenticator.js +8 -0
  12. package/auth/authenticators/iam-assume-authenticator.d.ts +82 -0
  13. package/auth/authenticators/iam-assume-authenticator.js +92 -0
  14. package/auth/authenticators/iam-authenticator.d.ts +6 -0
  15. package/auth/authenticators/iam-authenticator.js +8 -0
  16. package/auth/authenticators/iam-request-based-authenticator-immutable.d.ts +64 -0
  17. package/auth/authenticators/iam-request-based-authenticator-immutable.js +74 -0
  18. package/auth/authenticators/iam-request-based-authenticator.d.ts +19 -47
  19. package/auth/authenticators/iam-request-based-authenticator.js +28 -36
  20. package/auth/authenticators/index.d.ts +4 -1
  21. package/auth/authenticators/index.js +3 -1
  22. package/auth/authenticators/token-request-based-authenticator-immutable.d.ts +71 -0
  23. package/auth/authenticators/token-request-based-authenticator-immutable.js +91 -0
  24. package/auth/authenticators/token-request-based-authenticator.d.ts +4 -42
  25. package/auth/authenticators/token-request-based-authenticator.js +5 -40
  26. package/auth/token-managers/container-token-manager.d.ts +6 -0
  27. package/auth/token-managers/container-token-manager.js +18 -50
  28. package/auth/token-managers/cp4d-token-manager.js +6 -1
  29. package/auth/token-managers/iam-assume-token-manager.d.ts +101 -0
  30. package/auth/token-managers/iam-assume-token-manager.js +220 -0
  31. package/auth/token-managers/iam-request-based-token-manager.d.ts +3 -9
  32. package/auth/token-managers/iam-request-based-token-manager.js +5 -9
  33. package/auth/token-managers/iam-token-manager.d.ts +8 -2
  34. package/auth/token-managers/iam-token-manager.js +10 -2
  35. package/auth/token-managers/index.d.ts +4 -2
  36. package/auth/token-managers/index.js +6 -3
  37. package/auth/token-managers/mcsp-token-manager.js +6 -1
  38. package/auth/token-managers/token-manager.js +7 -3
  39. package/auth/token-managers/vpc-instance-token-manager.js +4 -1
  40. package/auth/utils/get-authenticator-from-environment.js +3 -0
  41. package/auth/utils/helpers.d.ts +18 -23
  42. package/auth/utils/helpers.js +50 -30
  43. package/auth/utils/read-external-sources.js +2 -0
  44. package/docs/ibm-cloud-sdk-core.api.json +787 -404
  45. package/es/auth/authenticators/authenticator.d.ts +1 -0
  46. package/es/auth/authenticators/authenticator.js +1 -0
  47. package/es/auth/authenticators/basic-authenticator.d.ts +1 -1
  48. package/es/auth/authenticators/basic-authenticator.js +3 -1
  49. package/es/auth/authenticators/bearer-token-authenticator.js +2 -0
  50. package/es/auth/authenticators/container-authenticator.d.ts +6 -0
  51. package/es/auth/authenticators/container-authenticator.js +8 -0
  52. package/es/auth/authenticators/iam-assume-authenticator.d.ts +82 -0
  53. package/es/auth/authenticators/iam-assume-authenticator.js +70 -0
  54. package/es/auth/authenticators/iam-authenticator.d.ts +6 -0
  55. package/es/auth/authenticators/iam-authenticator.js +8 -0
  56. package/es/auth/authenticators/iam-request-based-authenticator-immutable.d.ts +64 -0
  57. package/es/auth/authenticators/iam-request-based-authenticator-immutable.js +51 -0
  58. package/es/auth/authenticators/iam-request-based-authenticator.d.ts +19 -47
  59. package/es/auth/authenticators/iam-request-based-authenticator.js +26 -35
  60. package/es/auth/authenticators/index.d.ts +4 -1
  61. package/es/auth/authenticators/index.js +1 -0
  62. package/es/auth/authenticators/token-request-based-authenticator-immutable.d.ts +71 -0
  63. package/es/auth/authenticators/token-request-based-authenticator-immutable.js +65 -0
  64. package/es/auth/authenticators/token-request-based-authenticator.d.ts +4 -42
  65. package/es/auth/authenticators/token-request-based-authenticator.js +3 -37
  66. package/es/auth/token-managers/container-token-manager.d.ts +6 -0
  67. package/es/auth/token-managers/container-token-manager.js +18 -24
  68. package/es/auth/token-managers/cp4d-token-manager.js +6 -1
  69. package/es/auth/token-managers/iam-assume-token-manager.d.ts +101 -0
  70. package/es/auth/token-managers/iam-assume-token-manager.js +164 -0
  71. package/es/auth/token-managers/iam-request-based-token-manager.d.ts +3 -9
  72. package/es/auth/token-managers/iam-request-based-token-manager.js +5 -9
  73. package/es/auth/token-managers/iam-token-manager.d.ts +8 -2
  74. package/es/auth/token-managers/iam-token-manager.js +10 -2
  75. package/es/auth/token-managers/index.d.ts +4 -2
  76. package/es/auth/token-managers/index.js +4 -2
  77. package/es/auth/token-managers/mcsp-token-manager.js +6 -1
  78. package/es/auth/token-managers/token-manager.js +7 -3
  79. package/es/auth/token-managers/vpc-instance-token-manager.js +4 -1
  80. package/es/auth/utils/get-authenticator-from-environment.js +4 -1
  81. package/es/auth/utils/helpers.d.ts +18 -23
  82. package/es/auth/utils/helpers.js +35 -27
  83. package/es/auth/utils/read-external-sources.js +2 -0
  84. package/es/lib/base-service.js +2 -0
  85. package/es/lib/private-helpers.d.ts +22 -0
  86. package/es/lib/private-helpers.js +58 -0
  87. package/es/lib/request-wrapper.d.ts +43 -1
  88. package/es/lib/request-wrapper.js +113 -14
  89. package/etc/ibm-cloud-sdk-core.api.md +46 -28
  90. package/ibm-cloud-sdk-core.d.ts +306 -68
  91. package/lib/base-service.js +2 -0
  92. package/lib/private-helpers.d.ts +22 -0
  93. package/lib/private-helpers.js +62 -0
  94. package/lib/request-wrapper.d.ts +43 -1
  95. package/lib/request-wrapper.js +113 -14
  96. package/package.json +5 -4
  97. package/sdk-test-utilities/package-lock.json +8 -5
  98. package/sdk-test-utilities/package.json +3 -0
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ /**
3
+ * (C) Copyright IBM Corp. 2024.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __extends = (this && this.__extends) || (function () {
18
+ var extendStatics = function (d, b) {
19
+ extendStatics = Object.setPrototypeOf ||
20
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
21
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
22
+ return extendStatics(d, b);
23
+ };
24
+ return function (d, b) {
25
+ if (typeof b !== "function" && b !== null)
26
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
27
+ extendStatics(d, b);
28
+ function __() { this.constructor = d; }
29
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
30
+ };
31
+ })();
32
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
41
+ var __generator = (this && this.__generator) || function (thisArg, body) {
42
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
+ function verb(n) { return function (v) { return step([n, v]); }; }
45
+ function step(op) {
46
+ if (f) throw new TypeError("Generator is already executing.");
47
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
48
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
49
+ if (y = 0, t) op = [op[0] & 2, t.value];
50
+ switch (op[0]) {
51
+ case 0: case 1: t = op; break;
52
+ case 4: _.label++; return { value: op[1], done: false };
53
+ case 5: _.label++; y = op[1]; op = [0]; continue;
54
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
+ default:
56
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
+ if (t[2]) _.ops.pop();
61
+ _.trys.pop(); continue;
62
+ }
63
+ op = body.call(thisArg, _);
64
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
+ }
67
+ };
68
+ Object.defineProperty(exports, "__esModule", { value: true });
69
+ exports.IamAssumeTokenManager = void 0;
70
+ var helpers_1 = require("../utils/helpers");
71
+ var build_user_agent_1 = require("../../lib/build-user-agent");
72
+ var iam_request_based_token_manager_1 = require("./iam-request-based-token-manager");
73
+ var iam_token_manager_1 = require("./iam-token-manager");
74
+ /**
75
+ * The IamAssumeTokenManager takes an api key, along with trusted profile information, and performs
76
+ * the necessary interactions with the IAM token service to obtain and store a suitable bearer token
77
+ * that "assumes" the identify of the trusted profile.
78
+ */
79
+ var IamAssumeTokenManager = /** @class */ (function (_super) {
80
+ __extends(IamAssumeTokenManager, _super);
81
+ /**
82
+ *
83
+ * Create a new IamAssumeTokenManager instance.
84
+ *
85
+ * @param options - Configuration options.
86
+ * This should be an object containing these fields:
87
+ * - apikey: (required) the IAM api key
88
+ * - iamProfileId: (optional) the ID of the trusted profile to use
89
+ * - iamProfileCrn: (optional) the CRN of the trusted profile to use
90
+ * - iamProfileName: (optional) the name of the trusted profile to use (must be specified with iamAccountId)
91
+ * - iamAccountId: (optional) the ID of the account the trusted profile is in (must be specified with iamProfileName)
92
+ * - url: (optional) the endpoint URL for the IAM token service (default value: "https://iam.cloud.ibm.com")
93
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
94
+ * should be disabled or not
95
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
96
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
97
+ * Authorization header to be included in each request to the token service
98
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
99
+ * Authorization header to be included in each request to the token service
100
+ * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service
101
+ *
102
+ * @throws Error: the configuration options are not valid.
103
+ */
104
+ function IamAssumeTokenManager(options) {
105
+ var _this = _super.call(this, options) || this;
106
+ _this.requiredOptions = ['apikey'];
107
+ // This just verifies that the API key is provided and is free of common issues.
108
+ (0, helpers_1.validateInput)(options, _this.requiredOptions);
109
+ // This validates the assume-specific fields.
110
+ // Only one of the following three options may be specified.
111
+ if (!(0, helpers_1.onlyOne)(options.iamProfileId, options.iamProfileCrn, options.iamProfileName)) {
112
+ throw new Error('Exactly one of `iamProfileName`, `iamProfileCrn`, or `iamProfileId` must be specified.');
113
+ }
114
+ // `iamAccountId` may only be specified if `iamProfileName` is also specified.
115
+ if (Boolean(options.iamProfileName) !== Boolean(options.iamAccountId)) {
116
+ throw new Error('`iamProfileName` and `iamAccountId` must be provided together, or not at all.');
117
+ }
118
+ // Set class variables from options. If they are 'undefined' in options,
119
+ // they won't be changed, as they are 'undefined' to begin with.
120
+ _this.iamProfileId = options.iamProfileId;
121
+ _this.iamProfileCrn = options.iamProfileCrn;
122
+ _this.iamProfileName = options.iamProfileName;
123
+ _this.iamAccountId = options.iamAccountId;
124
+ _this.iamDelegate = options.iamDelegate;
125
+ // Create an instance of the IamTokenManager, which will be used to obtain
126
+ // an IAM access token for use in the "assume" token exchange. Most option
127
+ // names are shared between these token manager, and extraneous options will
128
+ // be ignored, so we can pass the options structure to that constructor as-is.
129
+ _this.iamDelegate = new iam_token_manager_1.IamTokenManager(options);
130
+ // These options are used by the delegate token manager
131
+ // but they are not supported by this token manager.
132
+ _this.clientId = undefined;
133
+ _this.clientSecret = undefined;
134
+ _this.scope = undefined;
135
+ // Set the grant type and user agent for this flavor of authentication.
136
+ _this.formData.grant_type = 'urn:ibm:params:oauth:grant-type:assume';
137
+ _this.userAgent = (0, build_user_agent_1.buildUserAgent)('iam-assume-authenticator');
138
+ return _this;
139
+ }
140
+ /**
141
+ * Request an IAM token using a standard access token and a trusted profile.
142
+ */
143
+ IamAssumeTokenManager.prototype.requestToken = function () {
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ var _a;
146
+ return __generator(this, function (_b) {
147
+ switch (_b.label) {
148
+ case 0:
149
+ // First, retrieve a standard IAM access token from the delegate and set it in the form data.
150
+ _a = this.formData;
151
+ return [4 /*yield*/, this.iamDelegate.getToken()];
152
+ case 1:
153
+ // First, retrieve a standard IAM access token from the delegate and set it in the form data.
154
+ _a.access_token = _b.sent();
155
+ if (this.iamProfileCrn) {
156
+ this.formData.profile_crn = this.iamProfileCrn;
157
+ }
158
+ else if (this.iamProfileId) {
159
+ this.formData.profile_id = this.iamProfileId;
160
+ }
161
+ else {
162
+ this.formData.profile_name = this.iamProfileName;
163
+ this.formData.account = this.iamAccountId;
164
+ }
165
+ return [2 /*return*/, _super.prototype.requestToken.call(this)];
166
+ }
167
+ });
168
+ });
169
+ };
170
+ /**
171
+ * Extend this method from the parent class to erase the refresh token from
172
+ * the class - we do not want to expose it for IAM Assume authentication.
173
+ *
174
+ * @param tokenResponse - the response object from JWT service request
175
+ */
176
+ IamAssumeTokenManager.prototype.saveTokenInfo = function (tokenResponse) {
177
+ _super.prototype.saveTokenInfo.call(this, tokenResponse);
178
+ this.refreshToken = undefined;
179
+ };
180
+ // Override the inherited "setters". This token manager does not store these options
181
+ // but they can adjust properties on the stored IAM delegate.
182
+ /**
183
+ * Sets the IAM "scope" value.
184
+ * This value is sent as the "scope" form parameter in the IAM delegate request.
185
+ *
186
+ * @param scope - a space-separated string that contains one or more scope names
187
+ */
188
+ IamAssumeTokenManager.prototype.setScope = function (scope) {
189
+ this.iamDelegate.setScope(scope);
190
+ };
191
+ /**
192
+ * Sets the IAM "clientId" and "clientSecret" values for the IAM delegate.
193
+ *
194
+ * @param clientId - the client id.
195
+ * @param clientSecret - the client secret.
196
+ */
197
+ IamAssumeTokenManager.prototype.setClientIdAndSecret = function (clientId, clientSecret) {
198
+ this.iamDelegate.setClientIdAndSecret(clientId, clientSecret);
199
+ };
200
+ /**
201
+ * Sets the "disableSslVerification" property for the IAM delegate.
202
+ *
203
+ * @param value - the new value for the disableSslVerification property
204
+ */
205
+ IamAssumeTokenManager.prototype.setDisableSslVerification = function (value) {
206
+ _super.prototype.setDisableSslVerification.call(this, value);
207
+ this.iamDelegate.setDisableSslVerification(value);
208
+ };
209
+ /**
210
+ * Sets the headers to be included in the IAM delegate's requests.
211
+ *
212
+ * @param headers - the set of headers to send with each request to the token server
213
+ */
214
+ IamAssumeTokenManager.prototype.setHeaders = function (headers) {
215
+ _super.prototype.setHeaders.call(this, headers);
216
+ this.iamDelegate.setHeaders(headers);
217
+ };
218
+ return IamAssumeTokenManager;
219
+ }(iam_request_based_token_manager_1.IamRequestBasedTokenManager));
220
+ exports.IamAssumeTokenManager = IamAssumeTokenManager;
@@ -28,9 +28,9 @@ export interface IamRequestOptions extends JwtTokenManagerOptions {
28
28
  * class be extended with specific implementations.
29
29
  */
30
30
  export declare class IamRequestBasedTokenManager extends JwtTokenManager {
31
- private clientId;
32
- private clientSecret;
33
- private scope;
31
+ protected clientId: string;
32
+ protected clientSecret: string;
33
+ protected scope: string;
34
34
  protected refreshToken: string;
35
35
  protected formData: any;
36
36
  /**
@@ -70,12 +70,6 @@ export declare class IamRequestBasedTokenManager extends JwtTokenManager {
70
70
  * @param clientSecret - the client secret.
71
71
  */
72
72
  setClientIdAndSecret(clientId: string, clientSecret: string): void;
73
- /**
74
- * Returns the most recently stored refresh token.
75
- *
76
- * @returns the refresh token
77
- */
78
- getRefreshToken(): string;
79
73
  /**
80
74
  * Extend this method from the parent class to extract the refresh token from
81
75
  * the request and save it.
@@ -120,14 +120,6 @@ var IamRequestBasedTokenManager = /** @class */ (function (_super) {
120
120
  logger_1.default.warn(CLIENT_ID_SECRET_WARNING);
121
121
  }
122
122
  };
123
- /**
124
- * Returns the most recently stored refresh token.
125
- *
126
- * @returns the refresh token
127
- */
128
- IamRequestBasedTokenManager.prototype.getRefreshToken = function () {
129
- return this.refreshToken;
130
- };
131
123
  /**
132
124
  * Extend this method from the parent class to extract the refresh token from
133
125
  * the request and save it.
@@ -168,7 +160,11 @@ var IamRequestBasedTokenManager = /** @class */ (function (_super) {
168
160
  rejectUnauthorized: !this.disableSslVerification,
169
161
  },
170
162
  };
171
- return this.requestWrapperInstance.sendRequest(parameters);
163
+ logger_1.default.debug("Invoking IAM get_token operation: ".concat(parameters.options.url));
164
+ return this.requestWrapperInstance.sendRequest(parameters).then(function (response) {
165
+ logger_1.default.debug('Returned from IAM get_token operation');
166
+ return response;
167
+ });
172
168
  };
173
169
  /**
174
170
  * 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 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
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 {};
@@ -35,8 +35,8 @@ var helpers_1 = require("../utils/helpers");
35
35
  var build_user_agent_1 = require("../../lib/build-user-agent");
36
36
  var iam_request_based_token_manager_1 = require("./iam-request-based-token-manager");
37
37
  /**
38
- * The IAMTokenManager takes an api key and performs the necessary interactions with
39
- * the IAM token service to obtain and store a suitable bearer token. Additionally, the IAMTokenManager
38
+ * The IamTokenManager takes an api key and performs the necessary interactions with
39
+ * the IAM token service to obtain and store a suitable bearer token. Additionally, the IamTokenManager
40
40
  * will retrieve bearer tokens via basic auth using a supplied "clientId" and "clientSecret" pair.
41
41
  */
42
42
  var IamTokenManager = /** @class */ (function (_super) {
@@ -72,6 +72,14 @@ var IamTokenManager = /** @class */ (function (_super) {
72
72
  _this.userAgent = (0, build_user_agent_1.buildUserAgent)('iam-authenticator');
73
73
  return _this;
74
74
  }
75
+ /**
76
+ * Returns the most recently stored refresh token.
77
+ *
78
+ * @returns the refresh token
79
+ */
80
+ IamTokenManager.prototype.getRefreshToken = function () {
81
+ return this.refreshToken;
82
+ };
75
83
  return IamTokenManager;
76
84
  }(iam_request_based_token_manager_1.IamRequestBasedTokenManager));
77
85
  exports.IamTokenManager = IamTokenManager;
@@ -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';
@@ -15,12 +15,12 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.McspTokenManager = exports.VpcInstanceTokenManager = exports.TokenManager = exports.JwtTokenManager = exports.IamRequestBasedTokenManager = exports.ContainerTokenManager = exports.Cp4dTokenManager = exports.IamTokenManager = void 0;
18
+ exports.IamAssumeTokenManager = exports.McspTokenManager = exports.VpcInstanceTokenManager = exports.TokenManager = exports.JwtTokenManager = exports.IamRequestBasedTokenManager = exports.ContainerTokenManager = exports.Cp4dTokenManager = exports.IamTokenManager = void 0;
19
19
  /**
20
20
  * @module token-managers
21
21
  * The ibm-cloud-sdk-core module supports the following types of token authentication:
22
- *
23
- * Identity and Access Management (IAM)
22
+ * Identity and Access Management (IAM, grant type: apikey)
23
+ * Identity and Access Management (IAM, grant type: assume)
24
24
  * Cloud Pak for Data
25
25
  * Container (IKS, etc)
26
26
  * VPC Instance
@@ -31,6 +31,7 @@ exports.McspTokenManager = exports.VpcInstanceTokenManager = exports.TokenManage
31
31
  *
32
32
  * classes:
33
33
  * IamTokenManager: Token Manager of IAM via apikey.
34
+ * IamAssumeTokenManager: Token Manager of IAM via apikey and trusted profile.
34
35
  * Cp4dTokenManager: Token Manager of CloudPak for data.
35
36
  * ContainerTokenManager: Token manager of IAM via compute resource token.
36
37
  * VpcInstanceTokenManager: Token manager of VPC Instance Metadata Service API tokens.
@@ -53,3 +54,5 @@ var vpc_instance_token_manager_1 = require("./vpc-instance-token-manager");
53
54
  Object.defineProperty(exports, "VpcInstanceTokenManager", { enumerable: true, get: function () { return vpc_instance_token_manager_1.VpcInstanceTokenManager; } });
54
55
  var mcsp_token_manager_1 = require("./mcsp-token-manager");
55
56
  Object.defineProperty(exports, "McspTokenManager", { enumerable: true, get: function () { return mcsp_token_manager_1.McspTokenManager; } });
57
+ var iam_assume_token_manager_1 = require("./iam-assume-token-manager");
58
+ Object.defineProperty(exports, "IamAssumeTokenManager", { enumerable: true, get: function () { return iam_assume_token_manager_1.IamAssumeTokenManager; } });
@@ -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
- return this.requestWrapperInstance.sendRequest(parameters);
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. request a new token
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
- // 2. use valid, managed token
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
  });
@@ -81,6 +81,9 @@ function getAuthenticatorFromEnvironment(serviceName) {
81
81
  else if (authType === authenticators_1.Authenticator.AUTHTYPE_IAM.toLowerCase()) {
82
82
  authenticator = new authenticators_1.IamAuthenticator(credentials);
83
83
  }
84
+ else if (authType === authenticators_1.Authenticator.AUTHTYPE_IAM_ASSUME.toLowerCase()) {
85
+ authenticator = new authenticators_1.IamAssumeAuthenticator(credentials);
86
+ }
84
87
  else if (authType === authenticators_1.Authenticator.AUTHTYPE_CONTAINER.toLowerCase()) {
85
88
  authenticator = new authenticators_1.ContainerAuthenticator(credentials);
86
89
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2022.
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 for at least one of two elements being defined.
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 a - the first object
70
- * @param b - the second object
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 atLeastOne(a: any, b: any): boolean;
63
+ export declare function onlyOne(...args: any): boolean;
74
64
  /**
75
- * Verifies that both properties are not specified.
65
+ * Checks for at least one of the given elements being defined.
76
66
  *
77
- * @param a - The first object
78
- * @param b - The second object
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
- * @returns false if a and b are both defined, true otherwise
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(a: any, b: any): boolean;
78
+ export declare function atMostOne(...args: any): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * (C) Copyright IBM Corp. 2019, 2022.
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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.atMostOne = exports.atLeastOne = exports.removeSuffix = exports.onlyOne = exports.getCurrentTime = exports.validateInput = exports.checkCredentials = exports.computeBasicAuthHeader = void 0;
18
+ exports.atMostOne = exports.atLeastOne = exports.onlyOne = exports.removeSuffix = exports.getCurrentTime = exports.validateInput = exports.checkCredentials = exports.computeBasicAuthHeader = void 0;
19
19
  var helper_1 = require("../../lib/helper");
20
20
  /**
21
21
  * Compute and return a Basic Authorization header from a username and password.
@@ -87,20 +87,6 @@ function getCurrentTime() {
87
87
  return Math.floor(Date.now() / 1000);
88
88
  }
89
89
  exports.getCurrentTime = getCurrentTime;
90
- /**
91
- * Checks for only one of two elements being defined.
92
- * Returns true if a is defined and b is undefined,
93
- * or vice versa. Returns false if both are defined
94
- * or both are undefined.
95
- *
96
- * @param a - The first object
97
- * @param b - The second object
98
- * @returns true if and only if exactly one of a or b is defined
99
- */
100
- function onlyOne(a, b) {
101
- return Boolean((a && !b) || (b && !a));
102
- }
103
- exports.onlyOne = onlyOne;
104
90
  /**
105
91
  * Removes a given suffix if it exists.
106
92
  *
@@ -117,26 +103,60 @@ function removeSuffix(str, suffix) {
117
103
  }
118
104
  exports.removeSuffix = removeSuffix;
119
105
  /**
120
- * Checks for at least one of two elements being defined.
106
+ * Checks that exactly one of the arguments provided is defined.
107
+ * Returns true if one argument is defined. Returns false if no
108
+ * argument are defined or if 2 or more are defined.
121
109
  *
122
- * @param a - the first object
123
- * @param b - the second object
124
- * @returns true if a or b is defined; false if both are undefined
110
+ * @param args - The spread of arguments to check
111
+ * @returns true if and only if exactly one argument is defined
125
112
  */
126
- function atLeastOne(a, b) {
127
- return Boolean(a || b);
113
+ function onlyOne() {
114
+ var args = [];
115
+ for (var _i = 0; _i < arguments.length; _i++) {
116
+ args[_i] = arguments[_i];
117
+ }
118
+ return countDefinedArgs(args) === 1;
128
119
  }
129
- exports.atLeastOne = atLeastOne;
120
+ exports.onlyOne = onlyOne;
130
121
  /**
131
- * Verifies that both properties are not specified.
122
+ * Checks for at least one of the given elements being defined.
132
123
  *
133
- * @param a - The first object
134
- * @param b - The second object
124
+ * @param args - The spread of arguments to check
125
+ * @returns true if one or more are defined; false if all are undefined
126
+ */
127
+ function atLeastOne() {
128
+ var args = [];
129
+ for (var _i = 0; _i < arguments.length; _i++) {
130
+ args[_i] = arguments[_i];
131
+ }
132
+ return countDefinedArgs(args) >= 1;
133
+ }
134
+ exports.atLeastOne = atLeastOne;
135
+ /**
136
+ * Verifies that no more than one of the given elements are defined.
137
+ * Returns true if one or none are defined, and false otherwise.
135
138
  *
136
- * @returns false if a and b are both defined, true otherwise
137
-
139
+ * @param args - The spread of arguments to check
140
+ * @returns false if more than one elements are defined, true otherwise
138
141
  */
139
- function atMostOne(a, b) {
140
- return Boolean(!(a && b));
142
+ function atMostOne() {
143
+ var args = [];
144
+ for (var _i = 0; _i < arguments.length; _i++) {
145
+ args[_i] = arguments[_i];
146
+ }
147
+ return countDefinedArgs(args) <= 1;
141
148
  }
142
149
  exports.atMostOne = atMostOne;
150
+ /**
151
+ * Takes a list of anything (intended to be the arguments passed to one of the
152
+ * argument checking functions above) and returns how many elements in that
153
+ * list are not undefined.
154
+ */
155
+ function countDefinedArgs(args) {
156
+ return args.reduce(function (total, arg) {
157
+ if (arg) {
158
+ total += 1;
159
+ }
160
+ return total;
161
+ }, 0);
162
+ }
@@ -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
  /**