@@ -23,79 +23,61 @@ fun getConnectionCount(): Long {
2323
2424fun getEnabledConnectionsForTelemetry (project : Project ? ): Set <AuthFormId > {
2525 project ? : return emptySet()
26- val enabledConnections = mutableSetOf<AuthFormId >()
27-
28- val explorerConnection = checkIamConnectionValidity(project)
29- if (explorerConnection !is ActiveConnection .NotConnected ) {
30- if (explorerConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
31- enabledConnections.add(AuthFormId .IDENTITYCENTER_EXPLORER )
32- } else {
33- enabledConnections.add(
34- AuthFormId .IAMCREDENTIALS_EXPLORER
35- )
36- }
37- }
38- val codeCatalystConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODECATALYST )
39- if (codeCatalystConnection !is ActiveConnection .NotConnected ) {
40- if (codeCatalystConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
41- enabledConnections.add(AuthFormId .IDENTITYCENTER_CODECATALYST )
42- } else {
43- enabledConnections.add(AuthFormId .BUILDERID_CODECATALYST )
44- }
45- }
46-
47- val codeWhispererConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODEWHISPERER )
48- if (codeWhispererConnection !is ActiveConnection .NotConnected ) {
49- if (codeWhispererConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
50- enabledConnections.add(AuthFormId .IDENTITYCENTER_CODEWHISPERER )
51- } else {
52- enabledConnections.add(
53- AuthFormId .BUILDERID_CODEWHISPERER
54- )
55- }
56- }
57-
58- val qConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .Q )
59- if (qConnection !is ActiveConnection .NotConnected ) {
60- if (qConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
61- enabledConnections.add(AuthFormId .IDENTITYCENTER_Q )
62- } else {
63- enabledConnections.add(
64- AuthFormId .BUILDERID_Q
65- )
66- }
67- }
68- return enabledConnections
26+ val enabledConnections = mutableSetOf<Any >()
27+
28+ addConnectionInfoToSet(
29+ checkIamConnectionValidity(project),
30+ enabledConnections,
31+ AuthFormId .IDENTITYCENTER_EXPLORER ,
32+ AuthFormId .IAMCREDENTIALS_EXPLORER
33+ )
34+
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 }
6956}
7057
7158fun getEnabledConnections (project : Project ? ): String =
7259 getEnabledConnectionsForTelemetry(project).joinToString(" ," )
7360
7461fun getAuthScopesForTelemetry (project : Project ? ): Set <String > {
7562 project ? : return emptySet()
76- val scopes = mutableSetOf<String >()
77-
78- fun addScopes (connection : ActiveConnection ) {
79- if (connection !is ActiveConnection .NotConnected ) {
80- val connectionScopes = connection.activeConnectionBearer?.scopes
81- if (connectionScopes != null ) {
82- scopes.addAll(connectionScopes)
83- }
84- }
85- }
63+ val scopes = mutableSetOf<Any >()
8664
8765 val explorerConnection = checkIamProfileByCredentialType(project)
8866 if (explorerConnection !is ActiveConnection .NotConnected && explorerConnection.connectionType == ActiveConnectionType .IAM_IDC ) {
8967 scopes.add(IDENTITY_CENTER_ROLE_ACCESS_SCOPE )
9068 }
9169
92- val codeCatalystConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODECATALYST )
93- addScopes(codeCatalystConnection)
70+ addConnectionInfoToSet(
71+ checkBearerConnectionValidity(project, BearerTokenFeatureSet .CODECATALYST ),
72+ dataSet = scopes
73+ )
9474
95- val qConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet .Q )
96- addScopes(qConnection)
75+ addConnectionInfoToSet(
76+ checkBearerConnectionValidity(project, BearerTokenFeatureSet .Q ),
77+ dataSet = scopes
78+ )
9779
98- return scopes
80+ return scopes.mapTo( mutableSetOf ()) { it as String }
9981}
10082
10183fun getAuthScopes (project : Project ? ): String =
@@ -118,6 +100,38 @@ fun getAuthStatus(project: Project) = when (checkConnectionValidity(project)) {
118100 else -> AuthStatus .NotConnected
119101}
120102
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+
121135enum class AuthFormId {
122136 IAMCREDENTIALS_EXPLORER ,
123137 IDENTITYCENTER_EXPLORER ,
0 commit comments