Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion uriget/uriget.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/registry"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras-go/v2/registry/remote/auth"
"oras.land/oras-go/v2/registry/remote/credentials"
"oras.land/oras-go/v2/registry/remote/retry"
)

// options is a struct holding fields that may need to have overrides in certain environments or during unit testing.
Expand Down Expand Up @@ -278,17 +281,28 @@ func (o *options) getOci(ctx context.Context, u *url.URL) ([]byte, error) {
ref.Reference = "latest"
}
specifiedFile := strings.TrimPrefix(u.Fragment, "#")
storeOpts := credentials.StoreOptions{}
credStore, err := credentials.NewStoreFromDocker(storeOpts)
if err != nil {
o.logger.Printf("Warning: Unable to load Docker credentials, continuing without auth. Error: %v", err)
}
remoteRepo, err := remote.NewRepository(ref.String())
if err != nil {
return nil, fmt.Errorf("connection to remote repository failed: %w", err)
}
remoteRepo.PlainHTTP = strings.HasPrefix(ref.Registry, "localhost") || strings.HasPrefix(ref.Registry, "127.0.0.1")
remoteRepo.Client = &auth.Client{
Client: retry.DefaultClient,
Cache: auth.NewCache(),
Credential: credentials.Credential(credStore),
}
_, rc, err := remoteRepo.Manifests().FetchReference(ctx, ref.Reference)
if err != nil {
return nil, fmt.Errorf("manifest fetch failed: %w", err)
}
defer rc.Close()
var manifest v1.Manifest
if err = json.NewDecoder(rc).Decode(&manifest); err != nil {
if err := json.NewDecoder(rc).Decode(&manifest); err != nil {
return nil, fmt.Errorf("manifest decode failed: %w", err)
}
var selectedLayer *v1.Descriptor
Expand Down