-
Notifications
You must be signed in to change notification settings - Fork 43
Add diff logic and parallel logger support for audit #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
18c22a1
6c07738
caf59eb
7fc3bd0
96ae51a
b22d7c4
16f7f21
c38b6c3
5e4a231
86e70fd
37f3743
b0eb167
957b363
809a52f
a5897a9
22f7713
56609db
816605d
1ca4a0a
0b35329
bccd932
7a90d14
ad0f25d
4485151
53833b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,6 +292,11 @@ func (auditCmd *AuditCommand) CommandName() string { | |
| // Returns an audit Results object containing all the scan results. | ||
| // If the current server is entitled for JAS, the advanced security results will be included in the scan results. | ||
| func RunAudit(auditParams *AuditParams) (cmdResults *results.SecurityCommandResults) { | ||
| // Set up isolated logging if a log collector is provided | ||
| if collector := auditParams.GetLogCollector(); collector != nil { | ||
| log.SetLoggerForGoroutine(collector.Logger()) | ||
| defer log.ClearLoggerForGoroutine() | ||
| } | ||
| // Prepare the command for the scan. | ||
| if cmdResults = prepareToScan(auditParams); cmdResults.GeneralError != nil { | ||
| return | ||
|
|
@@ -623,7 +628,14 @@ func addJasScansToRunner(auditParallelRunner *utils.SecurityParallelRunner, audi | |
| return | ||
| } | ||
| auditParallelRunner.JasWg.Add(1) | ||
| if _, jasErr := auditParallelRunner.Runner.AddTaskWithError(createJasScansTask(auditParallelRunner, scanResults, serverDetails, auditParams, jasScanner), func(taskErr error) { | ||
| currentLogger := log.GetLogger() | ||
| jasTask := createJasScansTask(auditParallelRunner, scanResults, serverDetails, auditParams, jasScanner) | ||
| wrappedJasTask := func(threadId int) error { | ||
| log.SetLoggerForGoroutine(currentLogger) | ||
| defer log.ClearLoggerForGoroutine() | ||
| return jasTask(threadId) | ||
| } | ||
| if _, jasErr := auditParallelRunner.Runner.AddTaskWithError(wrappedJasTask, func(taskErr error) { | ||
|
eyalk007 marked this conversation as resolved.
Outdated
Comment on lines
+632
to
+634
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we only want to wrap and change logs if collector is set. |
||
| scanResults.AddGeneralError(fmt.Errorf("failed while adding JAS scan tasks: %s", taskErr.Error()), auditParams.AllowPartialResults()) | ||
| }); jasErr != nil { | ||
| generalError = fmt.Errorf("failed to create JAS task: %s", jasErr.Error()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package audit | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this should be at jfrog/jfrog-client-go#1297?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are the options Move LogCollector to client-go - but it's really just a wrapper or we Keep it as is
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing code from repo is always good :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doen tell me if you like it now |
||
|
|
||
| import ( | ||
| "github.com/jfrog/jfrog-client-go/utils/log" | ||
| ) | ||
|
|
||
| // LogCollector captures logs for isolated parallel audit operations. | ||
| type LogCollector struct { | ||
| logger *log.BufferedLogger | ||
| } | ||
|
|
||
| func NewLogCollector(level log.LevelType) *LogCollector { | ||
| return &LogCollector{ | ||
| logger: log.NewBufferedLogger(level), | ||
| } | ||
| } | ||
|
|
||
| func (c *LogCollector) Logger() log.Log { | ||
| return c.logger | ||
| } | ||
|
|
||
| // ReplayTo outputs captured logs through the target logger (preserving colors). | ||
| func (c *LogCollector) ReplayTo(target log.Log) { | ||
| c.logger.ReplayTo(target) | ||
| } | ||
|
|
||
| func (c *LogCollector) HasLogs() bool { | ||
| return c.logger.Len() > 0 | ||
| } | ||
|
|
||
| func (c *LogCollector) Len() int { | ||
| return c.logger.Len() | ||
| } | ||
|
|
||
| func (c *LogCollector) String() string { | ||
| return c.logger.String() | ||
| } | ||
|
|
||
| func (c *LogCollector) Clear() { | ||
| c.logger.Clear() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module github.com/jfrog/jfrog-cli-security | ||
|
|
||
| go 1.25.4 | ||
| go 1.25.5 | ||
|
|
||
| require ( | ||
| github.com/CycloneDX/cyclonedx-go v0.9.3 | ||
|
|
@@ -11,7 +11,7 @@ require ( | |
| github.com/gookit/color v1.6.0 | ||
| github.com/hashicorp/go-hclog v1.6.3 | ||
| github.com/hashicorp/go-plugin v1.6.3 | ||
| github.com/jfrog/build-info-go v1.12.5-0.20251209171349-eb030db986f9 | ||
| github.com/jfrog/build-info-go v1.13.0 | ||
| github.com/jfrog/froggit-go v1.20.6 | ||
| github.com/jfrog/gofrog v1.7.6 | ||
| github.com/jfrog/jfrog-apps-config v1.0.1 | ||
|
|
@@ -135,12 +135,12 @@ require ( | |
| gopkg.in/warnings.v0 v0.1.2 // indirect | ||
| ) | ||
|
|
||
| // replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go master | ||
|
|
||
| // replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 master | ||
|
|
||
| //replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory main | ||
|
|
||
| // replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go dev | ||
|
|
||
| // replace github.com/jfrog/froggit-go => github.com/jfrog/froggit-go master | ||
|
|
||
| replace github.com/jfrog/jfrog-client-go => github.com/eyalk007/jfrog-client-go v0.0.0-20260114112951-67b77f49255f | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder to remove replace after merging dependend PR |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the collector is running on main routine so it will first record all the logs from main and it will collect the other after?