Skip to content

Commit 5597316

Browse files
Changes related to seat contributor (AST-115788) and Retrieve Checkmarx Dev Assist License details (AST-112336) (#1363)
1 parent e992c7f commit 5597316

File tree

16 files changed

+167
-41
lines changed

16 files changed

+167
-41
lines changed

internal/commands/auth.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66

77
"github.com/MakeNowJust/heredoc"
8+
"github.com/checkmarx/ast-cli/internal/logger"
89
"github.com/checkmarx/ast-cli/internal/params"
910
"github.com/checkmarx/ast-cli/internal/wrappers"
1011
"github.com/google/uuid"
@@ -38,7 +39,7 @@ type ClientCreated struct {
3839
Secret string `json:"secret"`
3940
}
4041

41-
func NewAuthCommand(authWrapper wrappers.AuthWrapper) *cobra.Command {
42+
func NewAuthCommand(authWrapper wrappers.AuthWrapper, telemetryWrapper wrappers.TelemetryWrapper) *cobra.Command {
4243
authCmd := &cobra.Command{
4344
Use: "auth",
4445
Short: "Validate authentication and create OAuth2 credentials",
@@ -110,13 +111,13 @@ func NewAuthCommand(authWrapper wrappers.AuthWrapper) *cobra.Command {
110111
`,
111112
),
112113
},
113-
RunE: validLogin(),
114+
RunE: validLogin(telemetryWrapper),
114115
}
115116
authCmd.AddCommand(createClientCmd, validLoginCmd)
116117
return authCmd
117118
}
118119

119-
func validLogin() func(cmd *cobra.Command, args []string) error {
120+
func validLogin(telemetryWrapper wrappers.TelemetryWrapper) func(cmd *cobra.Command, args []string) error {
120121
return func(cmd *cobra.Command, args []string) error {
121122
clientID := viper.GetString(params.AccessKeyIDConfigKey)
122123
clientSecret := viper.GetString(params.AccessKeySecretConfigKey)
@@ -125,6 +126,19 @@ func validLogin() func(cmd *cobra.Command, args []string) error {
125126
authWrapper := wrappers.NewAuthHTTPWrapper()
126127
authWrapper.SetPath(viper.GetString(params.ScansPathKey))
127128
err := authWrapper.ValidateLogin()
129+
130+
uniqueID := wrappers.GetUniqueID()
131+
if uniqueID != "" {
132+
telemetryErr := telemetryWrapper.SendAIDataToLog(&wrappers.DataForAITelemetry{
133+
UniqueID: uniqueID,
134+
Type: "authentication",
135+
SubType: "authentication",
136+
})
137+
if telemetryErr != nil {
138+
logger.PrintIfVerbose("Failed to send telemetry data: " + telemetryErr.Error())
139+
}
140+
}
141+
128142
if err != nil {
129143
return errors.Errorf("%s", err)
130144
}

internal/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func NewAstCLI(
205205
)
206206

207207
versionCmd := util.NewVersionCommand()
208-
authCmd := NewAuthCommand(authWrapper)
208+
authCmd := NewAuthCommand(authWrapper, telemetryWrapper)
209209
utilsCmd := util.NewUtilsCommand(
210210
gitHubWrapper,
211211
azureWrapper,

internal/commands/telemetry.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm
5858
scanType, _ := cmd.Flags().GetString("scan-type")
5959
status, _ := cmd.Flags().GetString("status")
6060
totalCount, _ := cmd.Flags().GetInt("total-count")
61-
61+
uniqueID := wrappers.GetUniqueID()
6262
err := telemetryWrapper.SendAIDataToLog(&wrappers.DataForAITelemetry{
6363
AIProvider: aiProvider,
6464
ProblemSeverity: problemSeverity,
@@ -69,6 +69,7 @@ func runTelemetryAI(telemetryWrapper wrappers.TelemetryWrapper) func(*cobra.Comm
6969
ScanType: scanType,
7070
Status: status,
7171
TotalCount: totalCount,
72+
UniqueID: uniqueID,
7273
})
7374

7475
if err != nil {

internal/commands/util/tenant.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/spf13/cobra"
1212
)
1313

14-
func NewTenantConfigurationCommand(wrapper wrappers.TenantConfigurationWrapper, jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) *cobra.Command {
14+
func NewTenantConfigurationCommand(wrapper wrappers.TenantConfigurationWrapper, jwtWrapper wrappers.JWTWrapper) *cobra.Command {
1515
cmd := &cobra.Command{
1616
Use: "tenant",
1717
Short: "Shows the tenant settings",
@@ -27,7 +27,7 @@ func NewTenantConfigurationCommand(wrapper wrappers.TenantConfigurationWrapper,
2727
`,
2828
),
2929
},
30-
RunE: runTenantCmd(wrapper, jwtWrapper, featureFlagsWrapper),
30+
RunE: runTenantCmd(wrapper, jwtWrapper),
3131
}
3232
cmd.PersistentFlags().String(
3333
params.FormatFlag,
@@ -40,7 +40,7 @@ func NewTenantConfigurationCommand(wrapper wrappers.TenantConfigurationWrapper,
4040
return cmd
4141
}
4242

43-
func runTenantCmd(wrapper wrappers.TenantConfigurationWrapper, jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) func(cmd *cobra.Command, args []string) error {
43+
func runTenantCmd(wrapper wrappers.TenantConfigurationWrapper, jwtWrapper wrappers.JWTWrapper) func(cmd *cobra.Command, args []string) error {
4444
return func(cmd *cobra.Command, args []string) error {
4545
tenantConfigurationResponse, errorModel, err := wrapper.GetTenantConfiguration()
4646
if err != nil {
@@ -53,7 +53,7 @@ func runTenantCmd(wrapper wrappers.TenantConfigurationWrapper, jwtWrapper wrappe
5353
format, _ := cmd.Flags().GetString(params.FormatFlag)
5454
tenantConfigurationResponseView := toTenantConfigurationResponseView(tenantConfigurationResponse)
5555

56-
licenseDetails, err := jwtWrapper.GetLicenseDetails(featureFlagsWrapper)
56+
licenseDetails, err := jwtWrapper.GetLicenseDetails()
5757
if err == nil {
5858
tenantConfigurationResponseView = appendLicenseDetails(tenantConfigurationResponseView, licenseDetails)
5959
}

internal/commands/util/tenant_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,41 @@ import (
88
)
99

1010
func TestTenantConfigurationHelp(t *testing.T) {
11-
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
11+
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{})
1212
cmd.SetArgs([]string{"utils", "tenant", "--help"})
1313
err := cmd.Execute()
1414
assert.Assert(t, err == nil)
1515
}
1616

1717
func TestTenantConfigurationJsonFormat(t *testing.T) {
18-
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
18+
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{})
1919
cmd.SetArgs([]string{"utils", "tenant", "--format", "json"})
2020
err := cmd.Execute()
2121
assert.NilError(t, err, "Tenant configuration command should run with no errors and print to json")
2222
}
2323

2424
func TestTenantConfigurationListFormat(t *testing.T) {
25-
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
25+
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{})
2626
cmd.SetArgs([]string{"utils", "tenant", "--format", "list"})
2727
err := cmd.Execute()
2828
assert.NilError(t, err, "Tenant configuration command should run with no errors and print to list")
2929
}
3030

3131
func TestTenantConfigurationTableFormat(t *testing.T) {
32-
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
32+
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{})
3333
cmd.SetArgs([]string{"utils", "tenant", "--format", "table"})
3434
err := cmd.Execute()
3535
assert.NilError(t, err, "Tenant configuration command should run with no errors and print to table")
3636
}
3737

3838
func TestTenantConfigurationInvalidFormat(t *testing.T) {
39-
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
39+
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{})
4040
cmd.SetArgs([]string{"utils", "tenant", "--format", "MOCK"})
4141
err := cmd.Execute()
4242
assert.Assert(t, err.Error() == mockFormatErrorMessage)
4343
}
4444

4545
func TestNewTenantConfigurationCommand(t *testing.T) {
46-
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
46+
cmd := NewTenantConfigurationCommand(mock.TenantConfigurationMockWrapper{}, &mock.JWTMockWrapper{})
4747
assert.Assert(t, cmd != nil, "Tenant configuration command must exist")
4848
}

internal/commands/util/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewUtilsCommand(
7777

7878
learnMoreCmd := NewLearnMoreCommand(learnMoreWrapper)
7979

80-
tenantCmd := NewTenantConfigurationCommand(tenantWrapper, jwtWrapper, featureFlagsWrapper)
80+
tenantCmd := NewTenantConfigurationCommand(tenantWrapper, jwtWrapper)
8181

8282
maskSecretsCmd := NewMaskSecretsCommand(chatWrapper)
8383

internal/params/envs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const (
8181
RiskManagementPathEnv = "CX_RISK_MANAGEMENT_PATH"
8282
ConfigFilePathEnv = "CX_CONFIG_FILE_PATH"
8383
RealtimeScannerPathEnv = "CX_REALTIME_SCANNER_PATH"
84+
UniqueIDEnv = "CX_UNIQUE_ID"
8485
StartMultiPartUploadPathEnv = "CX_START_MULTIPART_UPLOAD_PATH"
8586
MultipartPresignedPathEnv = "CX_MULTIPART_PRESIGNED_URL_PATH"
8687
CompleteMultipartUploadPathEnv = "CX_COMPLETE_MULTIPART_UPLOAD_PATH"

internal/params/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ const (
292292
APISecurityType = "api-security"
293293
AIProtectionType = "AI Protection"
294294
CheckmarxOneAssistType = "Checkmarx One Assist"
295-
CheckmarxOneStandAloneType = "Standalone"
295+
CheckmarxDevAssistType = "Checkmarx Developer Assist"
296296
ContainersType = "containers"
297297
APIDocumentationFlag = "apisec-swagger-filter"
298298
IacType = "iac-security"

internal/params/keys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var (
8080
RiskManagementPathKey = strings.ToLower(RiskManagementPathEnv)
8181
ConfigFilePathKey = strings.ToLower(ConfigFilePathEnv)
8282
RealtimeScannerPathKey = strings.ToLower(RealtimeScannerPathEnv)
83+
UniqueIDConfigKey = strings.ToLower(UniqueIDEnv)
8384
StartMultiPartUploadPathKey = strings.ToLower(StartMultiPartUploadPathEnv)
8485
MultipartPresignedPathKey = strings.ToLower(MultipartPresignedPathEnv)
8586
CompleteMultiPartUploadPathKey = strings.ToLower(CompleteMultipartUploadPathEnv)

internal/services/realtimeengine/common.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ func EnsureLicense(jwtWrapper wrappers.JWTWrapper) error {
3434
return errors.Wrap(err, "failed to check AIProtectionType engine allowance")
3535
}
3636

37-
if aiAllowed || assistAllowed {
37+
devAssistAllowed, err := jwtWrapper.IsAllowedEngine(params.CheckmarxDevAssistType)
38+
if err != nil {
39+
return errors.Wrap(err, "failed to check Checkmarx Developer Assist engine allowance")
40+
}
41+
42+
if aiAllowed || assistAllowed || devAssistAllowed {
3843
return nil
3944
}
4045
return errors.New(errorconstants.ErrMissingAIFeatureLicense)

0 commit comments

Comments
 (0)