MCPcopy Create free account
hub / github.com/conforma/cli / NewImageReference

Function NewImageReference

internal/image/process.go:121–145  ·  view source on GitHub ↗

NewImageReference returns an ImageReference instance based on the given url.

(url string, opts ...name.Option)

Source from the content-addressed store, hash-verified

119
120// NewImageReference returns an ImageReference instance based on the given url.
121func NewImageReference(url string, opts ...name.Option) (*ImageReference, error) {
122 ref, err := name.ParseReference(url, opts...)
123 if err != nil {
124 return nil, err
125 }
126 imageRef := &ImageReference{ref: ref}
127
128 // An image reference may contain both a tag and a digest. However, the parsing library
129 // will drop the tag in favor of the digest. Since we care about the value of the tag,
130 // parse the url without the digest reference to force the library to retain the tag
131 // value in all cases where it is present.
132 tagRef, err := name.NewTag(strings.Split(url, "@")[0], opts...)
133 if err == nil {
134 imageRef.Tag = tagRef.TagStr()
135 imageRef.Repository = tagRef.Context().Name()
136 }
137
138 digestRef, err := name.NewDigest(url, opts...)
139 if err == nil {
140 imageRef.Digest = digestRef.DigestStr()
141 imageRef.Repository = digestRef.Context().Name()
142 }
143
144 return imageRef, nil
145}
146
147func (i ImageReference) Ref() name.Reference {
148 return i.ref

Callers 3

TestImageReferenceRefFunction · 0.85
ParseAndResolveFunction · 0.85
resolveDigestMethod · 0.85

Calls 1

NameMethod · 0.65

Tested by 1

TestImageReferenceRefFunction · 0.68