Skip to content

Commit 908a491

Browse files
authored
feat(db): allow passing registry options (#5226)
* 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]>
1 parent 5b4652d commit 908a491

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

pkg/commands/artifact/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (r *runner) initJavaDB(opts flag.Options) error {
329329

330330
// Update the Java DB
331331
noProgress := opts.Quiet || opts.NoProgress
332-
javadb.Init(opts.CacheDir, opts.JavaDBRepository, opts.SkipJavaDBUpdate, noProgress, opts.Insecure)
332+
javadb.Init(opts.CacheDir, opts.JavaDBRepository, opts.SkipJavaDBUpdate, noProgress, opts.RegistryOpts())
333333
if opts.DownloadJavaDBOnly {
334334
if err := javadb.Update(); err != nil {
335335
return xerrors.Errorf("Java DB error: %w", err)

pkg/fanal/analyzer/analyzer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ func TestAnalyzerGroup_PostAnalyze(t *testing.T) {
614614

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

620620
ctx := context.Background()

pkg/fanal/analyzer/language/java/jar/jar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func Test_javaLibraryAnalyzer_Analyze(t *testing.T) {
130130
for _, tt := range tests {
131131
t.Run(tt.name, func(t *testing.T) {
132132
// init java-trivy-db with skip update
133-
javadb.Init("testdata", defaultJavaDBRepository, true, false, false)
133+
javadb.Init("testdata", defaultJavaDBRepository, true, false, types.RegistryOptions{Insecure: false})
134134

135135
a := javaLibraryAnalyzer{slow: true}
136136
ctx := context.Background()

pkg/javadb/client.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const (
2626
var updater *Updater
2727

2828
type Updater struct {
29-
repo string
30-
dbDir string
31-
skip bool
32-
quiet bool
33-
insecure bool
29+
repo string
30+
dbDir string
31+
skip bool
32+
quiet bool
33+
registryOption ftypes.RegistryOptions
3434
}
3535

3636
func (u *Updater) Update() error {
@@ -54,7 +54,7 @@ func (u *Updater) Update() error {
5454

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

82-
func Init(cacheDir string, javaDBRepository string, skip, quiet, insecure bool) {
82+
func Init(cacheDir string, javaDBRepository string, skip, quiet bool, registryOption ftypes.RegistryOptions) {
8383
updater = &Updater{
84-
repo: fmt.Sprintf("%s:%d", javaDBRepository, db.SchemaVersion),
85-
dbDir: filepath.Join(cacheDir, "java-db"),
86-
skip: skip,
87-
quiet: quiet,
88-
insecure: insecure,
84+
repo: fmt.Sprintf("%s:%d", javaDBRepository, db.SchemaVersion),
85+
dbDir: filepath.Join(cacheDir, "java-db"),
86+
skip: skip,
87+
quiet: quiet,
88+
registryOption: registryOption,
8989
}
9090
}
9191

0 commit comments

Comments
 (0)