Skip to content

Commit

Permalink
fix the nil and the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Dec 10, 2024
1 parent 82c5607 commit 24aacad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
19 changes: 13 additions & 6 deletions api/oci/extensions/repositories/ocireg/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,23 @@ func (r *RepositoryImpl) getResolver(comp string) (regclient.Resolver, error) {
logger.Trace("no credentials")
}

pass := creds.GetProperty(credentials.ATTR_IDENTITY_TOKEN)
if pass == "" {
pass = creds.GetProperty(credentials.ATTR_PASSWORD)
var (
password, username string
)

if creds != nil {
password = creds.GetProperty(credentials.ATTR_IDENTITY_TOKEN)
if password == "" {
password = creds.GetProperty(credentials.ATTR_PASSWORD)
}
username = creds.GetProperty(credentials.ATTR_USERNAME)
}
username := creds.GetProperty(credentials.ATTR_USERNAME)

opts := regclient.ClientOptions{
Host: &regconfig.Host{
Name: "ghcr.io",
Name: "ghcr.io", //TODO: Need to figure out how to set the host.
User: username,
Pass: pass,
Pass: password,
},
Version: comp,
}
Expand Down
12 changes: 8 additions & 4 deletions api/tech/regclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,15 @@ func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descrip
if strings.Contains(err.Error(), "not found") {
// fallback to finding a blob if we have a digest
if r.Digest != "" {
blob, err := c.rc.BlobHead(ctx, r, descriptor.Descriptor{
blob, err := c.rc.BlobGet(ctx, r, descriptor.Descriptor{
Digest: digest.Digest(r.Digest),
Size: -1,
})
if err != nil {
if strings.Contains(err.Error(), "not found") {
return "", ociv1.Descriptor{}, errdefs.ErrNotFound
}

return "", ociv1.Descriptor{}, err
return "", ociv1.Descriptor{}, fmt.Errorf("failed to resolve blob head: %w", err)
}

return ref, c.convertDescriptorToOCI(blob.GetDescriptor()), nil
Expand Down Expand Up @@ -196,6 +195,7 @@ func (c *Client) Lister(ctx context.Context, ref string) (Lister, error) {
}

func (c *Client) Push(ctx context.Context, d ociv1.Descriptor, src Source) (PushRequest, error) {
fmt.Println("IN FUCKING PUSH: ", d)

Check failure on line 198 in api/tech/regclient/client.go

View workflow job for this annotation

GitHub Actions / Lint Golang

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
reader, err := src.Reader()
if err != nil {
return nil, err
Expand Down Expand Up @@ -249,9 +249,13 @@ func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (_ io.ReadClo
}()

// set up closing the client after fetching is done.
// -1 is not a thing in regclient.
if desc.Size < 0 {
desc.Size = 0
}
reader, err := c.rc.BlobGet(ctx, c.ref, c.convertDescriptorToRegClient(desc))
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get the blob reader: %w", err)
}

return reader, nil
Expand Down

0 comments on commit 24aacad

Please sign in to comment.