UNPKG

3.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.fromSSO = void 0;
4const property_provider_1 = require("@aws-sdk/property-provider");
5const shared_ini_file_loader_1 = require("@aws-sdk/shared-ini-file-loader");
6const isSsoProfile_1 = require("./isSsoProfile");
7const resolveSSOCredentials_1 = require("./resolveSSOCredentials");
8const validateSsoProfile_1 = require("./validateSsoProfile");
9const fromSSO = (init = {}) => async () => {
10 const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, ssoSession } = init;
11 const profileName = (0, shared_ini_file_loader_1.getProfileName)(init);
12 if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
13 const profiles = await (0, shared_ini_file_loader_1.parseKnownFiles)(init);
14 const profile = profiles[profileName];
15 if (!profile) {
16 throw new property_provider_1.CredentialsProviderError(`Profile ${profileName} was not found.`);
17 }
18 if (!(0, isSsoProfile_1.isSsoProfile)(profile)) {
19 throw new property_provider_1.CredentialsProviderError(`Profile ${profileName} is not configured with SSO credentials.`);
20 }
21 if (profile === null || profile === void 0 ? void 0 : profile.sso_session) {
22 const ssoSessions = await (0, shared_ini_file_loader_1.loadSsoSessionData)(init);
23 const session = ssoSessions[profile.sso_session];
24 const conflictMsg = ` configurations in profile ${profileName} and sso-session ${profile.sso_session}`;
25 if (ssoRegion && ssoRegion !== session.sso_region) {
26 throw new property_provider_1.CredentialsProviderError(`Conflicting SSO region` + conflictMsg, false);
27 }
28 if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
29 throw new property_provider_1.CredentialsProviderError(`Conflicting SSO start_url` + conflictMsg, false);
30 }
31 profile.sso_region = session.sso_region;
32 profile.sso_start_url = session.sso_start_url;
33 }
34 const { sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session } = (0, validateSsoProfile_1.validateSsoProfile)(profile);
35 return (0, resolveSSOCredentials_1.resolveSSOCredentials)({
36 ssoStartUrl: sso_start_url,
37 ssoSession: sso_session,
38 ssoAccountId: sso_account_id,
39 ssoRegion: sso_region,
40 ssoRoleName: sso_role_name,
41 ssoClient: ssoClient,
42 profile: profileName,
43 });
44 }
45 else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
46 throw new property_provider_1.CredentialsProviderError("Incomplete configuration. The fromSSO() argument hash must include " +
47 '"ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"');
48 }
49 else {
50 return (0, resolveSSOCredentials_1.resolveSSOCredentials)({
51 ssoStartUrl,
52 ssoSession,
53 ssoAccountId,
54 ssoRegion,
55 ssoRoleName,
56 ssoClient,
57 profile: profileName,
58 });
59 }
60};
61exports.fromSSO = fromSSO;