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,71 @@
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
+ /// <reference types="node" />
17
+ import { OutgoingHttpHeaders } from 'http';
18
+ import { JwtTokenManager } from '../token-managers/jwt-token-manager';
19
+ import { Authenticator } from './authenticator';
20
+ import { AuthenticateOptions } from './authenticator-interface';
21
+ /** Configuration options for token-based authentication. */
22
+ export type BaseOptions = {
23
+ /** Headers to be sent with every outbound HTTP requests to token services. */
24
+ headers?: OutgoingHttpHeaders;
25
+ /**
26
+ * A flag that indicates whether verification of the token server's SSL
27
+ * certificate should be disabled or not.
28
+ */
29
+ disableSslVerification?: boolean;
30
+ /** Endpoint for HTTP token requests. */
31
+ url?: string;
32
+ /** Allow additional request config parameters */
33
+ [propName: string]: any;
34
+ };
35
+ /**
36
+ * Class for common functionality shared by token-request authenticators.
37
+ * Token-request authenticators use token managers to retrieve, store,
38
+ * and refresh tokens. Not intended to be used as stand-alone authenticator,
39
+ * but as base class to authenticators that have their own token manager
40
+ * implementations.
41
+ *
42
+ * The token will be added as an Authorization header in the form:
43
+ *
44
+ * Authorization: Bearer \<bearer-token\>
45
+ */
46
+ export declare class TokenRequestBasedAuthenticatorImmutable extends Authenticator {
47
+ protected tokenManager: JwtTokenManager;
48
+ protected url: string;
49
+ protected headers: OutgoingHttpHeaders;
50
+ protected disableSslVerification: boolean;
51
+ /**
52
+ * Create a new TokenRequestBasedAuthenticatorImmutable instance with an internal JwtTokenManager.
53
+ *
54
+ * @param options - Configuration options.
55
+ * This should be an object containing these fields:
56
+ * - url: (optional) the endpoint URL for the token service
57
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
58
+ * should be disabled or not
59
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
60
+ */
61
+ constructor(options: BaseOptions);
62
+ /**
63
+ * Adds bearer token information to "requestOptions". The bearer token information
64
+ * will be set in the Authorization property of "requestOptions.headers" in the form:
65
+ *
66
+ * Authorization: Bearer \<bearer-token\>
67
+ *
68
+ * @param requestOptions - The request to augment with authentication information.
69
+ */
70
+ authenticate(requestOptions: AuthenticateOptions): Promise<void>;
71
+ }
@@ -0,0 +1,91 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TokenRequestBasedAuthenticatorImmutable = void 0;
37
+ var extend_1 = __importDefault(require("extend"));
38
+ var jwt_token_manager_1 = require("../token-managers/jwt-token-manager");
39
+ var authenticator_1 = require("./authenticator");
40
+ var logger_1 = __importDefault(require("../../lib/logger"));
41
+ /**
42
+ * Class for common functionality shared by token-request authenticators.
43
+ * Token-request authenticators use token managers to retrieve, store,
44
+ * and refresh tokens. Not intended to be used as stand-alone authenticator,
45
+ * but as base class to authenticators that have their own token manager
46
+ * implementations.
47
+ *
48
+ * The token will be added as an Authorization header in the form:
49
+ *
50
+ * Authorization: Bearer \<bearer-token\>
51
+ */
52
+ var TokenRequestBasedAuthenticatorImmutable = /** @class */ (function (_super) {
53
+ __extends(TokenRequestBasedAuthenticatorImmutable, _super);
54
+ /**
55
+ * Create a new TokenRequestBasedAuthenticatorImmutable instance with an internal JwtTokenManager.
56
+ *
57
+ * @param options - Configuration options.
58
+ * This should be an object containing these fields:
59
+ * - url: (optional) the endpoint URL for the token service
60
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
61
+ * should be disabled or not
62
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
63
+ */
64
+ function TokenRequestBasedAuthenticatorImmutable(options) {
65
+ var _this = _super.call(this) || this;
66
+ _this.disableSslVerification = Boolean(options.disableSslVerification);
67
+ _this.url = options.url;
68
+ // default to empty object
69
+ _this.headers = options.headers || {};
70
+ _this.tokenManager = new jwt_token_manager_1.JwtTokenManager(options);
71
+ return _this;
72
+ }
73
+ /**
74
+ * Adds bearer token information to "requestOptions". The bearer token information
75
+ * will be set in the Authorization property of "requestOptions.headers" in the form:
76
+ *
77
+ * Authorization: Bearer \<bearer-token\>
78
+ *
79
+ * @param requestOptions - The request to augment with authentication information.
80
+ */
81
+ TokenRequestBasedAuthenticatorImmutable.prototype.authenticate = function (requestOptions) {
82
+ var _this = this;
83
+ return this.tokenManager.getToken().then(function (token) {
84
+ var authHeader = { Authorization: "Bearer ".concat(token) };
85
+ requestOptions.headers = (0, extend_1.default)(true, {}, requestOptions.headers, authHeader);
86
+ logger_1.default.debug("Authenticated outbound request (type=".concat(_this.authenticationType(), ")"));
87
+ });
88
+ };
89
+ return TokenRequestBasedAuthenticatorImmutable;
90
+ }(authenticator_1.Authenticator));
91
+ exports.TokenRequestBasedAuthenticatorImmutable = TokenRequestBasedAuthenticatorImmutable;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2023.
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.
@@ -15,23 +15,9 @@
15
15
  */
