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.

29 lines (28 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fromSharedConfigFiles = exports.ENV_PROFILE = void 0; const property_provider_1 = require("@aws-sdk/property-provider"); const shared_ini_file_loader_1 = require("@aws-sdk/shared-ini-file-loader"); const DEFAULT_PROFILE = "default"; exports.ENV_PROFILE = "AWS_PROFILE"; const fromSharedConfigFiles = (configSelector, { preferredFile = "config", ...init } = {}) => async () => { const { loadedConfig = shared_ini_file_loader_1.loadSharedConfigFiles(init), profile = process.env[exports.ENV_PROFILE] || DEFAULT_PROFILE } = init; const { configFile, credentialsFile } = await loadedConfig; const profileFromCredentials = credentialsFile[profile] || {}; const profileFromConfig = configFile[profile] || {}; const mergedProfile = preferredFile === "config" ? { ...profileFromCredentials, ...profileFromConfig } : { ...profileFromConfig, ...profileFromCredentials }; try { const configValue = configSelector(mergedProfile); if (configValue === undefined) { throw new Error(); } return configValue; } catch (e) { throw new property_provider_1.CredentialsProviderError(e.message || `Cannot load config for profile ${profile} in SDK configuration files with getter: ${configSelector}`); } }; exports.fromSharedConfigFiles = fromSharedConfigFiles;