UNPKG

2 kBJavaScriptView Raw
1import { __assign, __awaiter, __generator, __rest } from "tslib";
2import { CredentialsProviderError } from "@aws-sdk/property-provider";
3import { getProfileName, loadSharedConfigFiles } from "@aws-sdk/shared-ini-file-loader";
4export var fromSharedConfigFiles = function (configSelector, _a) {
5 if (_a === void 0) { _a = {}; }
6 var _b = _a.preferredFile, preferredFile = _b === void 0 ? "config" : _b, init = __rest(_a, ["preferredFile"]);
7 return function () { return __awaiter(void 0, void 0, void 0, function () {
8 var profile, _a, configFile, credentialsFile, profileFromCredentials, profileFromConfig, mergedProfile, configValue;
9 return __generator(this, function (_b) {
10 switch (_b.label) {
11 case 0:
12 profile = getProfileName(init);
13 return [4, loadSharedConfigFiles(init)];
14 case 1:
15 _a = _b.sent(), configFile = _a.configFile, credentialsFile = _a.credentialsFile;
16 profileFromCredentials = credentialsFile[profile] || {};
17 profileFromConfig = configFile[profile] || {};
18 mergedProfile = preferredFile === "config"
19 ? __assign(__assign({}, profileFromCredentials), profileFromConfig) : __assign(__assign({}, profileFromConfig), profileFromCredentials);
20 try {
21 configValue = configSelector(mergedProfile);
22 if (configValue === undefined) {
23 throw new Error();
24 }
25 return [2, configValue];
26 }
27 catch (e) {
28 throw new CredentialsProviderError(e.message ||
29 "Cannot load config for profile ".concat(profile, " in SDK configuration files with getter: ").concat(configSelector));
30 }
31 return [2];
32 }
33 });
34 }); };
35};