16
16
  /// <reference types="node" />
17
17
  import { OutgoingHttpHeaders } from 'http';
18
- import { JwtTokenManager } from '../token-managers/jwt-token-manager';
19
- import { Authenticator } from './authenticator';
20
- import { AuthenticateOptions } from './authenticator-interface';
18
+ import { TokenRequestBasedAuthenticatorImmutable } from './token-request-based-authenticator-immutable';
21
19
  /** Configuration options for token-based authentication. */
22
- export type BaseOptions = {
23
- /** Headers to be sent with every outbound HTTP requests to token services. */
24
- headers?: OutgoingHttpHeaders;
25
- /**
26
- * A flag that indicates whether verification of the token server's SSL
27
- * certificate should be disabled or not.
28
- */
29
- disableSslVerification?: boolean;
30
- /** Endpoint for HTTP token requests. */
31
- url?: string;
32
- /** Allow additional request config parameters */
33
- [propName: string]: any;
34
- };
20
+ export { BaseOptions } from './token-request-based-authenticator-immutable';
35
21
  /**
36
22
  * Class for common functionality shared by token-request authenticators.
37
23
  * TokenRequestBasedAuthenticators use token managers to retrieve, store,
@@ -43,22 +29,7 @@ export type BaseOptions = {
43
29
  *
44
30
  * Authorization: Bearer \<bearer-token\>
45
31
  */
