ibm-cloud-sdk-core 4.0.6 → 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,10 @@
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
+
1
8
  ## [4.0.6](https://github.com/IBM/node-sdk-core/compare/v4.0.5...v4.0.6) (2023-05-18)
2
9
 
3
10
 
@@ -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
  }
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "4.0.6",
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",
@@ -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;