MCPcopy Create free account
hub / github.com/containers/image / Parse

Function Parse

docker/reference/reference.go:189–234  ·  view source on GitHub ↗

Parse parses s and returns a syntactically valid Reference. If an error was encountered it is returned, along with a nil Reference. NOTE: Parse will not handle short digests.

(s string)

Source from the content-addressed store, hash-verified

187// If an error was encountered it is returned, along with a nil Reference.
188// NOTE: Parse will not handle short digests.
189func Parse(s string) (Reference, error) {
190 matches := ReferenceRegexp.FindStringSubmatch(s)
191 if matches == nil {
192 if s == "" {
193 return nil, ErrNameEmpty
194 }
195 if ReferenceRegexp.FindStringSubmatch(strings.ToLower(s)) != nil {
196 return nil, ErrNameContainsUppercase
197 }
198 return nil, ErrReferenceInvalidFormat
199 }
200
201 if len(matches[1]) > NameTotalLengthMax {
202 return nil, ErrNameTooLong
203 }
204
205 var repo repository
206
207 nameMatch := anchoredNameRegexp.FindStringSubmatch(matches[1])
208 if len(nameMatch) == 3 {
209 repo.domain = nameMatch[1]
210 repo.path = nameMatch[2]
211 } else {
212 repo.domain = ""
213 repo.path = matches[1]
214 }
215
216 ref := reference{
217 namedRepository: repo,
218 tag: matches[2],
219 }
220 if matches[3] != "" {
221 var err error
222 ref.digest, err = digest.Parse(matches[3])
223 if err != nil {
224 return nil, err
225 }
226 }
227
228 r := getBestReferenceType(ref)
229 if r == nil {
230 return nil, ErrNameEmpty
231 }
232
233 return r, nil
234}
235
236// ParseNamed parses s and returns a syntactically valid reference implementing
237// the Named interface. The reference must have a name and be in the canonical

Callers 9

toNamedFunction · 0.92
parseShortNameValueFunction · 0.92
validateShortNameFunction · 0.92
ParseNormalizedNamedFunction · 0.85
UnmarshalTextMethod · 0.85
TestReferenceParseFunction · 0.85
TestParseAnyReferenceFunction · 0.85
TestParseDockerRefFunction · 0.85

Calls 2

getBestReferenceTypeFunction · 0.85
FindStringSubmatchMethod · 0.80

Tested by 4

toNamedFunction · 0.74
TestReferenceParseFunction · 0.68
TestParseAnyReferenceFunction · 0.68
TestParseDockerRefFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…