UNPKG

@softchef/cdk-iot-device-management

Version:

IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.

26 lines (25 loc) 1.51 kB
import { __assign, __awaiter, __generator } from "tslib"; import { CredentialsProviderError } from "@aws-sdk/property-provider"; import { readFileSync } from "fs"; import { fromWebToken } from "./fromWebToken"; var ENV_TOKEN_FILE = "AWS_WEB_IDENTITY_TOKEN_FILE"; var ENV_ROLE_ARN = "AWS_ROLE_ARN"; var ENV_ROLE_SESSION_NAME = "AWS_ROLE_SESSION_NAME"; export var fromTokenFile = function (init) { if (init === void 0) { init = {}; } return function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { return [2, resolveTokenFile(init)]; }); }); }; }; var resolveTokenFile = function (init) { var _a, _b, _c; var webIdentityTokenFile = (_a = init === null || init === void 0 ? void 0 : init.webIdentityTokenFile) !== null && _a !== void 0 ? _a : process.env[ENV_TOKEN_FILE]; var roleArn = (_b = init === null || init === void 0 ? void 0 : init.roleArn) !== null && _b !== void 0 ? _b : process.env[ENV_ROLE_ARN]; var roleSessionName = (_c = init === null || init === void 0 ? void 0 : init.roleSessionName) !== null && _c !== void 0 ? _c : process.env[ENV_ROLE_SESSION_NAME]; if (!webIdentityTokenFile || !roleArn) { throw new CredentialsProviderError("Web identity configuration not specified"); } return fromWebToken(__assign(__assign({}, init), { webIdentityToken: readFileSync(webIdentityTokenFile, { encoding: "ascii" }), roleArn: roleArn, roleSessionName: roleSessionName }))(); };