mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 15:16:33 -08:00
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:
@@ -329,7 +329,7 @@ func (r *runner) initJavaDB(opts flag.Options) error {
|
|||||||
|
|
||||||
// Update the Java DB
|
// Update the Java DB
|
||||||
noProgress := opts.Quiet || opts.NoProgress
|
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 opts.DownloadJavaDBOnly {
|
||||||
if err := javadb.Update(); err != nil {
|
if err := javadb.Update(); err != nil {
|
||||||
return xerrors.Errorf("Java DB error: %w", err)
|
return xerrors.Errorf("Java DB error: %w", err)
|
||||||
|
|||||||
@@ -614,7 +614,7 @@ func TestAnalyzerGroup_PostAnalyze(t *testing.T) {
|
|||||||
|
|
||||||
if tt.analyzerType == analyzer.TypeJar {
|
if tt.analyzerType == analyzer.TypeJar {
|
||||||
// init java-trivy-db with skip update
|
// 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()
|
ctx := context.Background()
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ func Test_javaLibraryAnalyzer_Analyze(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// init java-trivy-db with skip update
|
// 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}
|
a := javaLibraryAnalyzer{slow: true}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ const (
|
|||||||
var updater *Updater
|
var updater *Updater
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
repo string
|
repo string
|
||||||
dbDir string
|
dbDir string
|
||||||
skip bool
|
skip bool
|
||||||
quiet bool
|
quiet bool
|
||||||
insecure bool
|
registryOption ftypes.RegistryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Updater) Update() error {
|
func (u *Updater) Update() error {
|
||||||
@@ -54,7 +54,7 @@ func (u *Updater) Update() error {
|
|||||||
|
|
||||||
// TODO: support remote options
|
// TODO: support remote options
|
||||||
var a *oci.Artifact
|
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)
|
return xerrors.Errorf("oci error: %w", err)
|
||||||
}
|
}
|
||||||
if err = a.Download(context.Background(), dbDir, oci.DownloadOption{MediaType: mediaType}); err != nil {
|
if err = a.Download(context.Background(), dbDir, oci.DownloadOption{MediaType: mediaType}); err != nil {
|
||||||
@@ -79,13 +79,13 @@ func (u *Updater) Update() error {
|
|||||||
return nil
|
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{
|
updater = &Updater{
|
||||||
repo: fmt.Sprintf("%s:%d", javaDBRepository, db.SchemaVersion),
|
repo: fmt.Sprintf("%s:%d", javaDBRepository, db.SchemaVersion),
|
||||||
dbDir: filepath.Join(cacheDir, "java-db"),
|
dbDir: filepath.Join(cacheDir, "java-db"),
|
||||||
skip: skip,
|
skip: skip,
|
||||||
quiet: quiet,
|
quiet: quiet,
|
||||||
insecure: insecure,
|
registryOption: registryOption,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user