in scan/context.go [143:182]
func (s *Scanner) getContextFromRegistry(ctx context.Context, registryArtifact string) (err error) {
src, err := remote.NewRepository(registryArtifact)
if err != nil {
return errors.Wrapf(err, "failed to parse artifact %s", registryArtifact)
}
src.Client = &auth.Client{
Header: http.Header{
"User-Agent": {"oras-go"},
"X-Meta-Source-Client": {"azure/acr/tasks"},
},
Cache: auth.DefaultCache,
Credential: func(_ context.Context, registry string) (auth.Credential, error) {
// If no matching credential found, attempt an anonymous pull
if s.credentials[registry] == nil {
return auth.EmptyCredential, nil
}
return auth.Credential{
Username: s.credentials[registry].Username.ResolvedValue,
Password: s.credentials[registry].Password.ResolvedValue,
}, nil
},
}
dest, err := file.New(s.destinationFolder)
if err != nil {
return errors.Wrapf(err, "unable to pull artifact to %s", s.destinationFolder)
}
defer dest.Close()
fmt.Printf("Pulling from %s and saving to %s...\n", registryArtifact, s.destinationFolder)
desc, err := oras.Copy(ctx, src, src.Reference.Reference, dest, "", oras.DefaultCopyOptions)
if err != nil {
return errors.Wrap(err, "failed to pull artifact from registry")
}
fmt.Printf("Pulled from %s with digest %s\n", registryArtifact, desc.Digest)
return nil
}