-
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 12 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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import com.intellij.openapi.project.Project | ||
| import com.intellij.ui.dsl.builder.Panel | ||
| import software.aws.toolkits.core.credentials.CredentialIdentifier | ||
| import software.aws.toolkits.core.credentials.CredentialType | ||
| import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection | ||
| import software.aws.toolkits.jetbrains.core.credentials.AwsConnectionManager | ||
| import software.aws.toolkits.jetbrains.core.credentials.ConnectionState | ||
|
|
@@ -115,6 +116,20 @@ | |
| } | ||
| } | ||
|
|
||
| fun checkIamProfileByCredentialType(project: Project): ActiveConnection { | ||
| val currConn = AwsConnectionManager.getInstance(project).selectedCredentialIdentifier ?: return ActiveConnection.NotConnected | ||
| val invalidConnection = AwsConnectionManager.getInstance(project).connectionState.let { it.isTerminal && it !is ConnectionState.ValidConnection } | ||
| val connectionType = when (currConn.credentialType) { | ||
| CredentialType.SsoProfile -> ActiveConnectionType.IAM_IDC | ||
| else -> ActiveConnectionType.IAM | ||
| } | ||
| return if (invalidConnection) { | ||
| ActiveConnection.ExpiredIam(connectionType = connectionType, activeConnectionIam = currConn) | ||
|
Check warning on line 127 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedPanelUtils.kt
|
||
| } else { | ||
| ActiveConnection.ValidIam(connectionType = connectionType, activeConnectionIam = currConn) | ||
| } | ||
| } | ||
|
|
||
|
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. 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 commentThe 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. 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. 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? |
||
| /** | ||
| * Finds the first valid [ActiveConnection] and returns it. | ||
| * | ||
|
|
@@ -146,6 +161,7 @@ | |
| return result | ||
| } | ||
|
|
||
| @Deprecated("Does not work for current config file setup. Old versions still utilize this logic.") | ||
| fun isCredentialSso(providerId: String): ActiveConnectionType { | ||
| val profileName = providerId.split("-").first() | ||
| val ssoSessionIds = CredentialManager.getInstance().getSsoSessionIdentifiers().map { | ||
|
|
||
| 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 | ||
|
|
@@ -70,6 +71,36 @@ | |
| 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<String>() | ||
|
|
||
| fun addScopes(connection: ActiveConnection) { | ||
| if (connection !is ActiveConnection.NotConnected) { | ||
| val connectionScopes = connection.activeConnectionBearer?.scopes | ||
| if (connectionScopes != null) { | ||
| scopes.addAll(connectionScopes) | ||
|
Check warning on line 82 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| val explorerConnection = checkIamProfileByCredentialType(project) | ||
| if (explorerConnection !is ActiveConnection.NotConnected && explorerConnection.connectionType == ActiveConnectionType.IAM_IDC) { | ||
| scopes.add(IDENTITY_CENTER_ROLE_ACCESS_SCOPE) | ||
|
Check warning on line 89 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt
|
||
| } | ||
|
|
||
| val codeCatalystConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODECATALYST) | ||
| addScopes(codeCatalystConnection) | ||
|
|
||
| val qConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.Q) | ||
| addScopes(qConnection) | ||
|
|
||
| return scopes | ||
| } | ||
|
|
||
| fun getAuthScopes(project: Project?): String = | ||
| getAuthScopesForTelemetry(project).joinToString(",") | ||
|
|
||
| fun getStartupState(): StartUpState { | ||
| val hasStartedToolkitBefore = tryOrNull { | ||
| getPersistentStateComponentStorageLocation(AwsSettings::class.java)?.exists() | ||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.