@@ -22,6 +22,7 @@ import software.aws.toolkits.core.ToolkitClientManager
22
22
import software.aws.toolkits.core.credentials.CredentialIdentifier
23
23
import software.aws.toolkits.core.credentials.CredentialIdentifierBase
24
24
import software.aws.toolkits.core.credentials.CredentialProviderFactory
25
+ import software.aws.toolkits.core.credentials.CredentialType
25
26
import software.aws.toolkits.core.credentials.CredentialsChangeEvent
26
27
import software.aws.toolkits.core.credentials.CredentialsChangeListener
27
28
import software.aws.toolkits.core.credentials.sso.SSO_ACCOUNT
@@ -51,22 +52,24 @@ const val DEFAULT_PROFILE_ID = "profile:default"
51
52
52
53
private const val PROFILE_FACTORY_ID = " ProfileCredentialProviderFactory"
53
54
54
- private open class ProfileCredentialsIdentifier (val profileName : String , override val defaultRegionId : String? ) : CredentialIdentifierBase() {
55
+ private open class ProfileCredentialsIdentifier (val profileName : String , override val defaultRegionId : String? , credentialType : CredentialType ? ) :
56
+ CredentialIdentifierBase (credentialType) {
55
57
override val id = " profile:$profileName "
56
58
override val displayName = message(" credentials.profile.name" , profileName)
57
59
override val factoryId = PROFILE_FACTORY_ID
58
60
override val shortName: String = profileName
59
61
}
60
62
61
- private class ProfileCredentialsIdentifierMfa (profileName : String , defaultRegionId : String? ) :
62
- ProfileCredentialsIdentifier (profileName, defaultRegionId), MfaRequiredInteractiveCredentials
63
+ private class ProfileCredentialsIdentifierMfa (profileName : String , defaultRegionId : String? , credentialType : CredentialType ? ) :
64
+ ProfileCredentialsIdentifier (profileName, defaultRegionId, credentialType ), MfaRequiredInteractiveCredentials
63
65
64
66
private class ProfileCredentialsIdentifierSso (
65
67
profileName : String ,
66
68
defaultRegionId : String? ,
67
69
override val ssoCache : SsoCache ,
68
- override val ssoUrl : String
69
- ) : ProfileCredentialsIdentifier(profileName, defaultRegionId),
70
+ override val ssoUrl : String ,
71
+ credentialType : CredentialType ?
72
+ ) : ProfileCredentialsIdentifier(profileName, defaultRegionId, credentialType),
70
73
SsoRequiredInteractiveCredentials
71
74
72
75
class ProfileCredentialProviderFactory : CredentialProviderFactory {
@@ -317,16 +320,18 @@ class ProfileCredentialProviderFactory : CredentialProviderFactory {
317
320
private fun Profile.asId (profiles : Map <String , Profile >): ProfileCredentialsIdentifier {
318
321
val name = this .name()
319
322
val defaultRegion = this .properties()[ProfileProperty .REGION ]
323
+ val requestedProfileType = this .toCredentialType()
320
324
321
325
return when {
322
- this .requiresMfa(profiles) -> ProfileCredentialsIdentifierMfa (name, defaultRegion)
326
+ this .requiresMfa(profiles) -> ProfileCredentialsIdentifierMfa (name, defaultRegion, requestedProfileType )
323
327
this .requiresSso(profiles) -> ProfileCredentialsIdentifierSso (
324
328
name,
325
329
defaultRegion,
326
330
diskCache,
327
- this .requiredProperty(SSO_URL )
331
+ this .requiredProperty(SSO_URL ),
332
+ requestedProfileType
328
333
)
329
- else -> ProfileCredentialsIdentifier (name, defaultRegion)
334
+ else -> ProfileCredentialsIdentifier (name, defaultRegion, requestedProfileType )
330
335
}
331
336
}
332
337
@@ -337,6 +342,20 @@ class ProfileCredentialProviderFactory : CredentialProviderFactory {
337
342
.any { it.propertyExists(SSO_URL ) }
338
343
}
339
344
345
+ private fun Profile.toCredentialType (): CredentialType ? = when {
346
+ this .propertyExists(SSO_URL ) -> CredentialType .SsoProfile
347
+ this .propertyExists(ProfileProperty .ROLE_ARN ) -> {
348
+ if (this .propertyExists(ProfileProperty .MFA_SERIAL ))
349
+ CredentialType .AssumeMfaRoleProfile
350
+ else
351
+ CredentialType .AssumeRoleProfile
352
+ }
353
+ this .propertyExists(ProfileProperty .AWS_SESSION_TOKEN ) -> CredentialType .StaticSessionProfile
354
+ this .propertyExists(ProfileProperty .AWS_ACCESS_KEY_ID ) -> CredentialType .StaticProfile
355
+ this .propertyExists(ProfileProperty .CREDENTIAL_PROCESS ) -> CredentialType .CredentialProcessProfile
356
+ else -> null
357
+ }
358
+
340
359
private class ProfileHolder {
341
360
private val profiles = mutableMapOf<String , Profile >()
342
361
0 commit comments