MCPcopy Create free account
hub / github.com/containerd/nerdctl / Parse

Function Parse

pkg/referenceutil/referenceutil.go:96–146  ·  view source on GitHub ↗
(rawRef string)

Source from the content-addressed store, hash-verified

94}
95
96func Parse(rawRef string) (*ImageReference, error) {
97 ir := &ImageReference{}
98
99 if strings.HasPrefix(rawRef, "ipfs://") {
100 ir.Protocol = IPFSProtocol
101 rawRef = rawRef[7:]
102 } else if strings.HasPrefix(rawRef, "ipns://") {
103 ir.Protocol = IPNSProtocol
104 rawRef = rawRef[7:]
105 } else if strings.HasPrefix(rawRef, "oci-archive://") {
106 // The image must be loaded from the specified archive path first
107 // before parsing the image reference specified in its OCI image manifest.
108 return nil, ErrLoadOCIArchiveRequired
109 }
110 if decodedCID, err := decodeCid(rawRef); err == nil {
111 ir.Protocol = IPFSProtocol
112 rawRef = decodedCID
113 ir.Path = rawRef
114 return ir, nil
115 }
116
117 if dgst, err := digest.Parse(rawRef); err == nil {
118 ir.Digest = dgst
119 return ir, nil
120 } else if dgst, err := digest.Parse("sha256:" + rawRef); err == nil {
121 ir.Digest = dgst
122 return ir, nil
123 }
124
125 var err error
126 ir.nn, err = reference.ParseNormalizedNamed(rawRef)
127 if err != nil {
128 return ir, err
129 }
130 if tg, ok := ir.nn.(reference.Tagged); ok {
131 ir.ExplicitTag = tg.Tag()
132 }
133 if tg, ok := ir.nn.(reference.Named); ok {
134 ir.nn = reference.TagNameOnly(tg)
135 ir.Domain = reference.Domain(tg)
136 ir.Path = reference.Path(tg)
137 }
138 if tg, ok := ir.nn.(reference.Tagged); ok {
139 ir.Tag = tg.Tag()
140 }
141 if tg, ok := ir.nn.(reference.Digested); ok {
142 ir.Digest = tg.Digest()
143 }
144
145 return ir, nil
146}

Callers 15

WalkMethod · 0.92
WalkCriRmMethod · 0.92
ParseFiltersFunction · 0.92
matchesReferencesFunction · 0.92
EnsureImageFunction · 0.92
ResolveDigestFunction · 0.92
ParseRepoTagFunction · 0.92
CommitFunction · 0.92
CreateFunction · 0.92
ConvertFunction · 0.92
PushFunction · 0.92
inspectIdentifierFunction · 0.92

Calls 3

decodeCidFunction · 0.70
ParseMethod · 0.65
PathMethod · 0.65

Tested by 5

TestImagesFunction · 0.74
TestImagesFilterFunction · 0.74
TestBuilderFunction · 0.74
TestComposeImagesFunction · 0.74
TestReferenceUtilFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…