Socket
Socket
Sign inDemoInstall

ibm-cloud-sdk-core

Package Overview
Dependencies
Maintainers
3
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ibm-cloud-sdk-core - npm Package Compare versions

Comparing version 4.0.6 to 4.0.7

build/docs/ibm-cloud-sdk-core.containertokenmanager.getcrtoken.md

12

auth/token-managers/container-token-manager.d.ts
/**
* Copyright 2021, 2022 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -72,3 +72,13 @@ * Licensed under the Apache License, Version 2.0 (the "License");

protected requestToken(): Promise<any>;
/**
* 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.
*
* @returns the CR token value as a string
*/
protected getCrToken(): string;
}
export {};

53

auth/token-managers/container-token-manager.js
"use strict";
/**
* Copyright 2021, 2022 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -68,11 +68,8 @@ * Licensed under the Apache License, Version 2.0 (the "License");

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContainerTokenManager = void 0;
var logger_1 = __importDefault(require("../../lib/logger"));
var utils_1 = require("../utils");
var iam_request_based_token_manager_1 = require("./iam-request-based-token-manager");
var DEFAULT_CR_TOKEN_FILEPATH = '/var/run/secrets/tokens/vault-token';
var DEFAULT_CR_TOKEN_FILEPATH1 = '/var/run/secrets/tokens/vault-token';
var DEFAULT_CR_TOKEN_FILEPATH2 = '/var/run/secrets/tokens/sa-token';
/**

@@ -113,3 +110,5 @@ * The ContainerTokenManager retrieves a compute resource token from a file on the container. This token

}
_this.crTokenFilename = options.crTokenFilename || DEFAULT_CR_TOKEN_FILEPATH;
if (options.crTokenFilename) {
_this.crTokenFilename = options.crTokenFilename;
}
if (options.iamProfileName) {

@@ -151,6 +150,4 @@ _this.iamProfileName = options.iamProfileName;

return __awaiter(this, void 0, void 0, function () {
var crToken;
return __generator(this, function (_a) {
crToken = getCrToken(this.crTokenFilename);
this.formData.cr_token = crToken;
this.formData.cr_token = this.getCrToken();
// these member variables can be reset, set them in the form data right

@@ -168,9 +165,35 @@ // before making the request to ensure they're up to date

};
/**
* 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.
*
* @returns the CR token value as a string
*/
ContainerTokenManager.prototype.getCrToken = function () {
try {
var crToken = null;
if (this.crTokenFilename) {
// If the user specified a filename, then try to read from that.
crToken = (0, utils_1.readCrTokenFile)(this.crTokenFilename);
}
else {
// If no filename was specified, then try our two default filenames.
try {
crToken = (0, utils_1.readCrTokenFile)(DEFAULT_CR_TOKEN_FILEPATH1);
}
catch (err) {
crToken = (0, utils_1.readCrTokenFile)(DEFAULT_CR_TOKEN_FILEPATH2);
}
}
return crToken;
}
catch (err) {
throw new Error("Error reading CR token file: ".concat(err.toString()));
}
};
return ContainerTokenManager;
}(iam_request_based_token_manager_1.IamRequestBasedTokenManager));
exports.ContainerTokenManager = ContainerTokenManager;
function getCrToken(filename) {
logger_1.default.debug("Attempting to read CR token from file: ".concat(filename));
// moving the actual read to another file to isolate usage of node-only packages like `fs`
return (0, utils_1.readCrTokenFile)(filename);
}
/**
* Copyright 2021 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License");

"use strict";
/**
* Copyright 2021 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -91,19 +91,15 @@ * Licensed under the Apache License, Version 2.0 (the "License");

}
var token = '';
var fileExists = fileExistsAtPath(filepath);
if (fileExists) {
try {
var token = '';
logger_1.default.debug("Attempting to read CR token from file: ".concat(filepath));
token = (0, fs_1.readFileSync)(filepath, 'utf8');
logger_1.default.debug("Successfully read CR token from file: ".concat(filepath));
return token;
}
if (token === '') {
if (fileExists) {
logger_1.default.error("Expected to read CR token from file but the file is empty: ".concat(filepath));
}
else {
logger_1.default.error("Expected to find CR token file but the file does not exist: ".concat(filepath));
}
throw new Error("Unable to retrieve the CR token value from file: ".concat(filepath));
catch (err) {
var msg = "Error reading CR token: ".concat(err.toString());
logger_1.default.debug(msg);
throw new Error(msg);
}
return token;
}
exports.readCrTokenFile = readCrTokenFile;

@@ -255,3 +255,4 @@ # Authentication

- crTokenFilename: (optional) the name of the file containing the injected CR token value.
If not specified, then `/var/run/secrets/tokens/vault-token` is used as the default value.
If not specified, then the authenticator will first try `/var/run/secrets/tokens/vault-token`
and then `/var/run/secrets/tokens/sa-token` as the default value (first file found is used).
The application must have `read` permissions on the file containing the CR token value.

@@ -258,0 +259,0 @@

@@ -26,2 +26,3 @@ <!-- Do not edit this file. It is automatically generated by API Documenter. -->

| --- | --- | --- |
| [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. |
| [requestToken()](./ibm-cloud-sdk-core.containertokenmanager.requesttoken.md) | <code>protected</code> | Request an IAM token using a compute resource token. |

@@ -28,0 +29,0 @@ | [setCrTokenFilename(crTokenFilename)](./ibm-cloud-sdk-core.containertokenmanager.setcrtokenfilename.md) | | Sets the "crTokenFilename" field |

@@ -0,1 +1,8 @@

## [4.0.7](https://github.com/IBM/node-sdk-core/compare/v4.0.6...v4.0.7) (2023-05-22)
### Bug Fixes
* **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))
## [4.0.6](https://github.com/IBM/node-sdk-core/compare/v4.0.5...v4.0.6) (2023-05-18)

@@ -2,0 +9,0 @@

/**
* Copyright 2021, 2022 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -72,3 +72,13 @@ * Licensed under the Apache License, Version 2.0 (the "License");

protected requestToken(): Promise<any>;
/**
* 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.
*
* @returns the CR token value as a string
*/
protected getCrToken(): string;
}
export {};
/**
* Copyright 2021, 2022 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -25,6 +25,6 @@ * Licensed under the Apache License, Version 2.0 (the "License");

};
import logger from '../../lib/logger';
import { atLeastOne, readCrTokenFile } from '../utils';
import { IamRequestBasedTokenManager } from './iam-request-based-token-manager';
const DEFAULT_CR_TOKEN_FILEPATH = '/var/run/secrets/tokens/vault-token';
const DEFAULT_CR_TOKEN_FILEPATH1 = '/var/run/secrets/tokens/vault-token';
const DEFAULT_CR_TOKEN_FILEPATH2 = '/var/run/secrets/tokens/sa-token';
/**

@@ -63,3 +63,5 @@ * The ContainerTokenManager retrieves a compute resource token from a file on the container. This token

}
this.crTokenFilename = options.crTokenFilename || DEFAULT_CR_TOKEN_FILEPATH;
if (options.crTokenFilename) {
this.crTokenFilename = options.crTokenFilename;
}
if (options.iamProfileName) {

@@ -103,4 +105,3 @@ this.iamProfileName = options.iamProfileName;

return __awaiter(this, void 0, void 0, function* () {
const crToken = getCrToken(this.crTokenFilename);
this.formData.cr_token = crToken;
this.formData.cr_token = this.getCrToken();
// these member variables can be reset, set them in the form data right

@@ -117,7 +118,33 @@ // before making the request to ensure they're up to date

}
/**
* 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.
*
* @returns the CR token value as a string
*/
getCrToken() {
try {
let crToken = null;
if (this.crTokenFilename) {
// If the user specified a filename, then try to read from that.
crToken = readCrTokenFile(this.crTokenFilename);
}
else {
// If no filename was specified, then try our two default filenames.
try {
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH1);
}
catch (err) {
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH2);
}
}
return crToken;
}
catch (err) {
throw new Error(`Error reading CR token file: ${err.toString()}`);
}
}
}
function getCrToken(filename) {
logger.debug(`Attempting to read CR token from file: ${filename}`);
// moving the actual read to another file to isolate usage of node-only packages like `fs`
return readCrTokenFile(filename);
}
/**
* Copyright 2021 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License");

/**
* Copyright 2021 IBM Corp. All Rights Reserved.
* Copyright 2021, 2023 IBM Corp. All Rights Reserved.
*

@@ -82,18 +82,14 @@ * Licensed under the Apache License, Version 2.0 (the "License");

}
let token = '';
const fileExists = fileExistsAtPath(filepath);
if (fileExists) {
try {
let token = '';
logger.debug(`Attempting to read CR token from file: ${filepath}`);
token = readFileSync(filepath, 'utf8');
logger.debug(`Successfully read CR token from file: ${filepath}`);
return token;
}
if (token === '') {
if (fileExists) {
logger.error(`Expected to read CR token from file but the file is empty: ${filepath}`);
}
else {
logger.error(`Expected to find CR token file but the file does not exist: ${filepath}`);
}
throw new Error(`Unable to retrieve the CR token value from file: ${filepath}`);
catch (err) {
const msg = `Error reading CR token: ${err.toString()}`;
logger.debug(msg);
throw new Error(msg);
}
return token;
}

@@ -152,2 +152,3 @@ ## API Report File for "ibm-cloud-sdk-core"

constructor(options: Options_7);
protected getCrToken(): string;
protected requestToken(): Promise<any>;

@@ -154,0 +155,0 @@ setCrTokenFilename(crTokenFilename: string): void;

{
"name": "ibm-cloud-sdk-core",
"version": "4.0.6",
"version": "4.0.7",
"description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -152,2 +152,3 @@ ## API Report File for "ibm-cloud-sdk-core"

constructor(options: Options_7);
protected getCrToken(): string;
protected requestToken(): Promise<any>;

@@ -154,0 +155,0 @@ setCrTokenFilename(crTokenFilename: string): void;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc