Skip to content

Commit

Permalink
Import of provisioners from private OCI registry/image
Browse files Browse the repository at this point in the history
Signed-off-by: 7h3-3mp7y-m4n <[email protected]>
  • Loading branch information
7h3-3mp7y-m4n committed Nov 19, 2024
1 parent 20d69ce commit b9184e8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 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 @@ -250,17 +253,27 @@ 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.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

0 comments on commit b9184e8

Please sign in to comment.