From c2835af919727d12b4ad3c432418f95c4fe4d17c Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:33:42 +0530 Subject: [PATCH 01/10] unique-id --- internal/commands/auth.go | 8 ++++ internal/commands/telemetry.go | 5 ++- internal/params/envs.go | 1 + internal/params/keys.go | 1 + internal/wrappers/client.go | 73 +++++++++++++++++++++++++++++--- internal/wrappers/client_test.go | 2 +- internal/wrappers/telemetry.go | 1 + 7 files changed, 83 insertions(+), 8 deletions(-) diff --git a/internal/commands/auth.go b/internal/commands/auth.go index 832fa66bc..c223a9352 100644 --- a/internal/commands/auth.go +++ b/internal/commands/auth.go @@ -5,6 +5,7 @@ import ( "log" "github.com/MakeNowJust/heredoc" + "github.com/checkmarx/ast-cli/internal/logger" "github.com/checkmarx/ast-cli/internal/params" "github.com/checkmarx/ast-cli/internal/wrappers" "github.com/google/uuid" @@ -118,6 +119,13 @@ func NewAuthCommand(authWrapper wrappers.AuthWrapper) *cobra.Command { func validLogin() func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { + defer func() { + logger.PrintIfVerbose("Calling GetUniqueId func") + uniqueId := wrappers.GetUniqueId() + if uniqueId != "" { + logger.PrintIfVerbose("Set unique id: " + uniqueId) + } + }() clientID := viper.GetString(params.AccessKeyIDConfigKey) clientSecret := viper.GetString(params.AccessKeySecretConfigKey) apiKey := viper.GetString(params.AstAPIKey) diff --git a/internal/commands/telemetry.go b/internal/commands/telemetry.go index 3b5bbefe0..5881ec1b5 100644 --- a/internal/commands/telemetry.go +++ b/internal/commands/telemetry.go @@ -2,6 +2,7 @@ package commands import ( "github.com/MakeNowJust/heredoc" + "github.com/checkmarx/ast-cli/internal/logger" "github.com/checkmarx/ast-cli/internal/params" "github.com/checkmarx/ast-cli/internal/wrappers" "github.com/pkg/errors" @@ -58,7 +59,8 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm scanType, _ := cmd.Flags().GetString("scan-type") status, _ := cmd.Flags().GetString("status") totalCount, _ := cmd.Flags().GetInt("total-count") - + uniqueId := wrappers.GetUniqueId() + logger.PrintIfVerbose("unique id: " + uniqueId) err := telemetryWrapper.SendAIDataToLog(&wrappers.DataForAITelemetry{ AIProvider: aiProvider, ProblemSeverity: problemSeverity, @@ -69,6 +71,7 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm ScanType: scanType, Status: status, TotalCount: totalCount, + UniqueId: uniqueId, }) if err != nil { diff --git a/internal/params/envs.go b/internal/params/envs.go index 19dc0f3c7..39b1ad4d4 100644 --- a/internal/params/envs.go +++ b/internal/params/envs.go @@ -80,4 +80,5 @@ const ( RiskManagementPathEnv = "CX_RISK_MANAGEMENT_PATH" ConfigFilePathEnv = "CX_CONFIG_FILE_PATH" RealtimeScannerPathEnv = "CX_REALTIME_SCANNER_PATH" + UniqueIdEnv = "CX_UNIQUE_ID" ) diff --git a/internal/params/keys.go b/internal/params/keys.go index 839b13e53..680b19b8f 100644 --- a/internal/params/keys.go +++ b/internal/params/keys.go @@ -79,4 +79,5 @@ var ( RiskManagementPathKey = strings.ToLower(RiskManagementPathEnv) ConfigFilePathKey = strings.ToLower(ConfigFilePathEnv) RealtimeScannerPathKey = strings.ToLower(RealtimeScannerPathEnv) + UniqueIdConfigKey = strings.ToLower(UniqueIdEnv) ) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 032eb4e4b..3bb3cab07 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -12,6 +12,7 @@ import ( "net/http/httptrace" "net/url" "os" + "os/user" "runtime" "strings" "sync" @@ -20,6 +21,7 @@ import ( applicationErrors "github.com/checkmarx/ast-cli/internal/constants/errors" "github.com/checkmarx/ast-cli/internal/logger" "github.com/golang-jwt/jwt/v5" + "github.com/google/uuid" "github.com/pkg/errors" "github.com/spf13/viper" @@ -126,12 +128,21 @@ func retryHTTPForIAMRequest(requestFunc func() (*http.Response, error), retries return nil, err } -func setAgentNameAndOrigin(req *http.Request) { +func setAgentNameAndOrigin(req *http.Request, isAuth bool) { agentStr := viper.GetString(commonParams.AgentNameKey) + "/" + commonParams.Version req.Header.Set("User-Agent", agentStr) originStr := viper.GetString(commonParams.OriginKey) req.Header.Set("Cx-Origin", originStr) + logger.PrintIfVerbose("getting unique id") + + if !isAuth { + uniqueId := GetUniqueId() + if uniqueId != "" { + req.Header.Set("UniqueId", uniqueId) + logger.PrintIfVerbose("unique id: " + uniqueId) + } + } } func GetClient(timeout uint) *http.Client { @@ -375,7 +386,7 @@ func SendHTTPRequestByFullURLContentLength( req.ContentLength = contentLength } client := GetClient(timeout) - setAgentNameAndOrigin(req) + setAgentNameAndOrigin(req, false) if auth { enrichWithOath2Credentials(req, accessToken, bearerFormat) } @@ -427,7 +438,7 @@ func SendHTTPRequestPasswordAuth(method string, body io.Reader, timeout uint, us } req, err := http.NewRequest(method, u, body) client := GetClient(timeout) - setAgentNameAndOrigin(req) + setAgentNameAndOrigin(req, true) if err != nil { return nil, err } @@ -464,7 +475,7 @@ func HTTPRequestWithQueryParams( } req, err := http.NewRequest(method, u, body) client := GetClient(timeout) - setAgentNameAndOrigin(req) + setAgentNameAndOrigin(req, false) if err != nil { return nil, err } @@ -512,7 +523,7 @@ func SendHTTPRequestWithJSONContentType(method, path string, body io.Reader, aut } req, err := http.NewRequest(method, fullURL, body) client := GetClient(timeout) - setAgentNameAndOrigin(req) + setAgentNameAndOrigin(req, false) req.Header.Add("Content-Type", jsonContentType) if err != nil { return nil, err @@ -645,7 +656,7 @@ func writeCredentialsToCache(accessToken string) { func getNewToken(credentialsPayload, authServerURI string) (string, error) { payload := strings.NewReader(credentialsPayload) req, err := http.NewRequest(http.MethodPost, authServerURI, payload) - setAgentNameAndOrigin(req) + setAgentNameAndOrigin(req, true) if err != nil { return "", err } @@ -972,3 +983,53 @@ func extractAZPFromToken(astToken string) (string, error) { } return azp, nil } + +func GetUniqueId() string { + isAllowed := false + accessToken, err := GetAccessToken() + if err != nil { + logger.PrintIfVerbose("Failed to get access token") + return "" + } + parser := jwt.NewParser(jwt.WithoutClaimsValidation()) + token, _, err := parser.ParseUnverified(accessToken, jwt.MapClaims{}) + if err != nil { + logger.PrintIfVerbose("Failed to parse JWT token " + err.Error()) + return "" + } + claims, ok := token.Claims.(jwt.MapClaims) + if !ok { + logger.PrintIfVerbose("Failed to get JWT claims") + return "" + } + for _, engine := range claims["ast-license"].(map[string]interface{})["LicenseData"].(map[string]interface{})["allowedEngines"].([]interface{}) { + if strings.EqualFold(engine.(string), "Checkmarx One Assist") { + isAllowed = true + break + } + } + + if !isAllowed { + logger.PrintIfVerbose("User does not not have permission to standalone dev asists feature") + return "" + } + uniqueId := viper.GetString(commonParams.UniqueIdConfigKey) + if uniqueId != "" { + return uniqueId + } + logger.PrintIfVerbose("Generating new unique id") + currentUser, err := user.Current() + if err != nil { + logger.PrintIfVerbose("Failed to get user: " + err.Error()) + return "" + } + uniqueId = uuid.New().String() + currentUser.Username + logger.PrintIfVerbose("Unique id: " + uniqueId) + viper.Set(commonParams.UniqueIdConfigKey, uniqueId) + err = viper.WriteConfig() + if err != nil { + logger.PrintIfVerbose("Failed to write config: " + err.Error()) + return "" + } + return uniqueId +} diff --git a/internal/wrappers/client_test.go b/internal/wrappers/client_test.go index b8a45f0d1..e75e9e9b0 100644 --- a/internal/wrappers/client_test.go +++ b/internal/wrappers/client_test.go @@ -192,7 +192,7 @@ func TestSetAgentNameAndOrigin(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://example.com", nil) - setAgentNameAndOrigin(req) + setAgentNameAndOrigin(req, false) userAgent := req.Header.Get("User-Agent") origin := req.Header.Get("origin") diff --git a/internal/wrappers/telemetry.go b/internal/wrappers/telemetry.go index 58e8a5b73..00e464c36 100644 --- a/internal/wrappers/telemetry.go +++ b/internal/wrappers/telemetry.go @@ -10,6 +10,7 @@ type DataForAITelemetry struct { ScanType string `json:"scanType"` Status string `json:"status"` TotalCount int `json:"totalCount"` + UniqueId string `json:"uniqueId"` } type TelemetryWrapper interface { From 07248afd49429cd14a138a46bf5a7609c1691447 Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Thu, 16 Oct 2025 16:18:20 +0530 Subject: [PATCH 02/10] config-file-save --- internal/commands/auth.go | 6 +++--- internal/commands/telemetry.go | 4 ++-- internal/params/envs.go | 2 +- internal/params/keys.go | 2 +- internal/wrappers/client.go | 28 +++++++++++++++------------- internal/wrappers/telemetry.go | 2 +- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/internal/commands/auth.go b/internal/commands/auth.go index c223a9352..7d11003b6 100644 --- a/internal/commands/auth.go +++ b/internal/commands/auth.go @@ -121,9 +121,9 @@ func validLogin() func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { defer func() { logger.PrintIfVerbose("Calling GetUniqueId func") - uniqueId := wrappers.GetUniqueId() - if uniqueId != "" { - logger.PrintIfVerbose("Set unique id: " + uniqueId) + uniqueID := wrappers.GetUniqueID() + if uniqueID != "" { + logger.PrintIfVerbose("Set unique id: " + uniqueID) } }() clientID := viper.GetString(params.AccessKeyIDConfigKey) diff --git a/internal/commands/telemetry.go b/internal/commands/telemetry.go index 5881ec1b5..cc089397b 100644 --- a/internal/commands/telemetry.go +++ b/internal/commands/telemetry.go @@ -59,7 +59,7 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm scanType, _ := cmd.Flags().GetString("scan-type") status, _ := cmd.Flags().GetString("status") totalCount, _ := cmd.Flags().GetInt("total-count") - uniqueId := wrappers.GetUniqueId() + uniqueId := wrappers.GetUniqueID() logger.PrintIfVerbose("unique id: " + uniqueId) err := telemetryWrapper.SendAIDataToLog(&wrappers.DataForAITelemetry{ AIProvider: aiProvider, @@ -71,7 +71,7 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm ScanType: scanType, Status: status, TotalCount: totalCount, - UniqueId: uniqueId, + UniqueID: uniqueId, }) if err != nil { diff --git a/internal/params/envs.go b/internal/params/envs.go index 39b1ad4d4..51d29f632 100644 --- a/internal/params/envs.go +++ b/internal/params/envs.go @@ -80,5 +80,5 @@ const ( RiskManagementPathEnv = "CX_RISK_MANAGEMENT_PATH" ConfigFilePathEnv = "CX_CONFIG_FILE_PATH" RealtimeScannerPathEnv = "CX_REALTIME_SCANNER_PATH" - UniqueIdEnv = "CX_UNIQUE_ID" + UniqueIDEnv = "CX_UNIQUE_ID" ) diff --git a/internal/params/keys.go b/internal/params/keys.go index 680b19b8f..ef7bd8156 100644 --- a/internal/params/keys.go +++ b/internal/params/keys.go @@ -79,5 +79,5 @@ var ( RiskManagementPathKey = strings.ToLower(RiskManagementPathEnv) ConfigFilePathKey = strings.ToLower(ConfigFilePathEnv) RealtimeScannerPathKey = strings.ToLower(RealtimeScannerPathEnv) - UniqueIdConfigKey = strings.ToLower(UniqueIdEnv) + UniqueIDConfigKey = strings.ToLower(UniqueIDEnv) ) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 3bb3cab07..ce7f92151 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -27,6 +27,7 @@ import ( "github.com/spf13/viper" commonParams "github.com/checkmarx/ast-cli/internal/params" + "github.com/checkmarx/ast-cli/internal/wrappers/configuration" "github.com/checkmarx/ast-cli/internal/wrappers/kerberos" "github.com/checkmarx/ast-cli/internal/wrappers/ntlm" ) @@ -137,10 +138,10 @@ func setAgentNameAndOrigin(req *http.Request, isAuth bool) { logger.PrintIfVerbose("getting unique id") if !isAuth { - uniqueId := GetUniqueId() - if uniqueId != "" { - req.Header.Set("UniqueId", uniqueId) - logger.PrintIfVerbose("unique id: " + uniqueId) + uniqueID := GetUniqueID() + if uniqueID != "" { + req.Header.Set("UniqueId", uniqueID) + logger.PrintIfVerbose("unique id: " + uniqueID) } } } @@ -984,7 +985,7 @@ func extractAZPFromToken(astToken string) (string, error) { return azp, nil } -func GetUniqueId() string { +func GetUniqueID() string { isAllowed := false accessToken, err := GetAccessToken() if err != nil { @@ -1013,9 +1014,9 @@ func GetUniqueId() string { logger.PrintIfVerbose("User does not not have permission to standalone dev asists feature") return "" } - uniqueId := viper.GetString(commonParams.UniqueIdConfigKey) - if uniqueId != "" { - return uniqueId + uniqueID := viper.GetString(commonParams.UniqueIDConfigKey) + if uniqueID != "" { + return uniqueID } logger.PrintIfVerbose("Generating new unique id") currentUser, err := user.Current() @@ -1023,13 +1024,14 @@ func GetUniqueId() string { logger.PrintIfVerbose("Failed to get user: " + err.Error()) return "" } - uniqueId = uuid.New().String() + currentUser.Username - logger.PrintIfVerbose("Unique id: " + uniqueId) - viper.Set(commonParams.UniqueIdConfigKey, uniqueId) - err = viper.WriteConfig() + uniqueID = uuid.New().String() + "_" + currentUser.Username + logger.PrintIfVerbose("Unique id: " + uniqueID) + viper.Set(commonParams.UniqueIDConfigKey, uniqueID) + configFilePath, _ := configuration.GetConfigFilePath() + err = configuration.SafeWriteSingleConfigKeyString(configFilePath, commonParams.UniqueIDConfigKey, uniqueID) if err != nil { logger.PrintIfVerbose("Failed to write config: " + err.Error()) return "" } - return uniqueId + return uniqueID } diff --git a/internal/wrappers/telemetry.go b/internal/wrappers/telemetry.go index 00e464c36..b3e58781f 100644 --- a/internal/wrappers/telemetry.go +++ b/internal/wrappers/telemetry.go @@ -10,7 +10,7 @@ type DataForAITelemetry struct { ScanType string `json:"scanType"` Status string `json:"status"` TotalCount int `json:"totalCount"` - UniqueId string `json:"uniqueId"` + UniqueID string `json:"uniqueId"` } type TelemetryWrapper interface { From d996c7ae68b92b43601c12663f5b67eb142cf7cc Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Fri, 17 Oct 2025 10:46:37 +0530 Subject: [PATCH 03/10] unique-id --- internal/commands/telemetry.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/commands/telemetry.go b/internal/commands/telemetry.go index cc089397b..cbf3d1f3a 100644 --- a/internal/commands/telemetry.go +++ b/internal/commands/telemetry.go @@ -59,8 +59,8 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm scanType, _ := cmd.Flags().GetString("scan-type") status, _ := cmd.Flags().GetString("status") totalCount, _ := cmd.Flags().GetInt("total-count") - uniqueId := wrappers.GetUniqueID() - logger.PrintIfVerbose("unique id: " + uniqueId) + uniqueID := wrappers.GetUniqueID() + logger.PrintIfVerbose("unique id: " + uniqueID) err := telemetryWrapper.SendAIDataToLog(&wrappers.DataForAITelemetry{ AIProvider: aiProvider, ProblemSeverity: problemSeverity, @@ -71,7 +71,7 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm ScanType: scanType, Status: status, TotalCount: totalCount, - UniqueID: uniqueId, + UniqueID: uniqueID, }) if err != nil { From 37efa8354e078c7c13e86307cf276f38cffa51a6 Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:30:46 +0530 Subject: [PATCH 04/10] license-name-corrected --- internal/wrappers/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index ce7f92151..bcbd72cb5 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -1004,7 +1004,7 @@ func GetUniqueID() string { return "" } for _, engine := range claims["ast-license"].(map[string]interface{})["LicenseData"].(map[string]interface{})["allowedEngines"].([]interface{}) { - if strings.EqualFold(engine.(string), "Checkmarx One Assist") { + if strings.EqualFold(engine.(string), "Checkmarx Developer Assist") { isAllowed = true break } From 0051eb6345273cb283deb665bfb5b0dd59041fb3 Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Fri, 24 Oct 2025 11:36:37 +0530 Subject: [PATCH 05/10] interface-conversion-check --- internal/wrappers/client.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index bcbd72cb5..1cd68e4c6 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -986,6 +986,7 @@ func extractAZPFromToken(astToken string) (string, error) { } func GetUniqueID() string { + var uniqueID string isAllowed := false accessToken, err := GetAccessToken() if err != nil { @@ -1003,8 +1004,31 @@ func GetUniqueID() string { logger.PrintIfVerbose("Failed to get JWT claims") return "" } - for _, engine := range claims["ast-license"].(map[string]interface{})["LicenseData"].(map[string]interface{})["allowedEngines"].([]interface{}) { - if strings.EqualFold(engine.(string), "Checkmarx Developer Assist") { + + astLicense, ok := claims["ast-license"].(map[string]interface{}) + if !ok { + logger.PrintIfVerbose("Failed to get ast-license from claims") + return "" + } + + licenseData, ok := astLicense["LicenseData"].(map[string]interface{}) + if !ok { + logger.PrintIfVerbose("Failed to get LicenseData from ast-license") + return "" + } + + allowedEngines, ok := licenseData["allowedEngines"].([]interface{}) + if !ok { + logger.PrintIfVerbose("Failed to get allowedEngines from LicenseData") + return "" + } + + for _, engine := range allowedEngines { + engineStr, ok := engine.(string) + if !ok { + continue + } + if strings.EqualFold(engineStr, "Checkmarx Developer Assist") { isAllowed = true break } @@ -1014,7 +1038,7 @@ func GetUniqueID() string { logger.PrintIfVerbose("User does not not have permission to standalone dev asists feature") return "" } - uniqueID := viper.GetString(commonParams.UniqueIDConfigKey) + uniqueID = viper.GetString(commonParams.UniqueIDConfigKey) if uniqueID != "" { return uniqueID } From 0dda5b5c222aee888087ae96cb459c16b843e128 Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:18:44 +0530 Subject: [PATCH 06/10] removing-domain-from-username-if-exists --- internal/wrappers/client.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 1cd68e4c6..d10702d1e 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -1028,7 +1028,7 @@ func GetUniqueID() string { if !ok { continue } - if strings.EqualFold(engineStr, "Checkmarx Developer Assist") { + if strings.EqualFold(engineStr, "Checkmarx One Assist") { isAllowed = true break } @@ -1048,7 +1048,14 @@ func GetUniqueID() string { logger.PrintIfVerbose("Failed to get user: " + err.Error()) return "" } - uniqueID = uuid.New().String() + "_" + currentUser.Username + username := currentUser.Username + username = strings.TrimSpace(username) + logger.PrintIfVerbose("Username to be used for unique id: " + username) + if strings.Contains(username, "\\") { + username = strings.Split(username, "\\")[1] + } + uniqueID = uuid.New().String() + "_" + username + logger.PrintIfVerbose("Unique id: " + uniqueID) viper.Set(commonParams.UniqueIDConfigKey, uniqueID) configFilePath, _ := configuration.GetConfigFilePath() From ab57cb27b05dc2f73d79c4f2a46fefea9b3eb2ec Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:55:26 +0530 Subject: [PATCH 07/10] using-standalone-license --- internal/wrappers/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index d10702d1e..213188be4 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -1028,7 +1028,7 @@ func GetUniqueID() string { if !ok { continue } - if strings.EqualFold(engineStr, "Checkmarx One Assist") { + if strings.EqualFold(engineStr, "Checkmarx Developer Assist") { isAllowed = true break } From 6bf553d3ad791c8d9847c2518bb912c396f81861 Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Mon, 27 Oct 2025 14:54:20 +0530 Subject: [PATCH 08/10] calling-telemetry-api-post-valid-login --- internal/commands/auth.go | 12 +++++++++--- internal/commands/root.go | 2 +- internal/wrappers/client.go | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/commands/auth.go b/internal/commands/auth.go index 7d11003b6..bc9b2f7d0 100644 --- a/internal/commands/auth.go +++ b/internal/commands/auth.go @@ -39,7 +39,7 @@ type ClientCreated struct { Secret string `json:"secret"` } -func NewAuthCommand(authWrapper wrappers.AuthWrapper) *cobra.Command { +func NewAuthCommand(authWrapper wrappers.AuthWrapper, telemetryWrapper wrappers.TelemetryWrapper) *cobra.Command { authCmd := &cobra.Command{ Use: "auth", Short: "Validate authentication and create OAuth2 credentials", @@ -111,19 +111,25 @@ func NewAuthCommand(authWrapper wrappers.AuthWrapper) *cobra.Command { `, ), }, - RunE: validLogin(), + RunE: validLogin(telemetryWrapper), } authCmd.AddCommand(createClientCmd, validLoginCmd) return authCmd } -func validLogin() func(cmd *cobra.Command, args []string) error { +func validLogin(telemetryWrapper wrappers.TelemetryWrapper) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { defer func() { logger.PrintIfVerbose("Calling GetUniqueId func") uniqueID := wrappers.GetUniqueID() if uniqueID != "" { logger.PrintIfVerbose("Set unique id: " + uniqueID) + err := telemetryWrapper.SendAIDataToLog(&wrappers.DataForAITelemetry{ + UniqueID: uniqueID, + }) + if err != nil { + logger.PrintIfVerbose("Failed to send telemetry data: " + err.Error()) + } } }() clientID := viper.GetString(params.AccessKeyIDConfigKey) diff --git a/internal/commands/root.go b/internal/commands/root.go index 9c56cb812..dc9587c52 100644 --- a/internal/commands/root.go +++ b/internal/commands/root.go @@ -205,7 +205,7 @@ func NewAstCLI( ) versionCmd := util.NewVersionCommand() - authCmd := NewAuthCommand(authWrapper) + authCmd := NewAuthCommand(authWrapper, telemetryWrapper) utilsCmd := util.NewUtilsCommand( gitHubWrapper, azureWrapper, diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index 213188be4..d10702d1e 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -1028,7 +1028,7 @@ func GetUniqueID() string { if !ok { continue } - if strings.EqualFold(engineStr, "Checkmarx Developer Assist") { + if strings.EqualFold(engineStr, "Checkmarx One Assist") { isAllowed = true break } From ba926262e4cf911c28a10dc185fd5815295d3708 Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Thu, 30 Oct 2025 12:17:57 +0530 Subject: [PATCH 09/10] post-login-setting-type-n-subtype-as-authentication --- internal/commands/auth.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/commands/auth.go b/internal/commands/auth.go index bc9b2f7d0..bdbdb06b1 100644 --- a/internal/commands/auth.go +++ b/internal/commands/auth.go @@ -126,6 +126,8 @@ func validLogin(telemetryWrapper wrappers.TelemetryWrapper) func(cmd *cobra.Comm logger.PrintIfVerbose("Set unique id: " + uniqueID) err := telemetryWrapper.SendAIDataToLog(&wrappers.DataForAITelemetry{ UniqueID: uniqueID, + Type: "authentication", + SubType: "authentication", }) if err != nil { logger.PrintIfVerbose("Failed to send telemetry data: " + err.Error()) From 46b368110c7df5c260367990ea2ea001d02cf269 Mon Sep 17 00:00:00 2001 From: Hitesh Madgulkar <212497904+cx-hitesh-madgulkar@users.noreply.github.com> Date: Fri, 31 Oct 2025 11:41:03 +0530 Subject: [PATCH 10/10] dev-done-using-developer-license --- internal/wrappers/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/wrappers/client.go b/internal/wrappers/client.go index d10702d1e..213188be4 100644 --- a/internal/wrappers/client.go +++ b/internal/wrappers/client.go @@ -1028,7 +1028,7 @@ func GetUniqueID() string { if !ok { continue } - if strings.EqualFold(engineStr, "Checkmarx One Assist") { + if strings.EqualFold(engineStr, "Checkmarx Developer Assist") { isAllowed = true break }