-
Notifications
You must be signed in to change notification settings - Fork 273
Update telemetry: emit auth scopes in user state #4944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f157c53
f0d455d
924a2b0
4512625
a4db555
4e1af21
df30b58
2d053c5
13c8cd0
d05315f
744a2d3
098fa1d
e6082fe
214f4d8
e3e4838
5f780a1
1404bb1
82708b7
3ade8d8
0858d1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import software.aws.toolkits.jetbrains.core.credentials.CredentialManager | ||
| import software.aws.toolkits.jetbrains.core.credentials.ToolkitAuthManager | ||
| import software.aws.toolkits.jetbrains.core.credentials.profiles.ProfileCredentialsIdentifierSso | ||
| import software.aws.toolkits.jetbrains.core.credentials.sono.IDENTITY_CENTER_ROLE_ACCESS_SCOPE | ||
| import software.aws.toolkits.jetbrains.settings.AwsSettings | ||
| import software.aws.toolkits.telemetry.AuthStatus | ||
| import software.aws.toolkits.telemetry.StartUpState | ||
|
|
@@ -22,54 +23,66 @@ | |
|
|
||
| fun getEnabledConnectionsForTelemetry(project: Project?): Set<AuthFormId> { | ||
| project ?: return emptySet() | ||
| val enabledConnections = mutableSetOf<AuthFormId>() | ||
|
|
||
| val explorerConnection = checkIamConnectionValidity(project) | ||
| if (explorerConnection !is ActiveConnection.NotConnected) { | ||
| if (explorerConnection.connectionType == ActiveConnectionType.IAM_IDC) { | ||
| enabledConnections.add(AuthFormId.IDENTITYCENTER_EXPLORER) | ||
| } else { | ||
| enabledConnections.add( | ||
| AuthFormId.IAMCREDENTIALS_EXPLORER | ||
| ) | ||
| } | ||
| } | ||
| val codeCatalystConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODECATALYST) | ||
| if (codeCatalystConnection !is ActiveConnection.NotConnected) { | ||
| if (codeCatalystConnection.connectionType == ActiveConnectionType.IAM_IDC) { | ||
| enabledConnections.add(AuthFormId.IDENTITYCENTER_CODECATALYST) | ||
| } else { | ||
| enabledConnections.add(AuthFormId.BUILDERID_CODECATALYST) | ||
| } | ||
| } | ||
| val enabledConnections = mutableSetOf<Any>() | ||
|
|
||
| val codeWhispererConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODEWHISPERER) | ||
| if (codeWhispererConnection !is ActiveConnection.NotConnected) { | ||
| if (codeWhispererConnection.connectionType == ActiveConnectionType.IAM_IDC) { | ||
| enabledConnections.add(AuthFormId.IDENTITYCENTER_CODEWHISPERER) | ||
| } else { | ||
| enabledConnections.add( | ||
| AuthFormId.BUILDERID_CODEWHISPERER | ||
| ) | ||
| } | ||
| } | ||
| addConnectionInfoToSet( | ||
| checkIamConnectionValidity(project), | ||
| enabledConnections, | ||
| AuthFormId.IDENTITYCENTER_EXPLORER, | ||
| AuthFormId.IAMCREDENTIALS_EXPLORER | ||
| ) | ||
|
|
||
| val qConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.Q) | ||
| if (qConnection !is ActiveConnection.NotConnected) { | ||
| if (qConnection.connectionType == ActiveConnectionType.IAM_IDC) { | ||
| enabledConnections.add(AuthFormId.IDENTITYCENTER_Q) | ||
| } else { | ||
| enabledConnections.add( | ||
| AuthFormId.BUILDERID_Q | ||
| ) | ||
| } | ||
| } | ||
| return enabledConnections | ||
| addConnectionInfoToSet( | ||
| checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODECATALYST), | ||
| enabledConnections, | ||
| AuthFormId.IDENTITYCENTER_CODECATALYST, | ||
| AuthFormId.BUILDERID_CODECATALYST | ||
| ) | ||
|
|
||
| addConnectionInfoToSet( | ||
| checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODEWHISPERER), | ||
| enabledConnections, | ||
| AuthFormId.IDENTITYCENTER_CODEWHISPERER, | ||
| AuthFormId.BUILDERID_CODEWHISPERER | ||
| ) | ||
|
|
||
| addConnectionInfoToSet( | ||
| checkBearerConnectionValidity(project, BearerTokenFeatureSet.Q), | ||
| enabledConnections, | ||
| AuthFormId.IDENTITYCENTER_Q, | ||
| AuthFormId.BUILDERID_Q | ||
| ) | ||
| return enabledConnections.mapTo(mutableSetOf()) { it as AuthFormId } | ||
| } | ||
|
|
||
| fun getEnabledConnections(project: Project?): String = | ||
| getEnabledConnectionsForTelemetry(project).joinToString(",") | ||
|
|
||
| fun getAuthScopesForTelemetry(project: Project?): Set<String> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function above repeats some of the logic used here, can we move the common logic to a function? |
||
| project ?: return emptySet() | ||
| val scopes = mutableSetOf<Any>() | ||
|
Check warning on line 63 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
|
|
||
| val explorerConnection = checkIamProfileByCredentialType(project) | ||
|
Check warning on line 65 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| if (explorerConnection !is ActiveConnection.NotConnected && explorerConnection.connectionType == ActiveConnectionType.IAM_IDC) { | ||
| scopes.add(IDENTITY_CENTER_ROLE_ACCESS_SCOPE) | ||
|
Check warning on line 67 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| } | ||
|
|
||
| addConnectionInfoToSet( | ||
| checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODECATALYST), | ||
| dataSet = scopes | ||
|
Check warning on line 72 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| ) | ||
|
|
||
| addConnectionInfoToSet( | ||
| checkBearerConnectionValidity(project, BearerTokenFeatureSet.Q), | ||
| dataSet = scopes | ||
|
Check warning on line 77 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| ) | ||
|
|
||
| return scopes.mapTo(mutableSetOf()) { it as String } | ||
|
Check warning on line 80 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| } | ||
|
|
||
| fun getAuthScopes(project: Project?): String = | ||
| getAuthScopesForTelemetry(project).joinToString(",") | ||
|
Check warning on line 84 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
|
|
||
| fun getStartupState(): StartUpState { | ||
| val hasStartedToolkitBefore = tryOrNull { | ||
| getPersistentStateComponentStorageLocation(AwsSettings::class.java)?.exists() | ||
|
|
@@ -87,6 +100,38 @@ | |
| else -> AuthStatus.NotConnected | ||
| } | ||
|
|
||
| fun addConnectionInfoToSet( | ||
|
Check warning on line 103 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| activeConnection: ActiveConnection, | ||
| dataSet: MutableSet<Any>, | ||
| idcConnection: AuthFormId? = null, | ||
| defaultConnection: AuthFormId? = null, | ||
|
Check warning on line 107 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| ) { | ||
| if (activeConnection is ActiveConnection.NotConnected) { | ||
| return | ||
| } | ||
|
|
||
| // add enabled connections | ||
| when (activeConnection.connectionType) { | ||
| ActiveConnectionType.IAM_IDC -> { | ||
| idcConnection ?.let { | ||
| dataSet.add(idcConnection) | ||
| return | ||
|
Check warning on line 118 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| } | ||
| } else -> { | ||
| defaultConnection?.let { | ||
| dataSet.add(defaultConnection) | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // add scopes | ||
| val connectionScopes = activeConnection.activeConnectionBearer?.scopes | ||
| if (!connectionScopes.isNullOrEmpty()) { | ||
| dataSet.addAll(connectionScopes) | ||
|
Check warning on line 131 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| } | ||
| } | ||
|
Check warning on line 133 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
|
|
||
| enum class AuthFormId { | ||
| IAMCREDENTIALS_EXPLORER, | ||
| IDENTITYCENTER_EXPLORER, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrote this because the other function was using isCredentialSSO would always return IAM, even in cases where it should be IAM_IDC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other function is for the getting started auth which contains a dialog that accepts a session name.
Where does this function determine the credential type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that there was a CredentialType enum attached to the selected credentials so I thought I could use that. If the credentialType is an SsoProfile, does that not mean it is part of an IDC session?