ibm-cloud-sdk-core 4.0.5 → 4.0.7

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/Authentication.md CHANGED
@@ -252,7 +252,8 @@ The IAM access token is added to each outbound request in the `Authorization` he
252
252
  ### Properties
253
253
 
254
254
  - crTokenFilename: (optional) the name of the file containing the injected CR token value.
255
- If not specified, then `/var/run/secrets/tokens/vault-token` is used as the default value.
255
+ If not specified, then the authenticator will first try `/var/run/secrets/tokens/vault-token`
256
+ and then `/var/run/secrets/tokens/sa-token` as the default value (first file found is used).
256
257
  The application must have `read` permissions on the file containing the CR token value.
257
258
 
258
259
  - iamProfileName: (optional) the name of the linked trusted IAM profile to be used when obtaining the
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [4.0.7](https://github.com/IBM/node-sdk-core/compare/v4.0.6...v4.0.7) (2023-05-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **ContainerAuthenticator:** add sa-token as default CR token filename ([#241](https://github.com/IBM/node-sdk-core/issues/241)) ([91f9932](https://github.com/IBM/node-sdk-core/commit/91f9932ab0a74c11e1de5aecb46481dee3058018))
7
+
8
+ ## [4.0.6](https://github.com/IBM/node-sdk-core/compare/v4.0.5...v4.0.6) (2023-05-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * use consistent message for JSON.parse() errors ([#243](https://github.com/IBM/node-sdk-core/issues/243)) ([3cc7bab](https://github.com/IBM/node-sdk-core/commit/3cc7babac6a14b1744d64cf3ab93063b2ce63643))
14
+
1
15
  ## [4.0.5](https://github.com/IBM/node-sdk-core/compare/v4.0.4...v4.0.5) (2023-03-01)
2
16
 
3
17
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021, 2022 IBM Corp. All Rights Reserved.
2
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
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.
@@ -69,5 +69,15 @@ export declare class ContainerTokenManager extends IamRequestBasedTokenManager {
69
69
  * Request an IAM token using a compute resource token.
70
70
  */
71
71
  protected requestToken(): Promise<any>;
72
+ /**
73
+ * Retrieves the CR token from a file using this search order:
74
+ * 1. User-specified filename (if specified)
75
+ * 2. Default file #1 (/var/run/secrets/tokens/vault-token)
76
+ * 3. Default file #2 (/var/run/secrets/tokens/sa-token)
77
+ * First one found wins.
78
+ *
79
+ * @returns the CR token value as a string
80
+ */
81
+ protected getCrToken(): string;
72
82
  }
73
83
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Copyright 2021, 2022 IBM Corp. All Rights Reserved.
3
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
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.
@@ -65,15 +65,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
65
65
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
66
  }
67
67
  };
68
- var __importDefault = (this && this.__importDefault) || function (mod) {
69
- return (mod && mod.__esModule) ? mod : { "default": mod };
70
- };
71
68
  Object.defineProperty(exports, "__esModule", { value: true });
72
69
  exports.ContainerTokenManager = void 0;
73
- var logger_1 = __importDefault(require("../../lib/logger"));
74
70
  var utils_1 = require("../utils");
75
71
  var iam_request_based_token_manager_1 = require("./iam-request-based-token-manager");
