Skip to content

Commit 7841e27

Browse files
committed
revision 4
1 parent 5d6f66f commit 7841e27

File tree

3 files changed

+24
-324
lines changed

3 files changed

+24
-324
lines changed

packages/credential-providers/src/fromAwsCliV2CompatibleProviderChain.spec.ts

Lines changed: 0 additions & 155 deletions
This file was deleted.

packages/credential-providers/src/fromAwsCliV2CompatibleProviderChain.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,11 @@ export type AwsCliV2CompatibleProviderOptions = Partial<AwsCredentialIdentity> &
2222
FromSSOInit &
2323
FromTokenFileInit & {
2424
/**
25-
* Setting a client profile is similar to setting a value for the
26-
* AWS_PROFILE environment variable. Setting a profile on a client
27-
* in code only affects the single client instance, unlike AWS_PROFILE.
28-
*
29-
* When set, and only for environments where an AWS configuration
30-
* file exists, fields configurable by this file will be retrieved
31-
* from the specified profile within that file.
32-
* Conflicting code configuration and environment variables will
33-
* still have higher priority.
34-
*
35-
* For client credential resolution that involves checking the AWS
36-
* configuration file, the client's profile (this value) will be
37-
* used unless a different profile is set in the credential
38-
* provider options.
25+
* The name of the profile to use while loading credentials.
26+
* If specified, credentials will be loaded from the shared credentials file
27+
* or shared config file using this profile.
28+
* If not specified, the provider chain will attempt to load credentials from
29+
* other sources according to order of precedence.
3930
*
4031
*/
4132
profile?: string;
@@ -52,18 +43,18 @@ export type AwsCliV2CompatibleProviderOptions = Partial<AwsCredentialIdentity> &
5243
* Creates a credential provider that sources credentials using the same priority
5344
* chain as the AWS CLI v2:
5445
*
55-
* 1. Static credentials from initialization
56-
* 2. Profile credentials (if profile specified)
57-
* 3. Environment variables
58-
* 4. Web Identity Token credentials
59-
* 5. SSO credentials
60-
* 6. Process credentials
61-
* 7. Remote credentials (ECS, EC2 Instance Metadata)
46+
* 1. Static credentials from initialization.
47+
* 2. Profile credentials (if profile specified).
48+
* 3. Environment variables.
49+
* 4. Web Identity Token credentials.
50+
* 5. SSO credentials.
51+
* 6. Process credentials.
52+
* 7. Remote credentials (ECS, EC2 Instance Metadata).
6253
*
6354
* Uses dynamic imports and `createCredentialChain` to mimic AWS CLI V2 behavior.
6455
*
6556
* @param init - Configuration options for the provider chain
66-
* @returns An AWS credential provider function that returns a promise for credentials
57+
* @returns An AWS credential provider function
6758
*/
6859

6960
export const fromAwsCliV2CompatibleProviderChain =
@@ -73,31 +64,36 @@ export const fromAwsCliV2CompatibleProviderChain =
7364
const init: AwsCliV2CompatibleProviderOptions = {
7465
..._init,
7566
...callerClientConfig,
67+
profile: _init.profile ?? callerClientConfig?.profile,
7668
logger: _init.logger ?? callerClientConfig?.logger,
7769
};
7870

7971
init.logger?.debug(
8072
"@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - Initializing credential chain"
8173
);
8274

83-
const { profile, logger, ...awsCredentials } = init;
75+
const { profile, logger, accessKeyId, secretAccessKey, sessionToken, expiration, ...rest } = init;
8476

8577
// 1. If credentials are explicitly provided, return them.
86-
if (awsCredentials.accessKeyId && awsCredentials.secretAccessKey) {
78+
if (accessKeyId && secretAccessKey) {
8779
logger?.debug(
8880
"@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - using static credentials from initialization"
8981
);
90-
return awsCredentials as AwsCredentialIdentity;
82+
return {
83+
accessKeyId,
84+
secretAccessKey,
85+
...(sessionToken && { sessionToken }),
86+
...(expiration && { expiration }),
87+
} as AwsCredentialIdentity;
9188
}
9289

9390
// 2. If a profile is explicitly passed, use `fromIni`.
9491
if (profile) {
9592
logger?.debug(
96-
"@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - Using fromIni with profile:",
97-
profile
93+
"@aws-sdk/credential-providers - fromAwsCliV2CompatibleProviderChain - Using fromIni with profile:" + profile
9894
);
9995
const { fromIni } = await import("@aws-sdk/credential-provider-ini");
100-
return fromIni({ profile, logger })();
96+
return fromIni({ profile, logger, ...init })();
10197
}
10298

10399
logger?.debug(

packages/credential-providers/src/resolveAwsCliV2Region.spec.ts

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)