mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 23:26:39 -08:00
refactor: unify cache implementations (#6977)
Signed-off-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
@@ -6,12 +6,12 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy-db/pkg/db"
|
||||
"github.com/aquasecurity/trivy/pkg/cache"
|
||||
"github.com/aquasecurity/trivy/pkg/commands/operation"
|
||||
"github.com/aquasecurity/trivy/pkg/flag"
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
"github.com/aquasecurity/trivy/pkg/module"
|
||||
rpcServer "github.com/aquasecurity/trivy/pkg/rpc/server"
|
||||
"github.com/aquasecurity/trivy/pkg/utils/fsutils"
|
||||
)
|
||||
|
||||
// Run runs the scan
|
||||
@@ -19,16 +19,16 @@ func Run(ctx context.Context, opts flag.Options) (err error) {
|
||||
log.InitLogger(opts.Debug, opts.Quiet)
|
||||
|
||||
// configure cache dir
|
||||
fsutils.SetCacheDir(opts.CacheDir)
|
||||
cache, err := operation.NewCache(opts.CacheOptions)
|
||||
cache.SetDir(opts.CacheDir)
|
||||
cacheClient, err := cache.NewClient(opts.CacheOptions.CacheBackendOptions)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("server cache error: %w", err)
|
||||
}
|
||||
defer cache.Close()
|
||||
log.Debug("Cache", log.String("dir", fsutils.CacheDir()))
|
||||
defer cacheClient.Close()
|
||||
log.Debug("Cache", log.String("dir", cache.Dir()))
|
||||
|
||||
if opts.Reset {
|
||||
return cache.ClearDB()
|
||||
return cacheClient.ClearDB()
|
||||
}
|
||||
|
||||
// download the database file
|
||||
@@ -57,5 +57,5 @@ func Run(ctx context.Context, opts flag.Options) (err error) {
|
||||
|
||||
server := rpcServer.NewServer(opts.AppVersion, opts.Listen, opts.CacheDir, opts.Token, opts.TokenHeader,
|
||||
opts.DBRepository, opts.RegistryOpts())
|
||||
return server.ListenAndServe(ctx, cache, opts.SkipDBUpdate)
|
||||
return server.ListenAndServe(ctx, cacheClient, opts.SkipDBUpdate)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user