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.

38 lines (37 loc) 2.21 kB
import { __assign, __awaiter, __generator, __rest } from "tslib"; import { CredentialsProviderError } from "@aws-sdk/property-provider"; import { loadSharedConfigFiles, } from "@aws-sdk/shared-ini-file-loader"; var DEFAULT_PROFILE = "default"; export var ENV_PROFILE = "AWS_PROFILE"; export var fromSharedConfigFiles = function (configSelector, _a) { if (_a === void 0) { _a = {}; } var _b = _a.preferredFile, preferredFile = _b === void 0 ? "config" : _b, init = __rest(_a, ["preferredFile"]); return function () { return __awaiter(void 0, void 0, void 0, function () { var _a, loadedConfig, _b, profile, _c, configFile, credentialsFile, profileFromCredentials, profileFromConfig, mergedProfile, configValue; return __generator(this, function (_d) { switch (_d.label) { case 0: _a = init.loadedConfig, loadedConfig = _a === void 0 ? loadSharedConfigFiles(init) : _a, _b = init.profile, profile = _b === void 0 ? process.env[ENV_PROFILE] || DEFAULT_PROFILE : _b; return [4, loadedConfig]; case 1: _c = _d.sent(), configFile = _c.configFile, credentialsFile = _c.credentialsFile; profileFromCredentials = credentialsFile[profile] || {}; profileFromConfig = configFile[profile] || {}; mergedProfile = preferredFile === "config" ? __assign(__assign({}, profileFromCredentials), profileFromConfig) : __assign(__assign({}, profileFromConfig), profileFromCredentials); try { configValue = configSelector(mergedProfile); if (configValue === undefined) { throw new Error(); } return [2, configValue]; } catch (e) { throw new CredentialsProviderError(e.message || "Cannot load config for profile " + profile + " in SDK configuration files with getter: " + configSelector); } return [2]; } }); }); }; };