Skip to content

Commit 68b98dc

Browse files
knqyf263fl0pp5
authored andcommitted
refactor: remove parallel walk (aquasecurity#5180)
Signed-off-by: knqyf263 <[email protected]>
1 parent 69dfe4e commit 68b98dc

File tree

45 files changed

+504
-801
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+504
-801
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ jobs:
4545
id: lint
4646
uses: golangci/[email protected]
4747
with:
48-
version: v1.54
49-
args: --deadline=30m --out-format=line-number
48+
version: v1.57
49+
args: --timeout=30m --out-format=line-number
5050
skip-cache: true # https://github.com/golangci/golangci-lint-action/issues/244#issuecomment-1052197778
5151
if: matrix.operating-system == 'ubuntu-latest'
5252

.golangci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ linters:
8989

9090
run:
9191
go: '1.22'
92-
skip-files:
92+
93+
issues:
94+
exclude-files:
9395
- ".*_mock.go$"
9496
- ".*_test.go$"
9597
- "integration/*"
9698
- "examples/*"
97-
skip-dirs:
99+
exclude-dirs:
98100
- "pkg/iac/scanners/terraform/parser/funcs" # copies of Terraform functions
99-
100-
issues:
101101
exclude-rules:
102102
- linters:
103103
- gosec

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ require (
8888
github.com/package-url/packageurl-go v0.1.2
8989
github.com/quasilyte/go-ruleguard/dsl v0.3.22
9090
github.com/samber/lo v1.39.0
91-
github.com/saracen/walker v0.1.3
9291
github.com/secure-systems-lab/go-securesystemslib v0.8.0
9392
github.com/sigstore/rekor v1.2.2
9493
github.com/sirupsen/logrus v1.9.3

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,6 @@ github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
15231523
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
15241524
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
15251525
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
1526-
github.com/saracen/walker v0.1.3 h1:YtcKKmpRPy6XJTHJ75J2QYXXZYWnZNQxPCVqZSHVV/g=
1527-
github.com/saracen/walker v0.1.3/go.mod h1:FU+7qU8DeQQgSZDmmThMJi93kPkLFgy0oVAcLxurjIk=
15281526
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
15291527
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
15301528
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=

magefiles/magefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (Tool) Wire() error {
6161

6262
// GolangciLint installs golangci-lint
6363
func (Tool) GolangciLint() error {
64-
const version = "v1.54.2"
64+
const version = "v1.57.2"
6565
if exists(filepath.Join(GOBIN, "golangci-lint")) {
6666
return nil
6767
}

pkg/commands/artifact/inject.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ package artifact
55

66
import (
77
"context"
8-
"github.com/aquasecurity/trivy/pkg/fanal/artifact/vm"
9-
108
"github.com/google/wire"
119

1210
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
@@ -57,7 +55,7 @@ func initializeSBOMScanner(ctx context.Context, filePath string, artifactCache c
5755
}
5856

5957
func initializeVMScanner(ctx context.Context, filePath string, artifactCache cache.ArtifactCache,
60-
localArtifactCache cache.LocalArtifactCache, walker vm.Walker, artifactOption artifact.Option) (
58+
localArtifactCache cache.LocalArtifactCache, artifactOption artifact.Option) (
6159
scanner.Scanner, func(), error) {
6260
wire.Build(scanner.StandaloneVMSet)
6361
return scanner.Scanner{}, nil, nil
@@ -108,7 +106,7 @@ func initializeRemoteSBOMScanner(ctx context.Context, path string, artifactCache
108106

109107
// initializeRemoteVMScanner is for vm scanning in client/server mode
110108
func initializeRemoteVMScanner(ctx context.Context, path string, artifactCache cache.ArtifactCache,
111-
walker vm.Walker, remoteScanOptions client.ScannerOption, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
109+
remoteScanOptions client.ScannerOption, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
112110
wire.Build(scanner.RemoteVMSet)
113111
return scanner.Scanner{}, nil, nil
114112
}

pkg/commands/artifact/run.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
2020
"github.com/aquasecurity/trivy/pkg/fanal/cache"
2121
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
22+
"github.com/aquasecurity/trivy/pkg/fanal/walker"
2223
"github.com/aquasecurity/trivy/pkg/flag"
2324
"github.com/aquasecurity/trivy/pkg/javadb"
2425
"github.com/aquasecurity/trivy/pkg/log"
@@ -650,9 +651,8 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
650651
},
651652
ArtifactOption: artifact.Option{
652653
DisabledAnalyzers: disabledAnalyzers(opts),
653-
SkipFiles: opts.SkipFiles,
654-
SkipDirs: opts.SkipDirs,
655654
FilePatterns: opts.FilePatterns,
655+
Parallel: opts.Parallel,
656656
Offline: opts.OfflineScan,
657657
NoProgress: opts.NoProgress || opts.Quiet,
658658
Insecure: opts.Insecure,
@@ -662,7 +662,6 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
662662
SBOMSources: opts.SBOMSources,
663663
RekorURL: opts.RekorURL,
664664
//Platform: opts.Platform,
665-
Parallel: opts.Parallel,
666665
AWSRegion: opts.Region,
667666
AWSEndpoint: opts.Endpoint,
668667
FileChecksum: fileChecksum,
@@ -692,6 +691,12 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
692691
Full: opts.LicenseFull,
693692
ClassifierConfidenceLevel: opts.LicenseConfidenceLevel,
694693
},
694+
695+
// For file walking
696+
WalkerOption: walker.Option{
697+
SkipFiles: opts.SkipFiles,
698+
SkipDirs: opts.SkipDirs,
699+
},
695700
},
696701
}, scanOptions, nil
697702
}

pkg/commands/artifact/scanner.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"golang.org/x/xerrors"
77

8-
"github.com/aquasecurity/trivy/pkg/fanal/walker"
98
"github.com/aquasecurity/trivy/pkg/scanner"
109
)
1110

@@ -110,10 +109,7 @@ func sbomRemoteScanner(ctx context.Context, conf ScannerConfig) (scanner.Scanner
110109

111110
// vmStandaloneScanner initializes a VM scanner in standalone mode
112111
func vmStandaloneScanner(ctx context.Context, conf ScannerConfig) (scanner.Scanner, func(), error) {
113-
// TODO: The walker should be initialized in initializeVMScanner after https://github.com/aquasecurity/trivy/pull/5180
114-
w := walker.NewVM(conf.ArtifactOption.SkipFiles, conf.ArtifactOption.SkipDirs)
115-
s, cleanup, err := initializeVMScanner(ctx, conf.Target, conf.ArtifactCache, conf.LocalArtifactCache,
116-
w, conf.ArtifactOption)
112+
s, cleanup, err := initializeVMScanner(ctx, conf.Target, conf.ArtifactCache, conf.LocalArtifactCache, conf.ArtifactOption)
117113
if err != nil {
118114
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize a vm scanner: %w", err)
119115
}
@@ -122,9 +118,7 @@ func vmStandaloneScanner(ctx context.Context, conf ScannerConfig) (scanner.Scann
122118

123119
// vmRemoteScanner initializes a VM scanner in client/server mode
124120
func vmRemoteScanner(ctx context.Context, conf ScannerConfig) (scanner.Scanner, func(), error) {
125-
// TODO: The walker should be initialized in initializeVMScanner after https://github.com/aquasecurity/trivy/pull/5180
126-
w := walker.NewVM(conf.ArtifactOption.SkipFiles, conf.ArtifactOption.SkipDirs)
127-
s, cleanup, err := initializeRemoteVMScanner(ctx, conf.Target, conf.ArtifactCache, w, conf.ServerOption, conf.ArtifactOption)
121+
s, cleanup, err := initializeRemoteVMScanner(ctx, conf.Target, conf.ArtifactCache, conf.ServerOption, conf.ArtifactOption)
128122
if err != nil {
129123
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize a remote vm scanner: %w", err)
130124
}

pkg/commands/artifact/wire_gen.go

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/fanal/analyzer/pkg/dpkg/copyright.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (a *dpkgLicenseAnalyzer) parseCopyright(r xio.ReadSeekerAt) ([]types.Licens
8888
l := strings.TrimSpace(line[8:])
8989

9090
l = normalizeLicense(l)
91-
if len(l) > 0 {
91+
if l != "" {
9292
for _, lic := range licensing.SplitLicenses(l) {
9393
lic = licensing.Normalize(lic)
9494
if !slices.Contains(licenses, lic) {

0 commit comments

Comments
 (0)