feat(db): allow passing registry options (#5226)

* feat(db): allow passing registry options

Signed-off-by: Michel Meyer <meyer_michel@outlook.com>

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

---------

Signed-off-by: Michel Meyer <meyer_michel@outlook.com>
This commit is contained in:
Michel Meyer
2023-09-27 15:17:11 +02:00
committed by GitHub
parent 5b4652d796
commit 908a4914c7
4 changed files with 15 additions and 15 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -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()

View File

@@ -30,7 +30,7 @@ type Updater struct {
dbDir string
skip bool
quiet bool
insecure bool
registryOption ftypes.RegistryOptions
}
func (u *Updater) Update() error {
@@ -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 {
@@ -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,
registryOption: registryOption,
}
}