Skip to content

Commit

Permalink
adding #Save, #Add, #Push test scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed Apr 13, 2024
1 parent 0f3054e commit c87bd7a
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 66 deletions.
29 changes: 24 additions & 5 deletions cnb_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ func (h *CNBIndex) setImageURLs(img v1.Image, hash v1.Hash, urls []string) error
//
// If referencing an ImageIndex, will add Platform Specific Image from the Index.
// Use IndexAddOptions to alter behaviour for ImageIndex Reference.
func (h *CNBIndex) Add(ref name.Reference, ops ...func(*IndexAddOptions) error) error {
func (h *CNBIndex) Add(name string, ops ...func(*IndexAddOptions) error) error {
var addOps = &IndexAddOptions{}
for _, op := range ops {
op(addOps)
Expand Down Expand Up @@ -1175,10 +1175,10 @@ func (h *CNBIndex) Add(ref name.Reference, ops ...func(*IndexAddOptions) error)
//
// This call is returns a v1.Descriptor with `Size`, `MediaType`, `Digest` fields only!!
// This is a lightweight call used for checking MediaType of given Reference
ref, auth, err := referenceForRepoName(h.KeyChain, name, h.Insecure)

Check failure on line 1178 in cnb_index.go

View workflow job for this annotation

GitHub Actions / test-and-build-linux

ineffectual assignment to err (ineffassign)

Check failure on line 1178 in cnb_index.go

View workflow job for this annotation

GitHub Actions / test-and-build-windows

ineffectual assignment to err (ineffassign)
desc, err := remote.Head(
ref,
remote.WithAuthFromKeychain(h.KeyChain),
remote.WithTransport(GetTransport(h.Insecure)),
remote.WithAuth(auth),
)
if err != nil {
return err
Expand All @@ -1193,8 +1193,7 @@ func (h *CNBIndex) Add(ref name.Reference, ops ...func(*IndexAddOptions) error)
// Get the Full Image from remote if the given Reference refers an Image
img, err := remote.Image(
ref,
remote.WithAuthFromKeychain(h.KeyChain),
remote.WithTransport(GetTransport(h.Insecure)),
remote.WithAuth(auth),
)
if err != nil {
return err
Expand Down Expand Up @@ -1957,3 +1956,23 @@ func indexMediaType(format types.MediaType) string {
return "UNKNOWN"
}
}

// TODO this method is duplicated from remote.new file
// referenceForRepoName
func referenceForRepoName(keychain authn.Keychain, ref string, insecure bool) (name.Reference, authn.Authenticator, error) {
var auth authn.Authenticator
opts := []name.Option{name.WeakValidation}
if insecure {
opts = append(opts, name.Insecure)
}
r, err := name.ParseReference(ref, opts...)
if err != nil {
return nil, nil, err
}

auth, err = keychain.Resolve(r.Context().Registry)
if err != nil {
return nil, nil, err
}
return r, auth, nil
}
25 changes: 12 additions & 13 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,32 @@ import (
type ImageIndex interface {
// getters

OS(digest name.Digest) (os string, err error)
Annotations(digest name.Digest) (annotations map[string]string, err error)
Architecture(digest name.Digest) (arch string, err error)
Variant(digest name.Digest) (osVariant string, err error)
OSVersion(digest name.Digest) (osVersion string, err error)
Features(digest name.Digest) (features []string, err error)
OS(digest name.Digest) (os string, err error)
OSFeatures(digest name.Digest) (osFeatures []string, err error)
Annotations(digest name.Digest) (annotations map[string]string, err error)
OSVersion(digest name.Digest) (osVersion string, err error)
URLs(digest name.Digest) (urls []string, err error)
Variant(digest name.Digest) (osVariant string, err error)

// setters

SetOS(digest name.Digest, os string) error
SetAnnotations(digest name.Digest, annotations map[string]string) error
SetArchitecture(digest name.Digest, arch string) error
SetVariant(digest name.Digest, osVariant string) error
SetOSVersion(digest name.Digest, osVersion string) error
SetFeatures(digest name.Digest, features []string) error
SetOS(digest name.Digest, os string) error
SetOSFeatures(digest name.Digest, osFeatures []string) error
SetAnnotations(digest name.Digest, annotations map[string]string) error
SetOSVersion(digest name.Digest, osVersion string) error
SetURLs(digest name.Digest, urls []string) error
SetVariant(digest name.Digest, osVariant string) error

// misc

// TODO change the name.Reference and expose String?
Add(ref name.Reference, ops ...func(options *IndexAddOptions) error) error
Save() error
Push(ops ...func(options *IndexPushOptions) error) error
Add(repoName string, ops ...func(options *IndexAddOptions) error) error
Delete() error
Inspect() (string, error)
Push(ops ...func(options *IndexPushOptions) error) error
Remove(ref name.Reference) error
Delete() error
Save() error
}
Loading

0 comments on commit c87bd7a

Please sign in to comment.