Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -755,25 +755,6 @@
],
"passive": true
},
{
"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 @@ -16,6 +16,7 @@
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 @@ -238,10 +239,10 @@
fun emitUserState(project: Project) {
AuthTelemetry.userState(
project,
source = getStartupState().toString(),
authEnabledConnections = getEnabledConnections(project),
authScopes = getAuthScopes(project),

Check warning on line 243 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt#L243

Added line #L243 was not covered by tests
authStatus = getAuthStatus(project),
passive = true
source = getStartupState().toString()

Check warning on line 245 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt#L245

Added line #L245 was not covered by tests
)
}

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

Check warning on line 124 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#L124

Added line #L124 was not covered by tests
}
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)

Check warning on line 129 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#L129

Added line #L129 was not covered by tests
}
}

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 All @@ -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> {
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<Any>()

Check warning on line 63 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#L63

Added line #L63 was not covered by tests

val explorerConnection = checkIamProfileByCredentialType(project)

Check warning on line 65 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#L65

Added line #L65 was not covered by tests
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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L67 was not covered by tests
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L70 - L72 were not covered by tests
)

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L75 - L77 were not covered by tests
)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L80 was not covered by tests
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L84 was not covered by tests

fun getStartupState(): StartUpState {
val hasStartedToolkitBefore = tryOrNull {
getPersistentStateComponentStorageLocation(AwsSettings::class.java)?.exists()
Expand All @@ -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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L103 was not covered by tests
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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L106 - L107 were not covered by tests
) {
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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L117 - L118 were not covered by tests
}
} 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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L131 was not covered by tests
}
}

Check warning on line 133 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#L133

Added line #L133 was not covered by tests

enum class AuthFormId {
IAMCREDENTIALS_EXPLORER,
IDENTITYCENTER_EXPLORER,
Expand Down
Loading