mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-21 23:00:42 -08:00
feat: add auth support for downloading OCI artifacts (#3915)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/google/go-containerregistry/pkg/name"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
"github.com/aquasecurity/trivy/pkg/oci"
|
||||
)
|
||||
@@ -15,14 +16,14 @@ import (
|
||||
const mediaType = "application/vnd.module.wasm.content.layer.v1+wasm"
|
||||
|
||||
// Install installs a module
|
||||
func Install(ctx context.Context, dir, repo string, quiet, insecure bool) error {
|
||||
func Install(ctx context.Context, dir, repo string, quiet bool, opt types.RemoteOptions) error {
|
||||
ref, err := name.ParseReference(repo)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("repository parse error: %w", err)
|
||||
}
|
||||
|
||||
log.Logger.Infof("Installing the module from %s...", repo)
|
||||
artifact, err := oci.NewArtifact(repo, mediaType, "", quiet, insecure)
|
||||
artifact, err := oci.NewArtifact(repo, quiet, opt)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("module initialize error: %w", err)
|
||||
}
|
||||
@@ -30,7 +31,7 @@ func Install(ctx context.Context, dir, repo string, quiet, insecure bool) error
|
||||
dst := filepath.Join(dir, ref.Context().Name())
|
||||
log.Logger.Debugf("Installing the module to %s...", dst)
|
||||
|
||||
if err = artifact.Download(ctx, dst); err != nil {
|
||||
if err = artifact.Download(ctx, dst, oci.DownloadOption{MediaType: mediaType}); err != nil {
|
||||
return xerrors.Errorf("module download error: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user