Skip to content

Commit 5e2fe38

Browse files
Merge branch 'main' into other/sumitmorchhale7898/engines-assignment
2 parents 8e19aec + 8541016 commit 5e2fe38

15 files changed

Lines changed: 79 additions & 44 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
run: |
1919
sudo chmod +x ./internal/commands/.scripts/up.sh
2020
./internal/commands/.scripts/up.sh
21-
- name: Check if total coverage is greater then 79.9
21+
- name: Check if total coverage is greater then 78.2
2222
shell: bash
2323
run: |
2424
CODE_COV=$(go tool cover -func cover.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
25-
EXPECTED_CODE_COV=79.9
25+
EXPECTED_CODE_COV=78.2
2626
var=$(awk 'BEGIN{ print "'$CODE_COV'"<"'$EXPECTED_CODE_COV'" }')
2727
if [ "$var" -eq 1 ];then
2828
echo "Your code coverage is too low. Coverage precentage is: $CODE_COV"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM checkmarx/bash:5.2.37-r2-c5dcfc6a2fbe1c@sha256:c5dcfc6a2fbe1c8f9d11bdf902b5485bb78b4733864a99806749d5e244a6b75e
1+
FROM checkmarx/bash:5.2.37-r30-0714eec7a3fa2e@sha256:0714eec7a3fa2eadb3a6bdf2049bc158cc0311182a2475e8a467dbb2834df23f
22
USER nonroot
33

44
COPY cx /app/bin/cx

internal/commands/chat-kics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ func sendRequest(statefulWrapper gptWrapper.StatefulWrapper, azureAiEnabled bool
160160
Feature: featureName,
161161
}
162162
if azureAiEnabled {
163-
logger.Printf("Sending message to Azure AI model for " + featureName + " guided remediation. RequestID: " + requestID)
163+
logger.Printf("Sending message to Azure AI model for %s guided remediation. RequestID: %s", featureName, requestID)
164164
} else {
165-
logger.Printf("Sending message to Checkmarx AI model for " + featureName + " guided remediation. RequestID: " + requestID)
165+
logger.Printf("Sending message to Checkmarx AI model for %s guided remediation. RequestID: %s", featureName, requestID)
166166
}
167167
response, err = chatKicsWrapper.SecureCall(statefulWrapper, id, newMessages, &metadata, customerToken)
168168
if err != nil {
169169
return nil, err
170170
}
171171
} else { // if chatgpt is enabled or no engine is enabled
172-
logger.Printf("Sending message to ChatGPT model for " + featureName + " guided remediation. RequestID: " + requestID)
172+
logger.Printf("Sending message to ChatGPT model for %s guided remediation. RequestID: %s", featureName, requestID)
173173
response, err = chatKicsWrapper.Call(statefulWrapper, id, newMessages)
174174
if err != nil {
175175
return nil, err

internal/commands/chat-sast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func getSastConversationDetails(cmd *cobra.Command, chatConversationID string, s
104104
if userInput == "" {
105105
msg := fmt.Sprintf(UserInputRequiredErrorFormat, params.ChatUserInput, params.ChatConversationID)
106106
logger.PrintIfVerbose(msg)
107-
return false, "", uuid.UUID{}, outputError(cmd, uuid.Nil, errors.Errorf(msg))
107+
return false, "", uuid.UUID{}, outputError(cmd, uuid.Nil, errors.New(msg))
108108
}
109109
}
110110

internal/commands/result.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,14 @@ func riskManagementSubCommand(riskManagement wrappers.RiskManagementWrapper, fea
234234
Long: "The risk-management command displays risk management results for a specific project in Checkmarx One",
235235
Example: heredoc.Doc(
236236
`
237-
$ cx results risk-management --project-id <project Id> --limit <limit> (1-50, default: 50)
237+
$ cx results risk-management --project-id <project Id> --scan-id <scan ID> --limit <limit> (1-50, default: 50)
238238
`,
239239
),
240240
RunE: runRiskManagementCommand(riskManagement, featureFlagsWrapper),
241241
}
242242

243243
riskManagementCmd.PersistentFlags().String(commonParams.ProjectIDFlag, "", "Project ID")
244+
riskManagementCmd.PersistentFlags().String(commonParams.ScanIDFlag, "", "Scan ID")
244245
riskManagementCmd.PersistentFlags().Int(commonParams.LimitFlag, -1, "Limit")
245246

246247
addFormatFlag(riskManagementCmd, printer.FormatJSON, printer.FormatTable, printer.FormatList)
@@ -355,14 +356,16 @@ func runRiskManagementCommand(riskManagement wrappers.RiskManagementWrapper, fea
355356
) func(cmd *cobra.Command, args []string) error {
356357
return func(cmd *cobra.Command, args []string) error {
357358
projectID, _ := cmd.Flags().GetString(commonParams.ProjectIDFlag)
359+
scanID, _ := cmd.Flags().GetString(commonParams.ScanIDFlag)
360+
358361
limit, _ := cmd.Flags().GetInt(commonParams.LimitFlag)
359362

360363
flagResponse, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, wrappers.RiskManagementEnabled)
361364
ASPMEnabled := flagResponse.Status
362365
if !ASPMEnabled {
363366
return errors.Errorf("%s", "Risk management results are currently unavailable for your tenant.")
364367
}
365-
results, err := getRiskManagementResults(riskManagement, projectID)
368+
results, err := getRiskManagementResults(riskManagement, projectID, scanID)
366369
if err != nil {
367370
return err
368371
}
@@ -372,8 +375,8 @@ func runRiskManagementCommand(riskManagement wrappers.RiskManagementWrapper, fea
372375
}
373376
}
374377

375-
func getRiskManagementResults(riskManagement wrappers.RiskManagementWrapper, projectID string) (*wrappers.ASPMResult, error) {
376-
ASPMResult, errorModel, err := riskManagement.GetTopVulnerabilitiesByProjectID(projectID)
378+
func getRiskManagementResults(riskManagement wrappers.RiskManagementWrapper, projectID, scanID string) (*wrappers.ASPMResult, error) {
379+
ASPMResult, errorModel, err := riskManagement.GetTopVulnerabilitiesByProjectID(projectID, scanID)
377380
if err != nil {
378381
return nil, errors.Wrapf(err, "%s", failedListingResults)
379382
}

internal/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func getFilters(cmd *cobra.Command) (map[string]string, error) {
249249
for _, filter := range filters {
250250
filterKeyVal := strings.Split(filter, "=")
251251
if len(filterKeyVal) != params.KeyValuePairSize {
252-
return nil, errors.Errorf("Invalid filters. Filters should be in a KEY=VALUE format")
252+
return nil, errors.New("Invalid filters. Filters should be in a KEY=VALUE format")
253253
}
254254
filterKeyVal = validateExtraFilters(filterKeyVal)
255255
allFilters[filterKeyVal[0]] = strings.Replace(

internal/commands/scan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ func setupScanTypeProjectAndConfig(
722722
if newProjectName != "" {
723723
info["project"].(map[string]interface{})["id"] = newProjectName
724724
} else {
725-
return errors.Errorf("Project name is required")
725+
return errors.New("Project name is required")
726726
}
727727

728728
// We need to convert the project name into an ID
@@ -1072,7 +1072,7 @@ func isURLSupportedByScorecard(scsRepoURL string) bool {
10721072
func isScorecardRunnable(scsRepoToken, scsRepoURL, userScanTypes string) (bool, error) {
10731073
if scsRepoToken == "" || scsRepoURL == "" {
10741074
if userScanTypes != "" {
1075-
return false, errors.Errorf(ScsRepoRequiredMsg)
1075+
return false, errors.New(ScsRepoRequiredMsg)
10761076
}
10771077
fmt.Println(ScsRepoWarningMsg)
10781078
return false, nil
@@ -2137,7 +2137,7 @@ func parseThresholdLimit(limit string) (engineName string, intLimit int, err err
21372137
parts := strings.Split(limit, "=")
21382138
engineName = strings.Replace(parts[0], commonParams.KicsType, commonParams.IacType, 1)
21392139
if len(parts) <= 1 {
2140-
return engineName, 0, errors.Errorf("Error parsing threshold limit: missing values\n")
2140+
return engineName, 0, errors.New("Error parsing threshold limit: missing values\n")
21412141
}
21422142
intLimit, err = strconv.Atoi(parts[1])
21432143
if err != nil {
@@ -2245,7 +2245,7 @@ func isScanRunning(
22452245
log.Fatal("Cannot source code temp file.", err)
22462246
}
22472247
if errorModel != nil {
2248-
log.Fatalf(fmt.Sprintf("%s: CODE: %d, %s", failedGetting, errorModel.Code, errorModel.Message))
2248+
log.Fatalf("%s: CODE: %d, %s", failedGetting, errorModel.Code, errorModel.Message)
22492249
} else if scanResponseModel != nil {
22502250
if scanResponseModel.Status == wrappers.ScanRunning || scanResponseModel.Status == wrappers.ScanQueued {
22512251
log.Println("Scan status: ", scanResponseModel.Status)

internal/params/binds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ var EnvVarsBinds = []struct {
7373
{AiProxyCheckmarxAiRouteKey, AiProxyCheckmarxAiRouteEnv, "api/ai-proxy/redirect/azure"},
7474
{ASCAPortKey, ASCAPortEnv, ""},
7575
{ScsRepoTokenKey, ScsRepoTokenEnv, ""},
76-
{RiskManagementPathKey, RiskManagementPathEnv, "api/risk-management/projects/%s/results"},
76+
{RiskManagementPathKey, RiskManagementPathEnv, "api/risk-management/projects/%s/results?scanID=%s"},
7777
{ConfigFilePathKey, ConfigFilePathEnv, ""},
7878
}

internal/wrappers/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func GetClient(timeout uint) *http.Client {
123123

124124
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
125125
if len(via) > 1 {
126-
return fmt.Errorf("too many redirects")
126+
return errors.New("too many redirects")
127127
}
128128
if len(via) != 0 && req.Response.StatusCode == http.StatusMovedPermanently {
129129
for attr, val := range via[0].Header {
@@ -349,7 +349,7 @@ func addTenantAuthURI(baseAuthURI string) (string, error) {
349349
tenant := viper.GetString(commonParams.TenantKey)
350350

351351
if tenant == "" {
352-
return "", errors.Errorf(MissingTenant)
352+
return "", errors.New(MissingTenant)
353353
}
354354

355355
authPath = strings.Replace(authPath, "organization", strings.ToLower(tenant), 1)
@@ -454,9 +454,9 @@ func configureClientCredentialsAndGetNewToken() (string, error) {
454454
var accessToken string
455455

456456
if accessKeyID == "" && astAPIKey == "" {
457-
return "", errors.Errorf(fmt.Sprintf(FailedToAuth, "access key ID"))
457+
return "", errors.Errorf(FailedToAuth, "access key ID")
458458
} else if accessKeySecret == "" && astAPIKey == "" {
459-
return "", errors.Errorf(fmt.Sprintf(FailedToAuth, "access key secret"))
459+
return "", errors.Errorf(FailedToAuth, "access key secret")
460460
}
461461

462462
authURI, err := GetAuthURI()
@@ -642,12 +642,12 @@ func request(client *http.Client, req *http.Request, responseBody bool) (*http.R
642642
func handleRedirect(resp *http.Response, req *http.Request, body []byte) (*http.Request, error) {
643643
redirectURL := resp.Header.Get("Location")
644644
if redirectURL == "" {
645-
return nil, fmt.Errorf(applicationErrors.RedirectURLNotFound)
645+
return nil, errors.New(applicationErrors.RedirectURLNotFound)
646646
}
647647

648648
method := GetHTTPMethod(req)
649649
if method == "" {
650-
return nil, fmt.Errorf(applicationErrors.HTTPMethodNotFound)
650+
return nil, errors.New(applicationErrors.HTTPMethodNotFound)
651651
}
652652

653653
newReq, err := recreateRequest(req, method, redirectURL, body)
@@ -764,7 +764,7 @@ func GetURL(path, accessToken string) (string, error) {
764764
}
765765

766766
if cleanURL == "" {
767-
return "", errors.Errorf(MissingURI)
767+
return "", errors.New(MissingURI)
768768
}
769769

770770
cleanURL = strings.Trim(cleanURL, "/")

internal/wrappers/mock/risk-management-mock.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66

77
type RiskManagementMockWrapper struct{}
88

9-
func (r *RiskManagementMockWrapper) GetTopVulnerabilitiesByProjectID(projectID string) (*wrappers.ASPMResult, *wrappers.WebError, error) {
9+
func (r *RiskManagementMockWrapper) GetTopVulnerabilitiesByProjectID(projectID string, scanID string) (*wrappers.ASPMResult, *wrappers.WebError, error) {
1010
mockResults := []wrappers.RiskManagementResult{
11-
{ID: "1", Name: "Vuln1", Severity: "High"},
12-
{ID: "2", Name: "Vuln2", Severity: "Medium"},
11+
{ID: "1", Name: "Vuln1", Severity: "High", Traits: map[string]string{wrappers.ExpPathKey: wrappers.ExpPathValue}},
12+
{ID: "2", Name: "Vuln2", Severity: "Medium", Traits: map[string]string{wrappers.SuspMalwareKey: wrappers.SuspMalwareValue}},
1313
}
1414

1515
mockASPMResult := &wrappers.ASPMResult{
1616
ProjectID: projectID,
17+
ScanID: scanID,
1718
Results: mockResults,
1819
}
1920

0 commit comments

Comments
 (0)