Skip to content

Commit 897ebdb

Browse files
fixed conflicts
2 parents 97da1ee + 35b4d6f commit 897ebdb

File tree

9 files changed

+89
-12
lines changed

9 files changed

+89
-12
lines changed

internal/commands/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func NewAstCLI(
215215
prWrapper,
216216
learnMoreWrapper,
217217
tenantWrapper,
218+
jwtWrapper,
218219
chatWrapper,
219220
policyWrapper,
220221
scansWrapper,

internal/commands/util/tenant.go

Lines changed: 24 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) *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),
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) 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 {
@@ -52,10 +52,16 @@ func runTenantCmd(wrapper wrappers.TenantConfigurationWrapper) func(cmd *cobra.C
5252
if tenantConfigurationResponse != nil {
5353
format, _ := cmd.Flags().GetString(params.FormatFlag)
5454
tenantConfigurationResponseView := toTenantConfigurationResponseView(tenantConfigurationResponse)
55+
56+
licenseDetails, err := jwtWrapper.GetLicenseDetails()
57+
if err == nil {
58+
tenantConfigurationResponseView = appendLicenseDetails(tenantConfigurationResponseView, licenseDetails)
59+
}
60+
5561
if format == "" {
5662
format = defaultFormat
5763
}
58-
err := printer.Print(cmd.OutOrStdout(), tenantConfigurationResponseView, format)
64+
err = printer.Print(cmd.OutOrStdout(), tenantConfigurationResponseView, format)
5965
if err != nil {
6066
return err
6167
}
@@ -76,3 +82,17 @@ func toTenantConfigurationResponseView(response *[]*wrappers.TenantConfiguration
7682
}
7783
return tenantConfigurationResponseView
7884
}
85+
86+
func appendLicenseDetails(responseView interface{}, licenseDetails map[string]string) interface{} {
87+
tenantConfigurationResponseView := responseView.([]*wrappers.TenantConfigurationResponse)
88+
89+
for key, value := range licenseDetails {
90+
licenseEntry := &wrappers.TenantConfigurationResponse{
91+
Key: key,
92+
Value: value,
93+
}
94+
tenantConfigurationResponseView = append(tenantConfigurationResponseView, licenseEntry)
95+
}
96+
97+
return tenantConfigurationResponseView
98+
}

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{})
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{})
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{})
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{})
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{})
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{})
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func NewUtilsCommand(
3535
prWrapper wrappers.PRWrapper,
3636
learnMoreWrapper wrappers.LearnMoreWrapper,
3737
tenantWrapper wrappers.TenantConfigurationWrapper,
38+
jwtWrapper wrappers.JWTWrapper,
3839
chatWrapper wrappers.ChatWrapper,
3940
policyWrapper wrappers.PolicyWrapper,
4041
scansWrapper wrappers.ScansWrapper,
@@ -76,7 +77,7 @@ func NewUtilsCommand(
7677

7778
learnMoreCmd := NewLearnMoreCommand(learnMoreWrapper)
7879

79-
tenantCmd := NewTenantConfigurationCommand(tenantWrapper)
80+
tenantCmd := NewTenantConfigurationCommand(tenantWrapper, jwtWrapper)
8081

8182
maskSecretsCmd := NewMaskSecretsCommand(chatWrapper)
8283

internal/commands/util/utils_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestNewUtilsCommand(t *testing.T) {
2222
nil,
2323
mock.LearnMoreMockWrapper{},
2424
mock.TenantConfigurationMockWrapper{},
25+
&mock.JWTMockWrapper{},
2526
mock.ChatMockWrapper{},
2627
nil,
2728
nil,

internal/params/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ const (
289289
APISecurityType = "api-security"
290290
AIProtectionType = "AI Protection"
291291
CheckmarxOneAssistType = "Checkmarx One Assist"
292+
CheckmarxOneStandAloneType = "Checkmarx Developer Assist"
292293
ContainersType = "containers"
293294
APIDocumentationFlag = "apisec-swagger-filter"
294295
IacType = "iac-security"

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.CheckmarxOneStandAloneType)
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)

internal/wrappers/jwt-helper.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wrappers
22

33
import (
44
"os/user"
5+
"strconv"
56
"strings"
67

78
"github.com/checkmarx/ast-cli/internal/logger"
@@ -28,6 +29,7 @@ type JWTStruct struct {
2829

2930
type JWTWrapper interface {
3031
GetAllowedEngines(featureFlagsWrapper FeatureFlagsWrapper) (allowedEngines map[string]bool, err error)
32+
GetLicenseDetails() (licenseDetails map[string]string, err error)
3133
IsAllowedEngine(engine string) (bool, error)
3234
ExtractTenantFromToken() (tenant string, err error)
3335
CheckPermissionByAccessToken(requiredPermission string) (permission bool, err error)
@@ -81,6 +83,33 @@ func (*JWTStruct) GetAllowedEngines(featureFlagsWrapper FeatureFlagsWrapper) (al
8183
return getDefaultEngines(scsLicensingV2Flag.Status), nil
8284
}
8385

86+
func (*JWTStruct) GetLicenseDetails() (licenseDetails map[string]string, err error) {
87+
licenseDetails = make(map[string]string)
88+
89+
jwtStruct, err := getJwtStruct()
90+
if err != nil {
91+
return nil, err
92+
}
93+
94+
assistEnabled := containsIgnoreCase(jwtStruct.AstLicense.LicenseData.AllowedEngines, commonParams.CheckmarxOneAssistType) ||
95+
containsIgnoreCase(jwtStruct.AstLicense.LicenseData.AllowedEngines, commonParams.AIProtectionType)
96+
devAssistEnabled := containsIgnoreCase(jwtStruct.AstLicense.LicenseData.AllowedEngines, commonParams.CheckmarxOneStandAloneType)
97+
98+
licenseDetails["scan.config.plugins.cxoneassist"] = strconv.FormatBool(assistEnabled)
99+
licenseDetails["scan.config.plugins.cxonedevassist"] = strconv.FormatBool(devAssistEnabled)
100+
return licenseDetails, nil
101+
}
102+
103+
// containsIgnoreCase returns true if target exists in arr using case-insensitive comparison
104+
func containsIgnoreCase(arr []string, target string) bool {
105+
for _, s := range arr {
106+
if strings.EqualFold(s, target) {
107+
return true
108+
}
109+
}
110+
return false
111+
}
112+
84113
func getJwtStruct() (*JWTStruct, error) {
85114
accessToken, err := GetAccessToken()
86115
if err != nil {

internal/wrappers/mock/jwt-helper-mock.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mock
22

33
import (
4+
"strconv"
45
"strings"
56

67
"github.com/checkmarx/ast-cli/internal/params"
@@ -22,6 +23,8 @@ const SecretDetectionDisabled = 1
2223

2324
var engines = []string{"sast", "sca", "api-security", "iac-security", "scs", "containers", "enterprise-secrets"}
2425

26+
const licenseEnabledValue = "true"
27+
2528
// GetAllowedEngines mock for tests
2629
func (j *JWTMockWrapper) GetAllowedEngines(featureFlagsWrapper wrappers.FeatureFlagsWrapper) (allowedEngines map[string]bool, err error) {
2730
if j.CustomGetAllowedEngines != nil {
@@ -75,3 +78,19 @@ func (j *JWTMockWrapper) IsAllowedEngine(engine string) (bool, error) {
7578
func (j *JWTMockWrapper) CheckPermissionByAccessToken(requiredPermission string) (permission bool, err error) {
7679
return true, nil
7780
}
81+
82+
func (j *JWTMockWrapper) GetLicenseDetails() (licenseDetails map[string]string, err error) {
83+
licenseDetails = make(map[string]string)
84+
85+
assistEnabled := (j.CheckmarxOneAssistEnabled != CheckmarxOneAssistDisabled) || (j.AIEnabled != AIProtectionDisabled)
86+
licenseDetails["scan.config.plugins.cxoneassist"] = strconv.FormatBool(assistEnabled)
87+
88+
standaloneEnabled := true
89+
licenseDetails["scan.config.plugins.standalone"] = strconv.FormatBool(standaloneEnabled)
90+
91+
for _, engine := range engines {
92+
licenseDetails[engine] = licenseEnabledValue
93+
}
94+
95+
return licenseDetails, nil
96+
}

0 commit comments

Comments
 (0)