@@ -88,20 +88,73 @@ public static class CredentialProfileTypeDetector
88
88
private static Dictionary < CredentialProfileType , List < HashSet < string > > > TypePropertyDictionary =
89
89
new Dictionary < CredentialProfileType , List < HashSet < string > > > ( )
90
90
{
91
- {
92
- CredentialProfileType . CredentialProcess , new List < HashSet < string > > ( )
93
- {
94
- new HashSet < string > { CredentialProcess } ,
95
- new HashSet < string > { CredentialProcess , AwsAccountId }
96
- }
91
+ { CredentialProfileType . Basic , new List < HashSet < string > > ( )
92
+ {
93
+ new HashSet < string > { AccessKey , SecretKey } ,
94
+ new HashSet < string > { AccessKey , SecretKey , AwsAccountId } ,
95
+ }
97
96
} ,
98
-
99
- {
100
- CredentialProfileType . AssumeRole , new List < HashSet < string > > ( )
97
+ {
98
+ CredentialProfileType . Session , new List < HashSet < string > > ( )
99
+ {
100
+ new HashSet < string > { AccessKey , SecretKey , Token } ,
101
+ new HashSet < string > { AccessKey , SecretKey , Token , AwsAccountId } ,
102
+ }
103
+ } ,
104
+ {
105
+ CredentialProfileType . AssumeRole , new List < HashSet < string > > ( )
101
106
{
102
107
new HashSet < string > { RoleArn , SourceProfile } ,
103
108
new HashSet < string > { RoleArn , SourceProfile , AwsAccountId } ,
104
- }
109
+ }
110
+ } ,
111
+ {
112
+ CredentialProfileType . AssumeRoleMFA , new List < HashSet < string > > ( )
113
+ {
114
+ new HashSet < string > { MfaSerial , RoleArn , SourceProfile } ,
115
+ new HashSet < string > { MfaSerial , RoleArn , SourceProfile , AwsAccountId } ,
116
+ }
117
+ } ,
118
+ {
119
+ CredentialProfileType . AssumeRoleMFASessionName , new List < HashSet < string > > ( )
120
+ {
121
+ new HashSet < string > { MfaSerial , RoleArn , SourceProfile , RoleSessionName } ,
122
+ new HashSet < string > { MfaSerial , RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
123
+ }
124
+ } ,
125
+ {
126
+ CredentialProfileType . AssumeRoleExternalMFA , new List < HashSet < string > > ( )
127
+ {
128
+ new HashSet < string > { ExternalID , RoleArn , SourceProfile , MfaSerial }
129
+ }
130
+ } ,
131
+ {
132
+ CredentialProfileType . AssumeRoleExternal , new List < HashSet < string > > ( )
133
+ {
134
+ new HashSet < string > { ExternalID , RoleArn , SourceProfile } ,
135
+ new HashSet < string > { ExternalID , RoleArn , SourceProfile , AwsAccountId } ,
136
+ }
137
+ } ,
138
+ {
139
+ CredentialProfileType . AssumeRoleSessionName , new List < HashSet < string > > ( )
140
+ {
141
+ new HashSet < string > { RoleArn , SourceProfile , RoleSessionName } ,
142
+ new HashSet < string > { RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
143
+ }
144
+ } ,
145
+ {
146
+ CredentialProfileType . AssumeRoleExternalSessionName , new List < HashSet < string > > ( )
147
+ {
148
+ new HashSet < string > { ExternalID , RoleArn , SourceProfile , RoleSessionName } ,
149
+ new HashSet < string > { ExternalID , RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
150
+ }
151
+ } ,
152
+ {
153
+ CredentialProfileType . AssumeRoleExternalMFASessionName , new List < HashSet < string > > ( )
154
+ {
155
+ new HashSet < string > { ExternalID , MfaSerial , RoleArn , SourceProfile , RoleSessionName } ,
156
+ new HashSet < string > { ExternalID , MfaSerial , RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
157
+ }
105
158
} ,
106
159
{
107
160
CredentialProfileType . AssumeRoleCredentialSource , new List < HashSet < string > > ( )
@@ -111,13 +164,12 @@ public static class CredentialProfileTypeDetector
111
164
}
112
165
} ,
113
166
{
114
- CredentialProfileType . AssumeRoleExternal , new List < HashSet < string > > ( )
115
- {
116
- new HashSet < string > { ExternalID , RoleArn , SourceProfile } ,
117
- new HashSet < string > { ExternalID , RoleArn , SourceProfile , AwsAccountId } ,
118
- }
167
+ CredentialProfileType . AssumeRoleCredentialSourceSessionName , new List < HashSet < string > > ( )
168
+ {
169
+ new HashSet < string > { RoleArn , CredentialSource , RoleSessionName } ,
170
+ new HashSet < string > { RoleArn , CredentialSource , RoleSessionName , AwsAccountId } ,
171
+ }
119
172
} ,
120
- { CredentialProfileType . AssumeRoleExternalMFA , new List < HashSet < string > > ( ) { new HashSet < string > { ExternalID , RoleArn , SourceProfile , MfaSerial } } } ,
121
173
{
122
174
CredentialProfileType . AssumeRoleWithWebIdentity , new List < HashSet < string > > ( )
123
175
{
@@ -133,70 +185,33 @@ public static class CredentialProfileTypeDetector
133
185
new HashSet < string > { RoleArn , WebIdentityTokenFile , RoleSessionName , AwsAccountId } ,
134
186
}
135
187
} ,
136
- {
137
- CredentialProfileType . AssumeRoleMFA , new List < HashSet < string > > ( )
138
- {
139
- new HashSet < string > { MfaSerial , RoleArn , SourceProfile } ,
140
- new HashSet < string > { MfaSerial , RoleArn , SourceProfile , AwsAccountId } ,
141
- }
142
- } ,
143
- { CredentialProfileType . Basic , new List < HashSet < string > > ( )
144
- {
145
- new HashSet < string > { AccessKey , SecretKey } ,
146
- new HashSet < string > { AccessKey , SecretKey , AwsAccountId } ,
147
- }
148
- } ,
149
188
{
150
189
CredentialProfileType . SAMLRole , new List < HashSet < string > > ( )
151
190
{
152
191
new HashSet < string > { EndpointName , RoleArn } ,
153
192
new HashSet < string > { EndpointName , RoleArn , AwsAccountId } ,
154
193
}
155
194
} ,
156
- { CredentialProfileType . SAMLRoleUserIdentity , new List < HashSet < string > > ( ) { new HashSet < string > { EndpointName , RoleArn , UserIdentity } } } ,
157
195
{
158
- CredentialProfileType . Session , new List < HashSet < string > > ( )
196
+ CredentialProfileType . SAMLRoleUserIdentity , new List < HashSet < string > > ( )
159
197
{
160
- new HashSet < string > { AccessKey , SecretKey , Token } ,
161
- new HashSet < string > { AccessKey , SecretKey , Token , AwsAccountId } ,
198
+ new HashSet < string > { EndpointName , RoleArn , UserIdentity }
162
199
}
163
200
} ,
164
201
{
165
- CredentialProfileType . AssumeRoleSessionName , new List < HashSet < string > > ( )
166
- {
167
- new HashSet < string > { RoleArn , SourceProfile , RoleSessionName } ,
168
- new HashSet < string > { RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
169
- }
170
- } ,
171
- {
172
- CredentialProfileType . AssumeRoleCredentialSourceSessionName , new List < HashSet < string > > ( )
202
+ CredentialProfileType . SSO , new List < HashSet < string > > ( )
173
203
{
174
- new HashSet < string > { RoleArn , CredentialSource , RoleSessionName } ,
175
- new HashSet < string > { RoleArn , CredentialSource , RoleSessionName , AwsAccountId } ,
176
- }
177
- } ,
178
- {
179
- CredentialProfileType . AssumeRoleExternalSessionName , new List < HashSet < string > > ( )
180
- {
181
- new HashSet < string > { ExternalID , RoleArn , SourceProfile , RoleSessionName } ,
182
- new HashSet < string > { ExternalID , RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
183
- }
184
- } ,
185
- {
186
- CredentialProfileType . AssumeRoleExternalMFASessionName , new List < HashSet < string > > ( )
187
- {
188
- new HashSet < string > { ExternalID , MfaSerial , RoleArn , SourceProfile , RoleSessionName } ,
189
- new HashSet < string > { ExternalID , MfaSerial , RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
204
+ new HashSet < string > { SsoAccountId , SsoRegion , SsoRegistrationScopes , SsoRoleName , SsoStartUrl , SsoSession }
190
205
}
191
206
} ,
192
- { CredentialProfileType . SSO , new List < HashSet < string > > ( ) { new HashSet < string > { SsoAccountId , SsoRegion , SsoRegistrationScopes , SsoRoleName , SsoStartUrl , SsoSession } } } ,
193
- {
194
- CredentialProfileType . AssumeRoleMFASessionName , new List < HashSet < string > > ( )
195
- {
196
- new HashSet < string > { MfaSerial , RoleArn , SourceProfile , RoleSessionName } ,
197
- new HashSet < string > { MfaSerial , RoleArn , SourceProfile , RoleSessionName , AwsAccountId } ,
198
- }
207
+ {
208
+ CredentialProfileType . CredentialProcess , new List < HashSet < string > > ( )
209
+ {
210
+ new HashSet < string > { CredentialProcess } ,
211
+ new HashSet < string > { CredentialProcess , AwsAccountId }
212
+ }
199
213
} ,
214
+
200
215
} ;
201
216
202
217
private static Dictionary < CredentialProfileType , string > CredentialTypeDictionary =
@@ -238,18 +253,13 @@ public static string GetUserFriendlyCredentialType(CredentialProfileType? profil
238
253
239
254
HashSet < string > propertyNames = GetPropertyNames ( profileOptions ) ;
240
255
241
- // Spec: If one or more of the SSO properties is present, the profile MUST be resolved by the SSO credential provider.
242
- if ( propertyNames . Any ( propertyName => SsoProperties . Contains ( propertyName ) ) )
243
- {
244
- return CredentialProfileType . SSO ;
245
- }
246
256
247
257
// brute force algorithm - but it's a very small set
248
258
foreach ( var pair in TypePropertyDictionary )
249
259
{
250
260
foreach ( var item in pair . Value )
251
261
{
252
- if ( item . SetEquals ( propertyNames ) )
262
+ if ( item . IsSubsetOf ( propertyNames ) )
253
263
{
254
264
profileType = pair . Key ;
255
265
}
0 commit comments