mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-10 14:50:50 -08:00
* refactor(docker_conf): rename and remove unnecessary options * feat(rpc): define new API * fix(cli): change default timeout * fix(import): fix package names * refactor(vulnerability): remove old mock * refactor(utils): remove un-needed functions * feat(cache): implement cache communicating with a server * refactor(scan): separate scan function as local scanner * test(scanner): add tests for ScanImage * refactor(scan): remove unused options * test(vulnerability): generate mock * refactor(server): split a file * feat(server): implement new RPC server * feat(client): implement new RPC client * fix(cache): use new cache interface * fix(standalone): use new scanner * fix(client): use new scanner * fix(server): pass cache * test(integration): make sure an error is not nil before calling the method * fix(mod): update dependencies * test(integration): ensure the image load finishes * feat(docker): support DOCKER_HOST and DOCKER_CERT_PATH * chore(mod): update dependencies * refactor(rpc): remove old client * feat(server): support old API for backward compatibility * fix(server): check a schema version of JSON cache * fix(rpc): add a version to packages * feat(rpc): add PutImage * test: rename expectations * refactor(cache): rename LayerCache to ImageCache * refactor: rename ImageInfo to ImageReference * fix(applier): pass image_id to ApplyLayer * feat(cache): handle image cache * chore(mod): update dependencies * refactor(server): pass only config * feat(cli): add -removed-pkgs option * refactor(err): wrap errors
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"github.com/aquasecurity/fanal/cache"
|
|
"github.com/urfave/cli"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/aquasecurity/trivy-db/pkg/db"
|
|
"github.com/aquasecurity/trivy/internal/operation"
|
|
"github.com/aquasecurity/trivy/internal/server/config"
|
|
"github.com/aquasecurity/trivy/pkg/log"
|
|
"github.com/aquasecurity/trivy/pkg/rpc/server"
|
|
"github.com/aquasecurity/trivy/pkg/utils"
|
|
)
|
|
|
|
func Run(ctx *cli.Context) error {
|
|
return run(config.New(ctx))
|
|
}
|
|
|
|
func run(c config.Config) (err error) {
|
|
if err = log.InitLogger(c.Debug, c.Quiet); err != nil {
|
|
return xerrors.Errorf("failed to initialize a logger: %w", err)
|
|
}
|
|
|
|
// initialize config
|
|
if err = c.Init(); err != nil {
|
|
return xerrors.Errorf("failed to initialize options: %w", err)
|
|
}
|
|
|
|
// configure cache dir
|
|
utils.SetCacheDir(c.CacheDir)
|
|
log.Logger.Debugf("cache dir: %s", utils.CacheDir())
|
|
|
|
fsCache, err := cache.NewFSCache(utils.CacheDir())
|
|
if err != nil {
|
|
return xerrors.Errorf("unable to initialize cache: %w", err)
|
|
}
|
|
|
|
// server doesn't have image cache
|
|
cacheOperation := operation.NewCache(fsCache)
|
|
if c.Reset {
|
|
return cacheOperation.ClearDB()
|
|
}
|
|
|
|
if err = db.Init(c.CacheDir); err != nil {
|
|
return xerrors.Errorf("error in vulnerability DB initialize: %w", err)
|
|
}
|
|
|
|
// download the database file
|
|
if err = operation.DownloadDB(c.AppVersion, c.CacheDir, true, false, c.SkipUpdate); err != nil {
|
|
return err
|
|
}
|
|
|
|
if c.DownloadDBOnly {
|
|
return nil
|
|
}
|
|
|
|
return server.ListenAndServe(c, fsCache)
|
|
}
|