-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsast_health.go
68 lines (53 loc) · 2.03 KB
/
sast_health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/veracode/scan_health/v2/checks"
"github.com/veracode/scan_health/v2/data"
"github.com/veracode/scan_health/v2/report"
"github.com/veracode/scan_health/v2/utils"
"os"
)
func performSASTHealthCheck(scan *string, api data.API, regionToUse string, includePreviousScan *bool, outputFormat, jsonFilePath *string, errorOnHighSeverity *bool) {
buildId, err := utils.ParseBuildIdFromScanInformation(*scan)
if err != nil {
utils.ErrorAndExit("Could not parse build ID", err)
}
utils.ColorPrintf(fmt.Sprintf("Inspecting SAST build id = %d in the %s region\n",
buildId,
regionToUse))
healthReport := report.NewReport(buildId, regionToUse, AppVersion, false)
// Try to set the application ID however we could be working from a build ID so this may not be available
applicationId, err := utils.ParseApplicationIdFromPlatformUrl(*scan)
if err == nil {
healthReport.Scan.ApplicationId = applicationId
}
api.PopulateReportWithDataFromAPI(healthReport, *includePreviousScan)
if !healthReport.Scan.IsLatestScan {
if len(healthReport.Scan.SandboxName) > 0 {
color.HiYellow("Warning: This is not the latest SAST scan in this sandbox")
} else {
color.HiYellow("Warning: This is not the latest SAST policy scan")
}
}
var previousHealthReport = &report.Report{}
if *includePreviousScan == true {
previousBuildId := api.GetPreviousBuildId(healthReport)
if previousBuildId > 0 {
previousHealthReport = report.NewReport(previousBuildId, regionToUse, AppVersion, true)
previousHealthReport.Scan.ApplicationId = healthReport.Scan.ApplicationId
api.PopulateReportWithDataFromAPI(previousHealthReport, false)
}
}
checks.PerformChecks(healthReport, previousHealthReport)
healthReport.PrioritizeIssues()
healthReport.Render(*outputFormat, *jsonFilePath)
if *errorOnHighSeverity {
// Return exit code of 1 if any high severity issues found
for _, issue := range healthReport.Issues {
if issue.Severity == report.IssueSeverityHigh {
os.Exit(1)
}
}
}
}