@@ -10,6 +10,7 @@ import software.aws.toolkits.core.utils.tryOrNull
1010import software.aws.toolkits.jetbrains.core.credentials.CredentialManager
1111import software.aws.toolkits.jetbrains.core.credentials.ToolkitAuthManager
1212import software.aws.toolkits.jetbrains.core.credentials.profiles.ProfileCredentialsIdentifierSso
13+ import software.aws.toolkits.jetbrains.core.credentials.sono.IDENTITY_CENTER_ROLE_ACCESS_SCOPE
1314import software.aws.toolkits.jetbrains.settings.AwsSettings
1415import software.aws.toolkits.telemetry.AuthStatus
1516import software.aws.toolkits.telemetry.StartUpState
@@ -22,54 +23,66 @@ fun getConnectionCount(): Long {
2223
2324fun getEnabledConnectionsForTelemetry (project : Project ? ): Set <AuthFormId > {
2425 project ? : return emptySet()
25- val enabledConnections = mutableSetOf<AuthFormId >()
26-
27- val explorerConnection = checkIamConnectionValidity(project)
28- if (explorerConnection !is ActiveConnection .NotConnected ) {
29- if (explorerConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
30- enabledConnections.add(AuthFormId .IDENTITYCENTER_EXPLORER )
31- } else {
32- enabledConnections.add(
33- AuthFormId .IAMCREDENTIALS_EXPLORER
34- )
35- }
36- }
37- val codeCatalystConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODECATALYST )
38- if (codeCatalystConnection !is ActiveConnection .NotConnected ) {
39- if (codeCatalystConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
40- enabledConnections.add(AuthFormId .IDENTITYCENTER_CODECATALYST )
41- } else {
42- enabledConnections.add(AuthFormId .BUILDERID_CODECATALYST )
43- }
44- }
26+ val enabledConnections = mutableSetOf<Any >()
4527
46- val codeWhispererConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODEWHISPERER )
47- if (codeWhispererConnection !is ActiveConnection .NotConnected ) {
48- if (codeWhispererConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
49- enabledConnections.add(AuthFormId .IDENTITYCENTER_CODEWHISPERER )
50- } else {
51- enabledConnections.add(
52- AuthFormId .BUILDERID_CODEWHISPERER
53- )
54- }
55- }
28+ addConnectionInfoToSet(
29+ checkIamConnectionValidity(project),
30+ enabledConnections,
31+ AuthFormId .IDENTITYCENTER_EXPLORER ,
32+ AuthFormId .IAMCREDENTIALS_EXPLORER
33+ )
5634
57- val qConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .Q )
58- if (qConnection !is ActiveConnection .NotConnected ) {
59- if (qConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
60- enabledConnections.add(AuthFormId .IDENTITYCENTER_Q )
61- } else {
62- enabledConnections.add(
63- AuthFormId .BUILDERID_Q
64- )
65- }
66- }
67- return enabledConnections
35+ addConnectionInfoToSet(
36+ checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODECATALYST ),
37+ enabledConnections,
38+ AuthFormId .IDENTITYCENTER_CODECATALYST ,
39+ AuthFormId .BUILDERID_CODECATALYST
40+ )
41+
42+ addConnectionInfoToSet(
43+ checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODEWHISPERER ),
44+ enabledConnections,
45+ AuthFormId .IDENTITYCENTER_CODEWHISPERER ,
46+ AuthFormId .BUILDERID_CODEWHISPERER
47+ )
48+
49+ addConnectionInfoToSet(
50+ checkBearerConnectionValidity(project, BearerTokenFeatureSet .Q ),
51+ enabledConnections,
52+ AuthFormId .IDENTITYCENTER_Q ,
53+ AuthFormId .BUILDERID_Q
54+ )
55+ return enabledConnections.mapTo(mutableSetOf ()) { it as AuthFormId }
6856}
6957
7058fun getEnabledConnections (project : Project ? ): String =
7159 getEnabledConnectionsForTelemetry(project).joinToString(" ," )
7260
61+ fun getAuthScopesForTelemetry (project : Project ? ): Set <String > {
62+ project ? : return emptySet()
63+ val scopes = mutableSetOf<Any >()
64+
65+ val explorerConnection = checkIamProfileByCredentialType(project)
66+ if (explorerConnection !is ActiveConnection .NotConnected && explorerConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
67+ scopes.add(IDENTITY_CENTER_ROLE_ACCESS_SCOPE )
68+ }
69+
70+ addConnectionInfoToSet(
71+ checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODECATALYST ),
72+ dataSet = scopes
73+ )
74+
75+ addConnectionInfoToSet(
76+ checkBearerConnectionValidity(project, BearerTokenFeatureSet .Q ),
77+ dataSet = scopes
78+ )
79+
80+ return scopes.mapTo(mutableSetOf ()) { it as String }
81+ }
82+
83+ fun getAuthScopes (project : Project ? ): String =
84+ getAuthScopesForTelemetry(project).joinToString(" ," )
85+
7386fun getStartupState (): StartUpState {
7487 val hasStartedToolkitBefore = tryOrNull {
7588 getPersistentStateComponentStorageLocation(AwsSettings ::class .java)?.exists()
@@ -87,6 +100,38 @@ fun getAuthStatus(project: Project) = when (checkConnectionValidity(project)) {
87100 else -> AuthStatus .NotConnected
88101}
89102
103+ fun addConnectionInfoToSet (
104+ activeConnection : ActiveConnection ,
105+ dataSet : MutableSet <Any >,
106+ idcConnection : AuthFormId ? = null,
107+ defaultConnection : AuthFormId ? = null,
108+ ) {
109+ if (activeConnection is ActiveConnection .NotConnected ) {
110+ return
111+ }
112+
113+ // add enabled connections
114+ when (activeConnection.connectionType) {
115+ ActiveConnectionType .IAM_IDC -> {
116+ idcConnection ?.let {
117+ dataSet.add(idcConnection)
118+ return
119+ }
120+ } else -> {
121+ defaultConnection?.let {
122+ dataSet.add(defaultConnection)
123+ return
124+ }
125+ }
126+ }
127+
128+ // add scopes
129+ val connectionScopes = activeConnection.activeConnectionBearer?.scopes
130+ if (! connectionScopes.isNullOrEmpty()) {
131+ dataSet.addAll(connectionScopes)
132+ }
133+ }
134+
90135enum class AuthFormId {
91136 IAMCREDENTIALS_EXPLORER ,
92137 IDENTITYCENTER_EXPLORER ,
0 commit comments