Skip to content

Commit 2597ad2

Browse files
committed
better log with threadId
1 parent 10ec9a5 commit 2597ad2

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

jas/iac/iacscanner.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/jfrog/jfrog-cli-security/utils"
1010
"github.com/jfrog/jfrog-cli-security/utils/formats/sarifutils"
1111
"github.com/jfrog/jfrog-cli-security/utils/jasutils"
12-
clientutils "github.com/jfrog/jfrog-client-go/utils"
1312

1413
"github.com/jfrog/jfrog-client-go/utils/log"
1514
"github.com/owenrumney/go-sarif/v3/pkg/report/v210/sarif"
@@ -47,7 +46,7 @@ func RunIacScan(scanner *jas.JasScanner, module jfrogappsconfig.Module, targetCo
4746
if vulnerabilitiesResults, violationsResults, err = iacScanManager.scanner.Run(iacScanManager, module); err != nil {
4847
return
4948
}
50-
log.Info(clientutils.GetLogMsgPrefix(threadId, false) + utils.GetScanFindingsLog(utils.IacScan, sarifutils.GetResultsLocationCount(vulnerabilitiesResults...), startTime))
49+
log.Info(utils.GetScanFindingsLog(utils.IacScan, sarifutils.GetResultsLocationCount(vulnerabilitiesResults...), startTime, threadId))
5150
return
5251
}
5352

jas/sast/sastscanner.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/jfrog/jfrog-cli-security/utils"
1111
"github.com/jfrog/jfrog-cli-security/utils/formats/sarifutils"
1212
"github.com/jfrog/jfrog-cli-security/utils/jasutils"
13-
clientutils "github.com/jfrog/jfrog-client-go/utils"
1413
"github.com/jfrog/jfrog-client-go/utils/log"
1514
"github.com/owenrumney/go-sarif/v3/pkg/report/v210/sarif"
1615
"golang.org/x/exp/maps"
@@ -46,7 +45,7 @@ func RunSastScan(scanner *jas.JasScanner, module jfrogappsconfig.Module, signedD
4645
if vulnerabilitiesResults, violationsResults, err = sastScanManager.scanner.Run(sastScanManager, module); err != nil {
4746
return
4847
}
49-
log.Info(clientutils.GetLogMsgPrefix(threadId, false) + utils.GetScanFindingsLog(utils.SastScan, sarifutils.GetResultsLocationCount(vulnerabilitiesResults...), startTime))
48+
log.Info(utils.GetScanFindingsLog(utils.SastScan, sarifutils.GetResultsLocationCount(vulnerabilitiesResults...), startTime, threadId))
5049
return
5150
}
5251

jas/secrets/secretsscanner.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"strings"
66
"time"
77

8-
clientutils "github.com/jfrog/jfrog-client-go/utils"
9-
108
jfrogappsconfig "github.com/jfrog/jfrog-apps-config/go"
119
"github.com/jfrog/jfrog-cli-security/jas"
1210
"github.com/jfrog/jfrog-cli-security/utils"
@@ -54,7 +52,7 @@ func RunSecretsScan(scanner *jas.JasScanner, scanType SecretsScanType, module jf
5452
if vulnerabilitiesResults, violationsResults, err = secretScanManager.scanner.Run(secretScanManager, module); err != nil {
5553
return
5654
}
57-
log.Info(clientutils.GetLogMsgPrefix(threadId, false) + utils.GetScanFindingsLog(utils.SecretsScan, sarifutils.GetResultsLocationCount(vulnerabilitiesResults...), startTime))
55+
log.Info(utils.GetScanFindingsLog(utils.SecretsScan, sarifutils.GetResultsLocationCount(vulnerabilitiesResults...), startTime, threadId))
5856
return
5957
}
6058

policy/enforcer/policyenforcer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type PolicyEnforcerViolationGenerator struct {
3737
// Filters
3838
projectKey string
3939
watches []string
40+
// Run options
41+
threadId int
4042
}
4143

