Skip to content

Commit 3d7be94

Browse files
committed
fix(credential-provider-sso): prefer sso region for inner client if configured
1 parent 02f5d84 commit 3d7be94

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

packages/credential-provider-sso/src/fromSSO.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe(fromSSO.name, () => {
101101
expect(validateSsoProfile).toHaveBeenCalledWith(mockSsoProfile);
102102
});
103103

104-
it("calls resolveSSOCredentials with values from validated Sso profile", async () => {
104+
it("calls resolveSSOCredentials with values from validated SSO profile", async () => {
105105
const mockValidatedSsoProfile = {
106106
sso_start_url: "mock_sso_start_url",
107107
sso_account_id: "mock_sso_account_id",
@@ -119,7 +119,8 @@ describe(fromSSO.name, () => {
119119
ssoRoleName: mockValidatedSsoProfile.sso_role_name,
120120
profile: mockProfileName,
121121
ssoSession: undefined,
122-
ssoClient: expect.any(SSOClient),
122+
ssoClient: undefined,
123+
clientConfig: undefined,
123124
});
124125
});
125126
});

packages/credential-provider-sso/src/fromSSO.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ export const fromSSO =
8383
async () => {
8484
init.logger?.debug("@aws-sdk/credential-provider-sso", "fromSSO");
8585
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession } = init;
86-
let { ssoClient } = init;
87-
if (!ssoClient) {
88-
const { SSOClient } = await import("./loadSso");
89-
ssoClient = new SSOClient(init.clientConfig ?? {});
90-
}
86+
const { ssoClient } = init;
9187
const profileName = getProfileName(init);
9288

9389
if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
@@ -125,6 +121,7 @@ export const fromSSO =
125121
ssoRegion: sso_region,
126122
ssoRoleName: sso_role_name,
127123
ssoClient: ssoClient,
124+
clientConfig: init.clientConfig,
128125
profile: profileName,
129126
});
130127
} else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
@@ -140,6 +137,7 @@ export const fromSSO =
140137
ssoRegion,
141138
ssoRoleName,
142139
ssoClient,
140+
clientConfig: init.clientConfig,
143141
profile: profileName,
144142
});
145143
}

packages/credential-provider-sso/src/resolveSSOCredentials.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const resolveSSOCredentials = async ({
1818
ssoRegion,
1919
ssoRoleName,
2020
ssoClient,
21+
clientConfig,
2122
profile,
2223
}: FromSSOInit & SsoCredentialsParameters): Promise<AwsCredentialIdentity> => {
2324
let token: SSOToken;
@@ -55,7 +56,13 @@ export const resolveSSOCredentials = async ({
5556

5657
const { SSOClient, GetRoleCredentialsCommand } = await import("./loadSso");
5758

58-
const sso = ssoClient || new SSOClient({ region: ssoRegion });
59+
const sso =
60+
ssoClient ||
61+
new SSOClient(
62+
Object.assign({}, clientConfig ?? {}, {
63+
region: clientConfig?.region ?? ssoRegion,
64+
})
65+
);
5966
let ssoResp: GetRoleCredentialsCommandOutput;
6067
try {
6168
ssoResp = await sso.send(

0 commit comments

Comments
 (0)