76
- var DEFAULT_CR_TOKEN_FILEPATH = '/var/run/secrets/tokens/vault-token';
72
+ var DEFAULT_CR_TOKEN_FILEPATH1 = '/var/run/secrets/tokens/vault-token';
73
+ var DEFAULT_CR_TOKEN_FILEPATH2 = '/var/run/secrets/tokens/sa-token';
77
74
  /**
78
75
  * The ContainerTokenManager retrieves a compute resource token from a file on the container. This token
79
76
  * is used to perform the necessary interactions with the IAM token service to obtain and store a suitable
@@ -109,7 +106,9 @@ var ContainerTokenManager = /** @class */ (function (_super) {
109
106
  if (!(0, utils_1.atLeastOne)(options.iamProfileId, options.iamProfileName)) {
110
107
  throw new Error('At least one of `iamProfileName` or `iamProfileId` must be specified.');
111
108
  }
112
- _this.crTokenFilename = options.crTokenFilename || DEFAULT_CR_TOKEN_FILEPATH;
109
+ if (options.crTokenFilename) {
110
+ _this.crTokenFilename = options.crTokenFilename;
111
+ }
113
112
  if (options.iamProfileName) {
114
113
  _this.iamProfileName = options.iamProfileName;
115
114
  }
@@ -146,10 +145,8 @@ var ContainerTokenManager = /** @class */ (function (_super) {
146
145
  */
147
146
  ContainerTokenManager.prototype.requestToken = function () {
148
147
  return __awaiter(this, void 0, void 0, function () {
149
- var crToken;
150
148
  return __generator(this, function (_a) {
151
- crToken = getCrToken(this.crTokenFilename);
152
- this.formData.cr_token = crToken;
149
+ this.formData.cr_token = this.getCrToken();
153
150
  // these member variables can be reset, set them in the form data right
154
151
  // before making the request to ensure they're up to date
155
152
  if (this.iamProfileName) {
@@ -162,11 +159,37 @@ var ContainerTokenManager = /** @class */ (function (_super) {
162
159
  });
163
160
  });
164
161
  };
162
+ /**
163
+ * Retrieves the CR token from a file using this search order:
164
+ * 1. User-specified filename (if specified)
165
+ * 2. Default file #1 (/var/run/secrets/tokens/vault-token)
166
+ * 3. Default file #2 (/var/run/secrets/tokens/sa-token)
167
+ * First one found wins.
168
+ *
169
+ * @returns the CR token value as a string
170
+ */
171
+ ContainerTokenManager.prototype.getCrToken = function () {
172
+ try {
173
+ var crToken = null;
174
+ if (this.crTokenFilename) {
175
+ // If the user specified a filename, then try to read from that.
176
+ crToken = (0, utils_1.readCrTokenFile)(this.crTokenFilename);
177
+ }
178
+ else {
179
+ // If no filename was specified, then try our two default filenames.
180
+ try {
181
+ crToken = (0, utils_1.readCrTokenFile)(DEFAULT_CR_TOKEN_FILEPATH1);
182
+ }
183
+ catch (err) {
184
+ crToken = (0, utils_1.readCrTokenFile)(DEFAULT_CR_TOKEN_FILEPATH2);
185
+ }
186
+ }
187
+ return crToken;
188
+ }
189
+ catch (err) {
190
+ throw new Error("Error reading CR token file: ".concat(err.toString()));
191
+ }
192
+ };
165
193
  return ContainerTokenManager;
166
194
  }(iam_request_based_token_manager_1.IamRequestBasedTokenManager));
167
195
  exports.ContainerTokenManager = ContainerTokenManager;
168
- function getCrToken(filename) {
169
- logger_1.default.debug("Attempting to read CR token from file: ".concat(filename));
170
- // moving the actual read to another file to isolate usage of node-only packages like `fs`
171
- return (0, utils_1.readCrTokenFile)(filename);
172
- }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 IBM Corp. All Rights Reserved.
2
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Copyright 2021 IBM Corp. All Rights Reserved.
3
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
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.
@@ -88,21 +88,17 @@ function readCrTokenFile(filepath) {
88
88
  if (!fs_1.existsSync) {
89
89
  return '';
90
90
  }
91
- var token = '';
92
- var fileExists = fileExistsAtPath(filepath);
93
- if (fileExists) {
91
+ try {
92
+ var token = '';
93
+ logger_1.default.debug("Attempting to read CR token from file: ".concat(filepath));
94
94
  token = (0, fs_1.readFileSync)(filepath, 'utf8');
95
95
  logger_1.default.debug("Successfully read CR token from file: ".concat(filepath));
96
+ return token;
96
97
  }
97
- if (token === '') {
98
- if (fileExists) {
99
- logger_1.default.error("Expected to read CR token from file but the file is empty: ".concat(filepath));
100
- }
101
- else {
102
- logger_1.default.error("Expected to find CR token file but the file does not exist: ".concat(filepath));
103
- }
104
- throw new Error("Unable to retrieve the CR token value from file: ".concat(filepath));
98
+ catch (err) {
99
+ var msg = "Error reading CR token: ".concat(err.toString());
100
+ logger_1.default.debug(msg);
101
+ throw new Error(msg);
105
102
  }
106
- return token;
107
103
  }
108
104
  exports.readCrTokenFile = readCrTokenFile;
@@ -0,0 +1,19 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [ContainerTokenManager](./ibm-cloud-sdk-core.containertokenmanager.md) &gt; [getCrToken](./ibm-cloud-sdk-core.containertokenmanager.getcrtoken.md)
4
+
5
+ ## ContainerTokenManager.getCrToken() method
6
+
7
+ Retrieves the CR token from a file using this search order: 1. User-specified filename (if specified) 2. Default file \#1 (/var/run/secrets/tokens/vault-token) 3. Default file \#2 (/var/run/secrets/tokens/sa-token) First one found wins.
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ protected getCrToken(): string;
13
+ ```
14
+ <b>Returns:</b>
15
+
16
+ string
17
+
18
+ the CR token value as a string
19
+
@@ -23,6 +23,7 @@ export declare class ContainerTokenManager extends IamRequestBasedTokenManager
23
23
 
24
24
  | Method | Modifiers | Description |
25
25
  | --- | --- | --- |
26
+ | [getCrToken()](./ibm-cloud-sdk-core.containertokenmanager.getcrtoken.md) | <code>protected</code> | Retrieves the CR token from a file using this search order: 1. User-specified filename (if specified) 2. Default file \#1 (/var/run/secrets/tokens/vault-token) 3. Default file \#2 (/var/run/secrets/tokens/sa-token) First one found wins. |
26
27
  | [requestToken()](./ibm-cloud-sdk-core.containertokenmanager.requesttoken.md) | <code>protected</code> | Request an IAM token using a compute resource token. |
27
28
  | [setCrTokenFilename(crTokenFilename)](./ibm-cloud-sdk-core.containertokenmanager.setcrtokenfilename.md) | | Sets the "crTokenFilename" field |
28
29
  | [setIamProfileId(iamProfileId)](./ibm-cloud-sdk-core.containertokenmanager.setiamprofileid.md) | | Sets the ID of the IAM trusted profile to use when obtaining an access token from the IAM token server. |
@@ -2498,6 +2498,36 @@
2498
2498
  }
2499
2499
  ]
2500
2500
  },
2501
+ {
2502
+ "kind": "Method",
2503
+ "canonicalReference": "ibm-cloud-sdk-core!ContainerTokenManager#getCrToken:member(1)",
2504
+ "docComment": "/**\n * Retrieves the CR token from a file using this search order: 1. User-specified filename (if specified) 2. Default file #1 (/var/run/secrets/tokens/vault-token) 3. Default file #2 (/var/run/secrets/tokens/sa-token) First one found wins.\n *\n * @returns the CR token value as a string\n */\n",
2505
+ "excerptTokens": [
2506
+ {
2507
+ "kind": "Content",
2508
+ "text": "protected getCrToken(): "
2509
+ },
2510
+ {
2511
+ "kind": "Content",
2512
+ "text": "string"
2513
+ },
2514
+ {
2515
+ "kind": "Content",
2516
+ "text": ";"
2517
+ }
2518
+ ],
2519
+ "isStatic": false,
2520
+ "returnTypeTokenRange": {
2521
+ "startIndex": 1,
2522
+ "endIndex": 2
2523
+ },
2524
+ "releaseTag": "Public",
2525
+ "isProtected": true,
2526
+ "overloadIndex": 1,
2527
+ "parameters": [],
2528
+ "isOptional": false,
2529
+ "name": "getCrToken"
2530
+ },
2501
2531
  {
2502
2532
  "kind": "Method",
2503
2533
  "canonicalReference": "ibm-cloud-sdk-core!ContainerTokenManager#requestToken:member(1)",
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021, 2022 IBM Corp. All Rights Reserved.
2
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
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.
@@ -69,5 +69,15 @@ export declare class ContainerTokenManager extends IamRequestBasedTokenManager {
69
69
  * Request an IAM token using a compute resource token.
70
70
  */
71
71
  protected requestToken(): Promise<any>;
72
+ /**
73
+ * Retrieves the CR token from a file using this search order:
74
+ * 1. User-specified filename (if specified)
75
+ * 2. Default file #1 (/var/run/secrets/tokens/vault-token)
76
+ * 3. Default file #2 (/var/run/secrets/tokens/sa-token)
77
+ * First one found wins.
78
+ *
79
+ * @returns the CR token value as a string
80
+ */
81
+ protected getCrToken(): string;
72
82
  }
73
83
  export {};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021, 2022 IBM Corp. All Rights Reserved.
2
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -22,10 +22,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- import logger from '../../lib/logger';
26
25
  import { atLeastOne, readCrTokenFile } from '../utils';
27
26
  import { IamRequestBasedTokenManager } from './iam-request-based-token-manager';
28
- const DEFAULT_CR_TOKEN_FILEPATH = '/var/run/secrets/tokens/vault-token';
27
+ const DEFAULT_CR_TOKEN_FILEPATH1 = '/var/run/secrets/tokens/vault-token';
28
+ const DEFAULT_CR_TOKEN_FILEPATH2 = '/var/run/secrets/tokens/sa-token';
29
29
  /**
30
30
  * The ContainerTokenManager retrieves a compute resource token from a file on the container. This token
31
31
  * is used to perform the necessary interactions with the IAM token service to obtain and store a suitable
@@ -59,7 +59,9 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
59
59
  if (!atLeastOne(options.iamProfileId, options.iamProfileName)) {
60
60
  throw new Error('At least one of `iamProfileName` or `iamProfileId` must be specified.');
61
61
  }
62
- this.crTokenFilename = options.crTokenFilename || DEFAULT_CR_TOKEN_FILEPATH;
62
+ if (options.crTokenFilename) {
63
+ this.crTokenFilename = options.crTokenFilename;
64
+ }
63
65
  if (options.iamProfileName) {
64
66
  this.iamProfileName = options.iamProfileName;
65
67
  }
@@ -98,8 +100,7 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
98
100
  requestToken: { get: () => super.requestToken }
99
101
  });
100
102
  return __awaiter(this, void 0, void 0, function* () {
101
- const crToken = getCrToken(this.crTokenFilename);
102
- this.formData.cr_token = crToken;
103
+ this.formData.cr_token = this.getCrToken();
103
104
  // these member variables can be reset, set them in the form data right
104
105
  // before making the request to ensure they're up to date
105
106
  if (this.iamProfileName) {
@@ -111,9 +112,35 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
111
112
  return _super.requestToken.call(this);
112
113
  });
113
114
  }
114
- }
115
- function getCrToken(filename) {
116
- logger.debug(`Attempting to read CR token from file: ${filename}`);
117
- // moving the actual read to another file to isolate usage of node-only packages like `fs`
118
- return readCrTokenFile(filename);
115
+ /**
116
+ * Retrieves the CR token from a file using this search order:
117
+ * 1. User-specified filename (if specified)
118
+ * 2. Default file #1 (/var/run/secrets/tokens/vault-token)
119
+ * 3. Default file #2 (/var/run/secrets/tokens/sa-token)
120
+ * First one found wins.
121
+ *
122
+ * @returns the CR token value as a string
123
+ */
124
+ getCrToken() {
125
+ try {
126
+ let crToken = null;
127
+ if (this.crTokenFilename) {
128
+ // If the user specified a filename, then try to read from that.
129
+ crToken = readCrTokenFile(this.crTokenFilename);
130
+ }
131
+ else {
132
+ // If no filename was specified, then try our two default filenames.
133
+ try {
134
+ crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH1);
135
+ }
136
+ catch (err) {
137
+ crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH2);
138
+ }
139
+ }
140
+ return crToken;
141
+ }
142
+ catch (err) {
143
+ throw new Error(`Error reading CR token file: ${err.toString()}`);
144
+ }
145
+ }
119
146
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 IBM Corp. All Rights Reserved.
2
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2021 IBM Corp. All Rights Reserved.
2
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
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.
@@ -79,20 +79,16 @@ export function readCrTokenFile(filepath) {
79
79
  if (!existsSync) {
80
80
  return '';
81
81
  }
82
- let token = '';
83
- const fileExists = fileExistsAtPath(filepath);
84
- if (fileExists) {
82
+ try {
83
+ let token = '';
84
+ logger.debug(`Attempting to read CR token from file: ${filepath}`);
85
85
  token = readFileSync(filepath, 'utf8');
86
86
  logger.debug(`Successfully read CR token from file: ${filepath}`);
87
+ return token;
87
88
  }
88
- if (token === '') {
89
- if (fileExists) {
90
- logger.error(`Expected to read CR token from file but the file is empty: ${filepath}`);
91
- }
92
- else {
93
- logger.error(`Expected to find CR token file but the file does not exist: ${filepath}`);
94
- }
95
- throw new Error(`Unable to retrieve the CR token value from file: ${filepath}`);
89
+ catch (err) {
90
+ const msg = `Error reading CR token: ${err.toString()}`;
91
+ logger.debug(msg);
92
+ throw new Error(msg);
96
93
  }
97
- return token;
98
94
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2023.
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
+ * Given two Error instances 'error' and 'causedBy', this function will
18
+ * update 'error' by chaining 'causedBy' to it.
19
+ * Specifically, 'causedBy''s message and stack will be appended
20
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
21
+ *
22
+ * @param error the Error object to be updated
23
+ * @param causedBy an Error object that represents the cause of 'error'
24
+ * @returns 'error' after updating its message and stack fields
25
+ */
26
+ export declare function chainError(error: Error, causedBy: Error): Error;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2023.
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
+ * Given two Error instances 'error' and 'causedBy', this function will
18
+ * update 'error' by chaining 'causedBy' to it.
19
+ * Specifically, 'causedBy''s message and stack will be appended
20
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
21
+ *
22
+ * @param error the Error object to be updated
23
+ * @param causedBy an Error object that represents the cause of 'error'
24
+ * @returns 'error' after updating its message and stack fields
25
+ */
26
+ export function chainError(error, causedBy) {
27
+ error.message += ` ${causedBy.toString()}`;
28
+ if (causedBy.stack) {
29
+ error.stack += `\nCaused by: ${causedBy.stack}`;
30
+ }
31
+ return error;
32
+ }
@@ -13,11 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
16
+ import { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
17
17
  import { CookieJar } from 'tough-cookie';
18
18
  export declare class CookieInterceptor {
19
19
  private readonly cookieJar;
20
20
  constructor(cookieJar: CookieJar | boolean);
21
- requestInterceptor(config: AxiosRequestConfig): Promise<AxiosRequestConfig<any>>;
21
+ requestInterceptor(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
22
22
  responseInterceptor(response: AxiosResponse): Promise<AxiosResponse<any, any>>;
23
23
  }
@@ -35,6 +35,7 @@ import { buildRequestFileObject, isEmptyObject, isFileData, isFileWithMetadata,
35
35
  import logger from './logger';
36
36
  import { streamToPromise } from './stream-to-promise';
37
37
  import { CookieInterceptor } from './cookie-support';
38
+ import { chainError } from './chain-error';
38
39
  export class RequestWrapper {
39
40
  constructor(axiosOptions) {
40
41
  axiosOptions = axiosOptions || {};
@@ -479,9 +480,9 @@ function ensureJSONResponseBodyIsObject(response) {
479
480
  dataAsObject = JSON.parse(response.data);
480
481
  }
481
482
  catch (e) {
482
- logger.error('Response body was supposed to have JSON content but JSON parsing failed.');
483
- logger.error(`Malformed JSON string: ${response.data}`);
484
- throw e;
483
+ logger.verbose('Response body was supposed to have JSON content but JSON parsing failed.');
484
+ logger.verbose(`Malformed JSON string: ${response.data}`);
485
+ throw chainError(new Error('Error processing HTTP response:'), e);
485
486
  }
486
487
  return dataAsObject;
487
488
  }
@@ -149,6 +149,7 @@ export class ContainerAuthenticator extends IamRequestBasedAuthenticator {
149
149
  export class ContainerTokenManager extends IamRequestBasedTokenManager {
150
150
  // Warning: (ae-forgotten-export) The symbol "Options_7" needs to be exported by the entry point index.d.ts
151
151
  constructor(options: Options_7);
152
+ protected getCrToken(): string;
152
153
  protected requestToken(): Promise<any>;
153
154
  setCrTokenFilename(crTokenFilename: string): void;
154
155
  setIamProfileId(iamProfileId: string): void;
@@ -567,6 +567,16 @@ export declare class ContainerTokenManager extends IamRequestBasedTokenManager {
567
567
  * Request an IAM token using a compute resource token.
568
568
  */
569
569
  protected requestToken(): Promise<any>;
570
+ /**
571
+ * Retrieves the CR token from a file using this search order:
572
+ * 1. User-specified filename (if specified)
573
+ * 2. Default file #1 (/var/run/secrets/tokens/vault-token)
574
+ * 3. Default file #2 (/var/run/secrets/tokens/sa-token)
575
+ * First one found wins.
576
+ *
577
+ * @returns the CR token value as a string
578
+ */
579
+ protected getCrToken(): string;
570
580
  }
571
581
 
572
582
  export declare const contentType: {
@@ -1138,7 +1148,7 @@ export declare const qs: {
1138
1148
  };
1139
1149
 
1140
1150
  /**
1141
- * Copyright 2021 IBM Corp. All Rights Reserved.
1151
+ * Copyright 2021, 2023 IBM Corp. All Rights Reserved.
1142
1152
  *
1143
1153
  * Licensed under the Apache License, Version 2.0 (the "License");
1144
1154
  * you may not use this file except in compliance with the License.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2023.
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
+ * Given two Error instances 'error' and 'causedBy', this function will
18
+ * update 'error' by chaining 'causedBy' to it.
19
+ * Specifically, 'causedBy''s message and stack will be appended
20
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
21
+ *
22
+ * @param error the Error object to be updated
23
+ * @param causedBy an Error object that represents the cause of 'error'
24
+ * @returns 'error' after updating its message and stack fields
25
+ */
26
+ export declare function chainError(error: Error, causedBy: Error): Error;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * (C) Copyright IBM Corp. 2023.
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.chainError = void 0;
19
+ /**
20
+ * Given two Error instances 'error' and 'causedBy', this function will
21
+ * update 'error' by chaining 'causedBy' to it.
22
+ * Specifically, 'causedBy''s message and stack will be appended
23
+ * to 'error''s message and stack, respectively, to simulate chained Errors.
24
+ *
25
+ * @param error the Error object to be updated
26
+ * @param causedBy an Error object that represents the cause of 'error'
27
+ * @returns 'error' after updating its message and stack fields
28
+ */
29
+ function chainError(error, causedBy) {
30
+ error.message += " ".concat(causedBy.toString());
31
+ if (causedBy.stack) {
32
+ error.stack += "\nCaused by: ".concat(causedBy.stack);
33
+ }
34
+ return error;
35
+ }
36
+ exports.chainError = chainError;
@@ -13,11 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
16
+ import { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
17
17
  import { CookieJar } from 'tough-cookie';
18
18
  export declare class CookieInterceptor {
19
19
  private readonly cookieJar;
20
20
  constructor(cookieJar: CookieJar | boolean);
21
- requestInterceptor(config: AxiosRequestConfig): Promise<AxiosRequestConfig<any>>;
21
+ requestInterceptor(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
22
22
  responseInterceptor(response: AxiosResponse): Promise<AxiosResponse<any, any>>;
23
23
  }
@@ -102,6 +102,7 @@ var helper_1 = require("./helper");
102
102
  var logger_1 = __importDefault(require("./logger"));
103
103
  var stream_to_promise_1 = require("./stream-to-promise");
104
104
  var cookie_support_1 = require("./cookie-support");
105
+ var chain_error_1 = require("./chain-error");
105
106
  var RequestWrapper = /** @class */ (function () {
106
107
  function RequestWrapper(axiosOptions) {
107
108
  var _this = this;
@@ -582,9 +583,9 @@ function ensureJSONResponseBodyIsObject(response) {
582
583
  dataAsObject = JSON.parse(response.data);
583
584
  }
584
585
  catch (e) {
585
- logger_1.default.error('Response body was supposed to have JSON content but JSON parsing failed.');
586
- logger_1.default.error("Malformed JSON string: ".concat(response.data));
587
- throw e;
586
+ logger_1.default.verbose('Response body was supposed to have JSON content but JSON parsing failed.');
587
+ logger_1.default.verbose("Malformed JSON string: ".concat(response.data));
588
+ throw (0, chain_error_1.chainError)(new Error('Error processing HTTP response:'), e);
588
589
  }
589
590
  return dataAsObject;
590
591
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
5
5
  "main": "index.js",
6
6
  "typings": "./es/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "@types/isstream": "^0.1.0",
43
43
  "@types/node": "~10.14.19",
44
44
  "@types/tough-cookie": "^4.0.0",
45
- "axios": "1.2.1",
45
+ "axios": "1.4.0",
46
46
  "camelcase": "^5.3.1",
47
47
  "debug": "^4.1.1",
48
48
  "dotenv": "^6.2.0",
@@ -2498,6 +2498,36 @@
2498
2498
  }
2499
2499
  ]
2500
2500
  },
2501
+ {
2502
+ "kind": "Method",
2503
+ "canonicalReference": "ibm-cloud-sdk-core!ContainerTokenManager#getCrToken:member(1)",
2504
+ "docComment": "/**\n * Retrieves the CR token from a file using this search order: 1. User-specified filename (if specified) 2. Default file #1 (/var/run/secrets/tokens/vault-token) 3. Default file #2 (/var/run/secrets/tokens/sa-token) First one found wins.\n *\n * @returns the CR token value as a string\n */\n",
2505
+ "excerptTokens": [
2506
+ {
2507
+ "kind": "Content",
2508
+ "text": "protected getCrToken(): "
2509
+ },
2510
+ {
2511
+ "kind": "Content",
2512
+ "text": "string"
2513
+ },
2514
+ {
2515
+ "kind": "Content",
2516
+ "text": ";"
2517
+ }
2518
+ ],
2519
+ "isStatic": false,
2520
+ "returnTypeTokenRange": {
2521
+ "startIndex": 1,
2522
+ "endIndex": 2
2523
+ },
2524
+ "releaseTag": "Public",
2525
+ "isProtected": true,
2526
+ "overloadIndex": 1,
2527
+ "parameters": [],
2528
+ "isOptional": false,
2529
+ "name": "getCrToken"
2530
+ },
2501
2531
  {
2502
2532
  "kind": "Method",
2503
2533
  "canonicalReference": "ibm-cloud-sdk-core!ContainerTokenManager#requestToken:member(1)",
@@ -149,6 +149,7 @@ export class ContainerAuthenticator extends IamRequestBasedAuthenticator {
149
149
  export class ContainerTokenManager extends IamRequestBasedTokenManager {
150
150
  // Warning: (ae-forgotten-export) The symbol "Options_7" needs to be exported by the entry point index.d.ts
151
151
  constructor(options: Options_7);
152
+ protected getCrToken(): string;
152
153
  protected requestToken(): Promise<any>;
153
154
  setCrTokenFilename(crTokenFilename: string): void;
154
155
  setIamProfileId(iamProfileId: string): void;