1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.fromSharedConfigFiles = void 0;
|
4 | const property_provider_1 = require("@aws-sdk/property-provider");
|
5 | const shared_ini_file_loader_1 = require("@aws-sdk/shared-ini-file-loader");
|
6 | const fromSharedConfigFiles = (configSelector, { preferredFile = "config", ...init } = {}) => async () => {
|
7 | const profile = (0, shared_ini_file_loader_1.getProfileName)(init);
|
8 | const { configFile, credentialsFile } = await (0, shared_ini_file_loader_1.loadSharedConfigFiles)(init);
|
9 | const profileFromCredentials = credentialsFile[profile] || {};
|
10 | const profileFromConfig = configFile[profile] || {};
|
11 | const mergedProfile = preferredFile === "config"
|
12 | ? { ...profileFromCredentials, ...profileFromConfig }
|
13 | : { ...profileFromConfig, ...profileFromCredentials };
|
14 | try {
|
15 | const configValue = configSelector(mergedProfile);
|
16 | if (configValue === undefined) {
|
17 | throw new Error();
|
18 | }
|
19 | return configValue;
|
20 | }
|
21 | catch (e) {
|
22 | throw new property_provider_1.CredentialsProviderError(e.message ||
|
23 | `Cannot load config for profile ${profile} in SDK configuration files with getter: ${configSelector}`);
|
24 | }
|
25 | };
|
26 | exports.fromSharedConfigFiles = fromSharedConfigFiles;
|