Skip to content

Commit

Permalink
Use GCR and GHCR
Browse files Browse the repository at this point in the history
  • Loading branch information
shino committed Nov 26, 2024
1 parent 2cfb1a5 commit 5a4218c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"`
Expand Down
3 changes: 3 additions & 0 deletions detector/javadb/javadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...")

Expand Down
3 changes: 3 additions & 0 deletions detector/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 4 additions & 7 deletions subcmds/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
11 changes: 4 additions & 7 deletions subcmds/report_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
}
Expand Down
11 changes: 4 additions & 7 deletions subcmds/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 5a4218c

Please sign in to comment.