From 79a0578a0d2cd2b14e44c26d313ff3c5ec604784 Mon Sep 17 00:00:00 2001 From: Margarital Date: Wed, 15 Jan 2025 11:34:45 +0200 Subject: [PATCH] AST-74615 --- internal/commands/result.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/internal/commands/result.go b/internal/commands/result.go index 3f39fd2c2..fe7e27289 100644 --- a/internal/commands/result.go +++ b/internal/commands/result.go @@ -985,23 +985,35 @@ func runGetResultCommand( if errorModel != nil { return errors.Errorf("%s: CODE: %d, %s", failedGettingScan, errorModel.Code, errorModel.Message) } + if isScanFinished(scan.Status) { + policyResponseModel, err := services.HandlePolicyEvaluation(cmd, policyWrapper, scan, ignorePolicy, agent, waitDelay, policyTimeout) + if err != nil { + return err + } - policyResponseModel, err := services.HandlePolicyEvaluation(cmd, policyWrapper, scan, ignorePolicy, agent, waitDelay, policyTimeout) - if err != nil { + if sastRedundancy { + resultsParams[commonParams.SastRedundancyFlag] = "" + } + + _, err = CreateScanReport(resultsWrapper, risksOverviewWrapper, scsScanOverviewWrapper, exportWrapper, + policyResponseModel, resultsPdfReportsWrapper, scan, format, formatPdfToEmail, formatPdfOptions, + formatSbomOptions, targetFile, targetPath, agent, resultsParams, featureFlagsWrapper) return err - } + } else { + log.Printf("Scan executed in asynchronous mode or still running. Hence, no policy generated") - if sastRedundancy { - resultsParams[commonParams.SastRedundancyFlag] = "" } - - _, err = CreateScanReport(resultsWrapper, risksOverviewWrapper, scsScanOverviewWrapper, exportWrapper, - policyResponseModel, resultsPdfReportsWrapper, scan, format, formatPdfToEmail, formatPdfOptions, - formatSbomOptions, targetFile, targetPath, agent, resultsParams, featureFlagsWrapper) - return err + return nil } } +func isScanFinished(status wrappers.ScanStatus) bool { + statusBytes, _ := json.Marshal(status) + statusString := string(statusBytes) + statusString = strings.Trim(statusString, `"`) + return strings.EqualFold(statusString, "Completed") || strings.EqualFold(statusString, "Partial") +} + func runGetCodeBashingCommand( codeBashingWrapper wrappers.CodeBashingWrapper, ) func(cmd *cobra.Command, args []string) error { @@ -1973,7 +1985,7 @@ func parseGlDependencyLocation(result *wrappers.ScanResult) string { } else { location = "" } - return (location) + return location } func parseGlScaFiles(result *wrappers.ScanResult, glScaResult *wrappers.GlScaResultsCollection) *wrappers.GlScaResultsCollection { if result.ScanResultData.ScaPackageCollection != nil && result.ScanResultData.ScaPackageCollection.Locations != nil {