diff --git a/config/config.go b/config/config.go index 54aef8d12f..62d38f6ee2 100644 --- a/config/config.go +++ b/config/config.go @@ -6,6 +6,8 @@ import ( "strconv" "strings" + "github.com/aquasecurity/trivy/pkg/db" + "github.com/aquasecurity/trivy/pkg/javadb" "github.com/asaskevich/govalidator" "golang.org/x/xerrors" @@ -87,6 +89,11 @@ type ReportOpts struct { TrivyOpts } +var ( + DefaultTrivyDBRepositories = []string{db.DefaultGCRRepository, db.DefaultGHCRRepository} + DefaultTrivyJavaDBRepositories = []string{javadb.DefaultGCRRepository, javadb.DefaultGHCRRepository} +) + // TrivyOpts is options for trivy DBs type TrivyOpts struct { TrivyCacheDBDir string `json:"trivyCacheDBDir,omitempty"` diff --git a/detector/javadb/javadb.go b/detector/javadb/javadb.go index 6c96650f89..0586b378dd 100644 --- a/detector/javadb/javadb.go +++ b/detector/javadb/javadb.go @@ -49,6 +49,9 @@ func UpdateJavaDB(trivyOpts config.TrivyOpts, noProgress bool) error { } // Download DB + if len(trivyOpts.TrivyJavaDBRepositories) == 0 { + trivyOpts.TrivyJavaDBRepositories = config.DefaultTrivyJavaDBRepositories + } logging.Log.Infof("Trivy Java DB Repository: %s", strings.Join(trivyOpts.TrivyJavaDBRepositories, ", ")) logging.Log.Info("Downloading Trivy Java DB...") diff --git a/detector/library.go b/detector/library.go index 64ef7e18e8..06323c56b7 100644 --- a/detector/library.go +++ b/detector/library.go @@ -96,6 +96,9 @@ func DetectLibsCves(r *models.ScanResult, trivyOpts config.TrivyOpts, logOpts lo } func downloadDB(appVersion string, trivyOpts config.TrivyOpts, noProgress, skipUpdate bool) error { + if len(trivyOpts.TrivyDBRepositories) == 0 { + trivyOpts.TrivyDBRepositories = config.DefaultTrivyDBRepositories + } refs := make([]name.Reference, 0, len(trivyOpts.TrivyDBRepositories)) for _, repo := range trivyOpts.TrivyDBRepositories { ref, err := func() (name.Reference, error) { diff --git a/subcmds/report.go b/subcmds/report.go index 6f025f6e99..49362e2b78 100644 --- a/subcmds/report.go +++ b/subcmds/report.go @@ -5,13 +5,10 @@ package subcmds import ( "context" "flag" - "fmt" "os" "path/filepath" "github.com/aquasecurity/trivy/pkg/cache" - trivydb "github.com/aquasecurity/trivy/pkg/db" - trivyjavadb "github.com/aquasecurity/trivy/pkg/javadb" "github.com/google/subcommands" "github.com/k0kubun/pp" "golang.org/x/xerrors" @@ -183,13 +180,13 @@ func (p *ReportCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&config.Conf.TrivyCacheDBDir, "trivy-cachedb-dir", cache.DefaultDir(), "/path/to/dir") - config.Conf.TrivyOpts.TrivyDBRepositories = []string{trivydb.DefaultGHCRRepository} + config.Conf.TrivyOpts.TrivyDBRepositories = config.DefaultTrivyDBRepositories dbRepos := stringArrayFlag{target: &config.Conf.TrivyOpts.TrivyDBRepositories} - f.Var(&dbRepos, "trivy-db-repository", fmt.Sprintf("Trivy DB Repository in a comma-separated list (default %s)", trivydb.DefaultGHCRRepository)) + f.Var(&dbRepos, "trivy-db-repository", "Trivy DB Repository in a comma-separated list") - config.Conf.TrivyOpts.TrivyJavaDBRepositories = []string{trivyjavadb.DefaultGHCRRepository} + config.Conf.TrivyOpts.TrivyJavaDBRepositories = config.DefaultTrivyJavaDBRepositories javaDBRepos := stringArrayFlag{target: &config.Conf.TrivyOpts.TrivyJavaDBRepositories} - f.Var(&javaDBRepos, "trivy-java-db-repository", fmt.Sprintf("Trivy Java DB Repository in a comma-separated list (default %s)", trivyjavadb.DefaultGHCRRepository)) + f.Var(&javaDBRepos, "trivy-java-db-repository", "Trivy Java DB Repository in a comma-separated list") f.BoolVar(&config.Conf.TrivySkipJavaDBUpdate, "trivy-skip-java-db-update", false, "Skip Trivy Java DB Update") } diff --git a/subcmds/report_windows.go b/subcmds/report_windows.go index e3325e65b5..0f3fda1332 100644 --- a/subcmds/report_windows.go +++ b/subcmds/report_windows.go @@ -5,13 +5,10 @@ package subcmds import ( "context" "flag" - "fmt" "os" "path/filepath" "github.com/aquasecurity/trivy/pkg/cache" - trivydb "github.com/aquasecurity/trivy/pkg/db" - trivyjavadb "github.com/aquasecurity/trivy/pkg/javadb" "github.com/google/subcommands" "github.com/k0kubun/pp" @@ -180,13 +177,13 @@ func (p *ReportCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&config.Conf.TrivyCacheDBDir, "trivy-cachedb-dir", cache.DefaultDir(), "/path/to/dir") - config.Conf.TrivyOpts.TrivyDBRepositories = []string{trivydb.DefaultGHCRRepository} + config.Conf.TrivyOpts.TrivyDBRepositories = config.DefaultTrivyDBRepositories dbRepos := stringArrayFlag{target: &config.Conf.TrivyOpts.TrivyDBRepositories} - f.Var(&dbRepos, "trivy-db-repository", fmt.Sprintf("Trivy DB Repository in a comma-separated list (default %s)", trivydb.DefaultGHCRRepository)) + f.Var(&dbRepos, "trivy-db-repository", "Trivy DB Repository in a comma-separated list") - config.Conf.TrivyOpts.TrivyJavaDBRepositories = []string{trivyjavadb.DefaultGHCRRepository} + config.Conf.TrivyOpts.TrivyJavaDBRepositories = config.DefaultTrivyJavaDBRepositories javaDBRepos := stringArrayFlag{target: &config.Conf.TrivyOpts.TrivyJavaDBRepositories} - f.Var(&javaDBRepos, "trivy-java-db-repository", fmt.Sprintf("Trivy Java DB Repository in a comma-separated list (default %s)", trivyjavadb.DefaultGHCRRepository)) + f.Var(&javaDBRepos, "trivy-java-db-repository", "Trivy Java DB Repository in a comma-separated list") f.BoolVar(&config.Conf.TrivySkipJavaDBUpdate, "trivy-skip-java-db-update", false, "Skip Trivy Java DB Update") } diff --git a/subcmds/tui.go b/subcmds/tui.go index 4c3d64cd2d..d255e71980 100644 --- a/subcmds/tui.go +++ b/subcmds/tui.go @@ -6,13 +6,10 @@ package subcmds import ( "context" "flag" - "fmt" "os" "path/filepath" "github.com/aquasecurity/trivy/pkg/cache" - trivydb "github.com/aquasecurity/trivy/pkg/db" - trivyjavadb "github.com/aquasecurity/trivy/pkg/javadb" "github.com/google/subcommands" "github.com/future-architect/vuls/config" @@ -112,13 +109,13 @@ func (p *TuiCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&config.Conf.TrivyCacheDBDir, "trivy-cachedb-dir", cache.DefaultDir(), "/path/to/dir") - config.Conf.TrivyOpts.TrivyDBRepositories = []string{trivydb.DefaultGHCRRepository} + config.Conf.TrivyOpts.TrivyDBRepositories = config.DefaultTrivyDBRepositories dbRepos := stringArrayFlag{target: &config.Conf.TrivyOpts.TrivyDBRepositories} - f.Var(&dbRepos, "trivy-db-repository", fmt.Sprintf("Trivy DB Repository in a comma-separated list (default %s)", trivydb.DefaultGHCRRepository)) + f.Var(&dbRepos, "trivy-db-repository", "Trivy DB Repository in a comma-separated list") - config.Conf.TrivyOpts.TrivyJavaDBRepositories = []string{trivyjavadb.DefaultGHCRRepository} + config.Conf.TrivyOpts.TrivyJavaDBRepositories = config.DefaultTrivyJavaDBRepositories javaDBRepos := stringArrayFlag{target: &config.Conf.TrivyOpts.TrivyJavaDBRepositories} - f.Var(&javaDBRepos, "trivy-java-db-repository", fmt.Sprintf("Trivy Java DB Repository in a comma-separated list (default %s)", trivyjavadb.DefaultGHCRRepository)) + f.Var(&javaDBRepos, "trivy-java-db-repository", "Trivy Java DB Repository in a comma-separated list") f.BoolVar(&config.Conf.TrivySkipJavaDBUpdate, "trivy-skip-java-db-update", false, "Skip Trivy Java DB Update") }