4244
func NewPolicyEnforcerViolationGenerator() *PolicyEnforcerViolationGenerator {

sca/scan/enrich/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
type EnrichScanStrategy struct {
2020
serverDetails *config.ServerDetails
2121
projectKey string
22+
// Run Options
23+
threadId int
2224
}
2325

2426
func NewEnrichScanStrategy() *EnrichScanStrategy {

sca/scan/scascan.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ func hasDependenciesToScan(targetResults *results.TargetResults, logPrefix strin
149149
}
150150

151151
func scaScanTask(strategy SbomScanStrategy, params ScaScanParams) (err error) {
152-
logPrefix := ""
153-
if params.ThreadId >= 0 {
154-
logPrefix = clientUtils.GetLogMsgPrefix(params.ThreadId, false)
155-
}
156-
log.Info(logPrefix + utils.GetScanStartLog(utils.ScaScan, params.ScanResults.Target, params.TargetCount))
152+
log.Info(utils.GetScanStartLog(utils.ScaScan, params.ScanResults.Target, params.TargetCount, params.ThreadId))
157153
// Start the scan
158154
startTime := time.Now()
159155
if !params.IsNewFlow {
@@ -163,7 +159,7 @@ func scaScanTask(strategy SbomScanStrategy, params ScaScanParams) (err error) {
163159
if err != nil {
164160
return err
165161
}
166-
log.Info(logPrefix + utils.GetScanFindingsLog(utils.ScaScan, len(scanResults.Vulnerabilities), startTime))
162+
log.Info(utils.GetScanFindingsLog(utils.ScaScan, len(scanResults.Vulnerabilities), startTime, params.ThreadId))
167163
return dumpScanResponseToFileIfNeeded(scanResults, params.ResultsOutputDir, utils.ScaScan, params.ThreadId)
168164
}
169165
// New flow: we scan the SBOM and enrich it with CVE vulnerabilities and calculate violations.
@@ -177,7 +173,7 @@ func scaScanTask(strategy SbomScanStrategy, params ScaScanParams) (err error) {
177173
if params.ScanResults.ScaResults != nil && params.ScanResults.ScaResults.Sbom != nil && params.ScanResults.ScaResults.Sbom.Vulnerabilities != nil {
178174
vulnerabilityCount = len(*params.ScanResults.ScaResults.Sbom.Vulnerabilities)
179175
}
180-
log.Info(logPrefix + utils.GetScanFindingsLog(utils.ScaScan, vulnerabilityCount, startTime))
176+
log.Info(utils.GetScanFindingsLog(utils.ScaScan, vulnerabilityCount, startTime, params.ThreadId))
181177
return dumpEnrichedCdxToFileIfNeeded(bomWithVulnerabilities, params.ResultsOutputDir, utils.ScaScan, params.ThreadId)
182178
}
183179

utils/utils.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,26 @@ func getScanFindingName(scanType SubScanType) string {
133133
return fmt.Sprintf("%s vulnerabilities", subScanTypeToText[scanType])
134134
}
135135

136-
func GetScanStartLog(scanType SubScanType, target string, targetCount int) string {
136+
func GetScanStartLog(scanType SubScanType, target string, targetCount, threadId int) string {
137+
logPrefix := ""
138+
if threadId >= 0 {
139+
logPrefix = clientutils.GetLogMsgPrefix(threadId, false)
140+
}
137141
if targetCount > 1 {
138-
return fmt.Sprintf("Running %s scan on target '%s'...", subScanTypeToText[scanType], target)
142+
return logPrefix + fmt.Sprintf("Running %s scan on target '%s'...", subScanTypeToText[scanType], target)
139143
}
140-
return fmt.Sprintf("Running %s scan...", subScanTypeToText[scanType])
144+
return logPrefix + fmt.Sprintf("Running %s scan...", subScanTypeToText[scanType])
141145
}
142146

143-
func GetScanFindingsLog(scanType SubScanType, vulnerabilitiesCount int, startTime time.Time) string {
147+
func GetScanFindingsLog(scanType SubScanType, vulnerabilitiesCount int, startTime time.Time, threadId int) string {
148+
logPrefix := ""
149+
if threadId >= 0 {
150+
logPrefix = clientutils.GetLogMsgPrefix(threadId, false)
151+
}
144152
if vulnerabilitiesCount == 0 {
145-
return fmt.Sprintf("No %s were found (duration %s)", getScanFindingName(scanType), time.Since(startTime).String())
153+
return logPrefix + fmt.Sprintf("No %s were found (duration %s)", getScanFindingName(scanType), time.Since(startTime).String())
146154
}
147-
return fmt.Sprintf("Found %d %s (duration %s)", vulnerabilitiesCount, getScanFindingName(scanType), time.Since(startTime).String())
155+
return logPrefix + fmt.Sprintf("Found %d %s (duration %s)", vulnerabilitiesCount, getScanFindingName(scanType), time.Since(startTime).String())
148156
}
149157

150158
func IsCI() bool {

0 commit comments

Comments
 (0)