Skip to content

Commit

Permalink
feat(db): allow passing registry options (#5226)
Browse files Browse the repository at this point in the history
* feat(db): allow passing registry options

Signed-off-by: Michel Meyer <[email protected]>

* feat(db): pass cli registry options to javaDB

---------

Signed-off-by: Michel Meyer <[email protected]>
  • Loading branch information
mymichu authored Sep 27, 2023
1 parent 5b4652d commit 908a491
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/commands/artifact/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (r *runner) initJavaDB(opts flag.Options) error {

// Update the Java DB
noProgress := opts.Quiet || opts.NoProgress
javadb.Init(opts.CacheDir, opts.JavaDBRepository, opts.SkipJavaDBUpdate, noProgress, opts.Insecure)
javadb.Init(opts.CacheDir, opts.JavaDBRepository, opts.SkipJavaDBUpdate, noProgress, opts.RegistryOpts())
if opts.DownloadJavaDBOnly {
if err := javadb.Update(); err != nil {
return xerrors.Errorf("Java DB error: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func TestAnalyzerGroup_PostAnalyze(t *testing.T) {

if tt.analyzerType == analyzer.TypeJar {
// init java-trivy-db with skip update
javadb.Init("./language/java/jar/testdata", "ghcr.io/aquasecurity/trivy-java-db", true, false, false)
javadb.Init("./language/java/jar/testdata", "ghcr.io/aquasecurity/trivy-java-db", true, false, types.RegistryOptions{Insecure: false})
}

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/java/jar/jar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func Test_javaLibraryAnalyzer_Analyze(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// init java-trivy-db with skip update
javadb.Init("testdata", defaultJavaDBRepository, true, false, false)
javadb.Init("testdata", defaultJavaDBRepository, true, false, types.RegistryOptions{Insecure: false})

a := javaLibraryAnalyzer{slow: true}
ctx := context.Background()
Expand Down
24 changes: 12 additions & 12 deletions pkg/javadb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const (
var updater *Updater

type Updater struct {
repo string
dbDir string
skip bool
quiet bool
insecure bool
repo string
dbDir string
skip bool
quiet bool
registryOption ftypes.RegistryOptions
}

func (u *Updater) Update() error {
Expand All @@ -54,7 +54,7 @@ func (u *Updater) Update() error {

// TODO: support remote options
var a *oci.Artifact
if a, err = oci.NewArtifact(u.repo, u.quiet, ftypes.RegistryOptions{Insecure: u.insecure}); err != nil {
if a, err = oci.NewArtifact(u.repo, u.quiet, u.registryOption); err != nil {
return xerrors.Errorf("oci error: %w", err)
}
if err = a.Download(context.Background(), dbDir, oci.DownloadOption{MediaType: mediaType}); err != nil {
Expand All @@ -79,13 +79,13 @@ func (u *Updater) Update() error {
return nil
}

func Init(cacheDir string, javaDBRepository string, skip, quiet, insecure bool) {
func Init(cacheDir string, javaDBRepository string, skip, quiet bool, registryOption ftypes.RegistryOptions) {
updater = &Updater{
repo: fmt.Sprintf("%s:%d", javaDBRepository, db.SchemaVersion),
dbDir: filepath.Join(cacheDir, "java-db"),
skip: skip,
quiet: quiet,
insecure: insecure,
repo: fmt.Sprintf("%s:%d", javaDBRepository, db.SchemaVersion),
dbDir: filepath.Join(cacheDir, "java-db"),
skip: skip,
quiet: quiet,
registryOption: registryOption,
}
}

Expand Down

0 comments on commit 908a491

Please sign in to comment.