UNPKG

2.99 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.sso_session) {
16 const ssoSessions = await (0, shared_ini_file_loader_1.loadSsoSessionData)(init);
17 const session = ssoSessions[profile.sso_session];
18 const conflictMsg = ` configurations in profile ${profileName} and sso-session ${profile.sso_session}`;
19 if (ssoRegion && ssoRegion !== session.sso_region) {
20 throw new property_provider_1.CredentialsProviderError(`Conflicting SSO region` + conflictMsg, false);
21 }
22 if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
23 throw new property_provider_1.CredentialsProviderError(`Conflicting SSO start_url` + conflictMsg, false);
24 }
25 profile.sso_region = session.sso_region;
26 profile.sso_start_url = session.sso_start_url;
27 }
28 if (!(0, isSsoProfile_1.isSsoProfile)(profile)) {
29 throw new property_provider_1.CredentialsProviderError(`Profile ${profileName} is not configured with SSO credentials.`);
30 }
31 const { sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session } = (0, validateSsoProfile_1.validateSsoProfile)(profile);
32 return (0, resolveSSOCredentials_1.resolveSSOCredentials)({
33 ssoStartUrl: sso_start_url,
34 ssoSession: sso_session,
35 ssoAccountId: sso_account_id,
36 ssoRegion: sso_region,
37 ssoRoleName: sso_role_name,
38 ssoClient: ssoClient,
39 profile: profileName,
40 });
41 }
42 else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
43 throw new property_provider_1.CredentialsProviderError("Incomplete configuration. The fromSSO() argument hash must include " +
44 '"ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"');
45 }
46 else {
47 return (0, resolveSSOCredentials_1.resolveSSOCredentials)({
48 ssoStartUrl,
49 ssoSession,
50 ssoAccountId,
51 ssoRegion,
52 ssoRoleName,
53 ssoClient,
54 profile: profileName,
55 });
56 }
57};
58exports.fromSSO = fromSSO;