MCPcopy
hub / github.com/helm/helm / newReference

Function newReference

pkg/registry/reference.go:37–71  ·  view source on GitHub ↗

newReference will parse and validate the reference, and clean tags when applicable tags are only cleaned when plus (+) signs are present and are converted to underscores (_) before pushing See https://github.com/helm/helm/issues/10166

(raw string)

Source from the content-addressed store, hash-verified

35// converted to underscores (_) before pushing
36// See https://github.com/helm/helm/issues/10166
37func newReference(raw string) (result reference, err error) {
38 // Remove the oci:// prefix if it is there
39 raw = strings.TrimPrefix(raw, OCIScheme+"://")
40
41 // The sole possible reference modification is replacing plus (+) signs
42 // present in tags with underscores (_). To do this properly, we first
43 // need to identify a tag, and then pass it on to the reference parser
44 // NOTE: Passing immediately to the reference parser will fail since (+)
45 // signs are an invalid tag character, and simply replacing all plus (+)
46 // occurrences could invalidate other portions of the URI
47 lastIndex := strings.LastIndex(raw, "@")
48 if lastIndex >= 0 {
49 result.Digest = raw[(lastIndex + 1):]
50 raw = raw[:lastIndex]
51 }
52 parts := strings.Split(raw, ":")
53 if len(parts) > 1 && !strings.Contains(parts[len(parts)-1], "/") {
54 tag := parts[len(parts)-1]
55
56 if tag != "" {
57 // Replace any plus (+) signs with known underscore (_) conversion
58 newTag := strings.ReplaceAll(tag, "+", "_")
59 raw = strings.ReplaceAll(raw, tag, newTag)
60 }
61 }
62
63 result.orasReference, err = registry.ParseReference(raw)
64 if err != nil {
65 return result, err
66 }
67 result.Registry = result.orasReference.Registry
68 result.Repository = result.orasReference.Repository
69 result.Tag = result.orasReference.Reference
70 return result, nil
71}
72
73func (r *reference) String() string {
74 if r.Tag == "" {

Callers 7

TestNewReferenceFunction · 0.85
GetPluginNameFunction · 0.85
PullGenericMethod · 0.85
PushMethod · 0.85
ResolveMethod · 0.85
ValidateReferenceMethod · 0.85

Calls 1

ContainsMethod · 0.80

Tested by 2

TestNewReferenceFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…