46
- export declare class TokenRequestBasedAuthenticator extends Authenticator {
47
- protected tokenManager: JwtTokenManager;
48
- protected url: string;
49
- protected headers: OutgoingHttpHeaders;
50
- protected disableSslVerification: boolean;
51
- /**
52
- * Create a new TokenRequestBasedAuthenticator instance with an internal JwtTokenManager.
53
- *
54
- * @param options - Configuration options.
55
- * This should be an object containing these fields:
56
- * - url: (optional) the endpoint URL for the token service
57
- * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
58
- * should be disabled or not
59
- * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
60
- */
61
- constructor(options: BaseOptions);
32
+ export declare class TokenRequestBasedAuthenticator extends TokenRequestBasedAuthenticatorImmutable {
62
33
  /**
63
34
  * Set the flag that indicates whether verification of the server's SSL
64
35
  * certificate should be disabled or not.
@@ -74,13 +45,4 @@ export declare class TokenRequestBasedAuthenticator extends Authenticator {
74
45
  * Overwrites previous default headers.
75
46
  */
76
47
  setHeaders(headers: OutgoingHttpHeaders): void;
77
- /**
78
- * Adds bearer token information to "requestOptions". The bearer token information
79
- * will be set in the Authorization property of "requestOptions.headers" in the form:
80
- *
81
- * Authorization: Bearer \<bearer-token\>
82
- *
83
- * @param requestOptions - The request to augment with authentication information.
84
- */
85
- authenticate(requestOptions: AuthenticateOptions): Promise<void>;
86
48
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * (C) Copyright IBM Corp. 2019, 2023.
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.
@@ -29,14 +29,9 @@ var __extends = (this && this.__extends) || (function () {
29
29
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
30
30
  };
31
31
  })();
32
- var __importDefault = (this && this.__importDefault) || function (mod) {
33
- return (mod && mod.__esModule) ? mod : { "default": mod };
34
- };
35
32
  Object.defineProperty(exports, "__esModule", { value: true });
36
33
  exports.TokenRequestBasedAuthenticator = void 0;
37
- var extend_1 = __importDefault(require("extend"));
38
- var jwt_token_manager_1 = require("../token-managers/jwt-token-manager");
39
- var authenticator_1 = require("./authenticator");
34
+ var token_request_based_authenticator_immutable_1 = require("./token-request-based-authenticator-immutable");
40
35
  /**
41
36
  * Class for common functionality shared by token-request authenticators.
42
37
  * TokenRequestBasedAuthenticators use token managers to retrieve, store,
@@ -50,24 +45,8 @@ var authenticator_1 = require("./authenticator");
50
45
  */
51
46
  var TokenRequestBasedAuthenticator = /** @class */ (function (_super) {
52
47
  __extends(TokenRequestBasedAuthenticator, _super);
53
- /**
54
- * Create a new TokenRequestBasedAuthenticator instance with an internal JwtTokenManager.
55
- *
56
- * @param options - Configuration options.
57
- * This should be an object containing these fields:
58
- * - url: (optional) the endpoint URL for the token service
59
- * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
60
- * should be disabled or not
61
- * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
62
- */
63
- function TokenRequestBasedAuthenticator(options) {
64
- var _this = _super.call(this) || this;
65
- _this.disableSslVerification = Boolean(options.disableSslVerification);
66
- _this.url = options.url;
67
- // default to empty object
68
- _this.headers = options.headers || {};
69
- _this.tokenManager = new jwt_token_manager_1.JwtTokenManager(options);
70
- return _this;
48
+ function TokenRequestBasedAuthenticator() {
49
+ return _super !== null && _super.apply(this, arguments) || this;
71
50
  }
72
51
  /**
73
52
  * Set the flag that indicates whether verification of the server's SSL
@@ -96,20 +75,6 @@ var TokenRequestBasedAuthenticator = /** @class */ (function (_super) {
96
75
  this.headers = headers;
97
76
  this.tokenManager.setHeaders(this.headers);
98
77
  };
99
- /**
100
- * Adds bearer token information to "requestOptions". The bearer token information
101
- * will be set in the Authorization property of "requestOptions.headers" in the form:
102
- *
103
- * Authorization: Bearer \<bearer-token\>
104
- *
105
- * @param requestOptions - The request to augment with authentication information.
106
- */
107
- TokenRequestBasedAuthenticator.prototype.authenticate = function (requestOptions) {
108
- return this.tokenManager.getToken().then(function (token) {
109
- var authHeader = { Authorization: "Bearer ".concat(token) };
110
- requestOptions.headers = (0, extend_1.default)(true, {}, requestOptions.headers, authHeader);
111
- });
112
- };
113
78
  return TokenRequestBasedAuthenticator;
114
- }(authenticator_1.Authenticator));
79
+ }(token_request_based_authenticator_immutable_1.TokenRequestBasedAuthenticatorImmutable));
115
80
  exports.TokenRequestBasedAuthenticator = TokenRequestBasedAuthenticator;
@@ -65,6 +65,12 @@ export declare class ContainerTokenManager extends IamRequestBasedTokenManager {
65
65
  * @param iamProfileId - the ID of the IAM trusted profile
66
66
  */
67
67
  setIamProfileId(iamProfileId: string): void;
68
+ /**
69
+ * Returns the most recently stored refresh token.
70
+ *
71
+ * @returns the refresh token
72
+ */
73
+ getRefreshToken(): string;
68
74
  /**
69
75
  * Request an IAM token using a compute resource token.
70
76
  */
@@ -29,42 +29,6 @@ var __extends = (this && this.__extends) || (function () {
29
29
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
30
30
  };
31
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
32
  Object.defineProperty(exports, "__esModule", { value: true });
69
33
  exports.ContainerTokenManager = void 0;
70
34
  var helpers_1 = require("../utils/helpers");
@@ -143,24 +107,28 @@ var ContainerTokenManager = /** @class */ (function (_super) {
143
107
  ContainerTokenManager.prototype.setIamProfileId = function (iamProfileId) {
144
108
  this.iamProfileId = iamProfileId;
145
109
  };
110
+ /**
111
+ * Returns the most recently stored refresh token.
112
+ *
113
+ * @returns the refresh token
114
+ */
115
+ ContainerTokenManager.prototype.getRefreshToken = function () {
116
+ return this.refreshToken;
117
+ };
146
118
  /**
147
119
  * Request an IAM token using a compute resource token.
148
120
  */
149
121
  ContainerTokenManager.prototype.requestToken = function () {
150
- return __awaiter(this, void 0, void 0, function () {
151
- return __generator(this, function (_a) {
152
- this.formData.cr_token = this.getCrToken();
153
- // these member variables can be reset, set them in the form data right
154
- // before making the request to ensure they're up to date
155
- if (this.iamProfileName) {
156
- this.formData.profile_name = this.iamProfileName;
157
- }
158
- if (this.iamProfileId) {
159
- this.formData.profile_id = this.iamProfileId;
160
- }
161
- return [2 /*return*/, _super.prototype.requestToken.call(this)];
162
- });
163
- });
122
+ this.formData.cr_token = this.getCrToken();
123
+ // these member variables can be reset, set them in the form data right
124
+ // before making the request to ensure they're up to date
125
+ if (this.iamProfileName) {
126
+ this.formData.profile_name = this.iamProfileName;
127
+ }
128
+ if (this.iamProfileId) {
129
+ this.formData.profile_id = this.iamProfileId;
130
+ }
131
+ return _super.prototype.requestToken.call(this);
164
132
  };
165
133
  /**
166
134
  * Retrieves the CR token from a file using this search order:
@@ -38,6 +38,7 @@ var extend_1 = __importDefault(require("extend"));
38
38
  var helpers_1 = require("../utils/helpers");
39
39
  var build_user_agent_1 = require("../../lib/build-user-agent");
40
40
  var jwt_token_manager_1 = require("./jwt-token-manager");
41
+ var logger_1 = __importDefault(require("../../lib/logger"));
41
42
  /**
42
43
  * Token Manager of CloudPak for data.
43
44
  *
@@ -99,7 +100,11 @@ var Cp4dTokenManager = /** @class */ (function (_super) {
99
100
  rejectUnauthorized: !this.disableSslVerification,
100
101
  },
101
102
  };
102
- return this.requestWrapperInstance.sendRequest(parameters);
103
+ logger_1.default.debug("Invoking CP4D token service operation: ".concat(parameters.options.url));
104
+ return this.requestWrapperInstance.sendRequest(parameters).then(function (response) {
105
+ logger_1.default.debug('Returned from CP4D token service operation');
106
+ return response;
107
+ });
103
108
  };
104
109
  return Cp4dTokenManager;
105
110
  }(jwt_token_manager_1.JwtTokenManager));
@@ -0,0 +1,101 @@
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
+ /// <reference types="node" />
17
+ import { OutgoingHttpHeaders } from 'http';
18
+ import { IamRequestBasedTokenManager, IamRequestOptions } from './iam-request-based-token-manager';
19
+ /** Configuration options for IAM Assume token retrieval. */
20
+ interface Options extends IamRequestOptions {
21
+ apikey: string;
22
+ iamProfileId?: string;
23
+ iamProfileCrn?: string;
24
+ iamProfileName?: string;
25
+ iamAccountId?: string;
26
+ }
27
+ /**
28
+ * The IamAssumeTokenManager takes an api key, along with trusted profile information, and performs
29
+ * the necessary interactions with the IAM token service to obtain and store a suitable bearer token
30
+ * that "assumes" the identify of the trusted profile.
31
+ */
32
+ export declare class IamAssumeTokenManager extends IamRequestBasedTokenManager {
33
+ protected requiredOptions: string[];
34
+ private iamProfileId;
35
+ private iamProfileCrn;
36
+ private iamProfileName;
37
+ private iamAccountId;
38
+ private iamDelegate;
39
+ /**
40
+ *
41
+ * Create a new IamAssumeTokenManager instance.
42
+ *
43
+ * @param options - Configuration options.
44
+ * This should be an object containing these fields:
45
+ * - apikey: (required) the IAM api key
46
+ * - iamProfileId: (optional) the ID of the trusted profile to use
47
+ * - iamProfileCrn: (optional) the CRN of the trusted profile to use
48
+ * - iamProfileName: (optional) the name of the trusted profile to use (must be specified with iamAccountId)
49
+ * - iamAccountId: (optional) the ID of the account the trusted profile is in (must be specified with iamProfileName)
50
+ * - url: (optional) the endpoint URL for the IAM token service (default value: "https://iam.cloud.ibm.com")
51
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
52
+ * should be disabled or not
53
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
54
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
55
+ * Authorization header to be included in each request to the token service
56
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
57
+ * Authorization header to be included in each request to the token service
58
+ * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service
59
+ *
60
+ * @throws Error: the configuration options are not valid.
61
+ */
62
+ constructor(options: Options);
63
+ /**
64
+ * Request an IAM token using a standard access token and a trusted profile.
65
+ */
66
+ protected requestToken(): Promise<any>;
67
+ /**
68
+ * Extend this method from the parent class to erase the refresh token from
69
+ * the class - we do not want to expose it for IAM Assume authentication.
70
+ *
71
+ * @param tokenResponse - the response object from JWT service request
72
+ */
73
+ protected saveTokenInfo(tokenResponse: any): void;
74
+ /**
75
+ * Sets the IAM "scope" value.
76
+ * This value is sent as the "scope" form parameter in the IAM delegate request.
77
+ *
78
+ * @param scope - a space-separated string that contains one or more scope names
79
+ */
80
+ setScope(scope: string): void;
81
+ /**
82
+ * Sets the IAM "clientId" and "clientSecret" values for the IAM delegate.
83
+ *
84
+ * @param clientId - the client id.
85
+ * @param clientSecret - the client secret.
86
+ */
87
+ setClientIdAndSecret(clientId: string, clientSecret: string): void;
88
+ /**
89
+ * Sets the "disableSslVerification" property for the IAM delegate.
90
+ *
91
+ * @param value - the new value for the disableSslVerification property
92
+ */
93
+ setDisableSslVerification(value: boolean): void;
94
+ /**
95
+ * Sets the headers to be included in the IAM delegate's requests.
96
+ *
97
+ * @param headers - the set of headers to send with each request to the token server
98
+ */
99
+ setHeaders(headers: OutgoingHttpHeaders): void;
100
+ }
101
+ export {};