Skip to content

Commit

Permalink
Send addConnection telemetry on builder id login (#4579)
Browse files Browse the repository at this point in the history
Send addConnection telemetry on builder id login
  • Loading branch information
wularr authored Jun 14, 2024
1 parent d09a609 commit 11c88e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ sealed interface Login {
data class BuilderId(
val scopes: List<String>,
val onPendingToken: (InteractiveBearerTokenProvider) -> Unit,
val onError: (Exception) -> Unit
val onError: (Exception) -> Unit,
val onSuccess: () -> Unit
) : Login {
override val id: CredentialSourceId = CredentialSourceId.AwsId

fun loginBuilderId(project: Project): Boolean {
loginSso(project, SONO_URL, SONO_REGION, scopes, onPendingToken, onError)
loginSso(project, SONO_URL, SONO_REGION, scopes, onPendingToken, onError, onSuccess)
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ fun loginSso(
region: String,
requestedScopes: List<String>,
onPendingToken: (InteractiveBearerTokenProvider) -> Unit = {},
onError: (Exception) -> Unit = {}
onError: (Exception) -> Unit = {},
onSuccess: () -> Unit = {},
): AwsBearerTokenConnection? {
fun createAndAuthNewConnection(profile: AuthProfile): AwsBearerTokenConnection? {
val authManager = ToolkitAuthManager.getInstance()
Expand All @@ -121,6 +122,10 @@ fun loginSso(
null
}

if (connection != null) {
onSuccess()
}

ToolkitConnectionManager.getInstance(project).switchConnection(connection)
return connection
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.InteractiveBe
import software.aws.toolkits.jetbrains.core.credentials.ssoErrorMessageFromException
import software.aws.toolkits.jetbrains.utils.pollFor
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.AuthTelemetry
import software.aws.toolkits.telemetry.AwsTelemetry
import software.aws.toolkits.telemetry.CredentialSourceId
import software.aws.toolkits.telemetry.CredentialType
Expand Down Expand Up @@ -96,14 +97,21 @@ abstract class LoginBrowser(
credentialSourceId = CredentialSourceId.AwsId
)
}
loginWithBackgroundContext {
Login.BuilderId(scopes, onPendingToken, onError).loginBuilderId(project)
val onSuccess: () -> Unit = {
AwsTelemetry.loginWithBrowser(
project = null,
credentialStartUrl = SONO_URL,
result = Result.Succeeded,
credentialSourceId = CredentialSourceId.AwsId
)
AuthTelemetry.addConnection(
result = Result.Succeeded,
credentialSourceId = CredentialSourceId.AwsId
)
}

loginWithBackgroundContext {
Login.BuilderId(scopes, onPendingToken, onError, onSuccess).loginBuilderId(project)
}
}

Expand Down

0 comments on commit 11c88e1

Please sign in to comment.