Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f157c53
add authScopes to emitUserState telemetry
samgst-amazon Oct 7, 2024
f0d455d
add authScopes to emitUserState telemetry
samgst-amazon Oct 7, 2024
924a2b0
Replace userState function with direct TelemetryService record functi…
samgst-amazon Oct 7, 2024
4512625
add value parameter
samgst-amazon Oct 7, 2024
a4db555
fix whitespace
samgst-amazon Oct 7, 2024
4e1af21
Update plugins/core/jetbrains-community/src/software/aws/toolkits/jet…
samgst-amazon Oct 8, 2024
df30b58
Check current explorerConnection for scopes only
samgst-amazon Oct 15, 2024
2d053c5
Add function to grab scopes from each activeConnection used that is c…
samgst-amazon Oct 16, 2024
13c8cd0
remove TelemetryOverride definition and use common's telemetry functi…
samgst-amazon Oct 18, 2024
d05315f
remove unused imports
samgst-amazon Oct 18, 2024
744a2d3
Change the way explorer connection scope is checked
samgst-amazon Oct 18, 2024
098fa1d
remove check for CodeWhispererConnection: merged into qConnection & q…
samgst-amazon Oct 21, 2024
e6082fe
add common logic to one function
samgst-amazon Nov 1, 2024
214f4d8
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 4, 2024
e3e4838
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 4, 2024
5f780a1
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 5, 2024
1404bb1
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 6, 2024
82708b7
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 7, 2024
3ade8d8
Update telemetryOverride.json
samgst-amazon Nov 7, 2024
0858d1b
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This comment was marked as outdated.

Original file line number Diff line number Diff line change
Expand Up @@ -749,25 +749,6 @@
}
]
},
{
"name": "auth_userState",
"description": "The state of the user's authentication.",
"metadata": [
{
"type": "source",
"required": true
},
{
"type": "authStatus",
"required": true
},
{
"type": "authEnabledConnections",
"required": true
}
],
"passive": true
},
{
"name": "webview_amazonqSignInOpened",
"description": "Called when a Amazon Q sign in webview is opened.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
import software.aws.toolkits.jetbrains.core.credentials.reauthConnectionIfNeeded
import software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.SourceOfEntry
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getAuthScopes
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getAuthStatus
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getConnectionCount
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getEnabledConnections
Expand Down Expand Up @@ -231,10 +232,10 @@ fun reauthenticateWithQ(project: Project) {
fun emitUserState(project: Project) {
AuthTelemetry.userState(
project,
source = getStartupState().toString(),
authEnabledConnections = getEnabledConnections(project),
authScopes = getAuthScopes(project),
authStatus = getAuthStatus(project),
passive = true
source = getStartupState().toString()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedPanelUtils.kt#L127

Added line #L127 was not covered by tests
} else {
ActiveConnection.ValidIam(connectionType = connectionType, activeConnectionIam = currConn)
}
}

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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?

/**
* Finds the first valid [ActiveConnection] and returns it.
*
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,6 +71,36 @@
fun getEnabledConnections(project: Project?): String =
getEnabledConnectionsForTelemetry(project).joinToString(",")

fun getAuthScopesForTelemetry(project: Project?): Set<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The 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

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt#L82

Added line #L82 was not covered by tests
}
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt#L89

Added line #L89 was not covered by tests
}

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()
Expand Down
Loading