@@ -33,34 +33,25 @@ export class AwsCliCompatible {
33
33
* 4. Respects $AWS_DEFAULT_PROFILE in addition to $AWS_PROFILE.
34
34
*/
35
35
public static async credentialChain ( options : CredentialChainOptions = { } ) {
36
+ // Force reading the `config` file if it exists by setting the appropriate
37
+ // environment variable.
38
+ await forceSdkToReadConfigIfPresent ( ) ;
36
39
37
40
// To match AWS CLI behavior, if a profile is explicitly given using --profile,
38
41
// we use that to the exclusion of everything else (note: this does not apply
39
42
// to AWS_PROFILE, environment credentials still take precedence over AWS_PROFILE)
40
43
if ( options . profile ) {
41
- await forceSdkToReadConfigIfPresent ( ) ;
42
- const theProfile = options . profile ;
43
- return new AWS . CredentialProviderChain ( [
44
- ( ) => profileCredentials ( theProfile ) ,
45
- ( ) => new AWS . ProcessCredentials ( { profile : theProfile } ) ,
46
- ] ) ;
44
+ return new AWS . CredentialProviderChain ( iniFileCredentialFactories ( options . profile ) ) ;
47
45
}
48
46
49
47
const implicitProfile = process . env . AWS_PROFILE || process . env . AWS_DEFAULT_PROFILE || 'default' ;
50
48
51
49
const sources = [
52
50
( ) => new AWS . EnvironmentCredentials ( 'AWS' ) ,
53
51
( ) => new AWS . EnvironmentCredentials ( 'AMAZON' ) ,
52
+ ...iniFileCredentialFactories ( implicitProfile ) ,
54
53
] ;
55
54
56
- if ( await fs . pathExists ( credentialsFileName ( ) ) ) {
57
- // Force reading the `config` file if it exists by setting the appropriate
58
- // environment variable.
59
- await forceSdkToReadConfigIfPresent ( ) ;
60
- sources . push ( ( ) => profileCredentials ( implicitProfile ) ) ;
61
- sources . push ( ( ) => new AWS . ProcessCredentials ( { profile : implicitProfile } ) ) ;
62
- }
63
-
64
55
if ( options . containerCreds ?? hasEcsCredentials ( ) ) {
65
56
sources . push ( ( ) => new AWS . ECSCredentials ( ) ) ;
66
57
} else if ( hasWebIdentityCredentials ( ) ) {
@@ -83,6 +74,14 @@ export class AwsCliCompatible {
83
74
tokenCodeFn,
84
75
} ) ;
85
76
}
77
+
78
+ function iniFileCredentialFactories ( theProfile : string ) {
79
+ return [
80
+ ( ) => profileCredentials ( theProfile ) ,
81
+ ( ) => new AWS . SsoCredentials ( { profile : theProfile } ) ,
82
+ ( ) => new AWS . ProcessCredentials ( { profile : theProfile } ) ,
83
+ ] ;
84
+ }
86
85
}
87
86
88
87
/**
0 commit comments