ensure consistency in registry client Push/Pull function signatures. ensure message is only printed when tags contain a replaced character

Signed-off-by: Josh Wolf <josh@wolfs.io>
pull/10521/head
Josh Wolf 3 years ago
parent 157ac85ab7
commit fed0d31bf5

@ -213,8 +213,8 @@ type (
) )
// Pull downloads a chart from a registry // Pull downloads a chart from a registry
func (c *Client) Pull(rawRef string, options ...PullOption) (*PullResult, error) { func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
ref, err := parseReference(rawRef) parsedRef, err := parseReference(ref)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -248,7 +248,7 @@ func (c *Client) Pull(rawRef string, options ...PullOption) (*PullResult, error)
var descriptors, layers []ocispec.Descriptor var descriptors, layers []ocispec.Descriptor
registryStore := content.Registry{Resolver: c.resolver} registryStore := content.Registry{Resolver: c.resolver}
manifest, err := oras.Copy(ctx(c.out, c.debug), registryStore, ref.String(), memoryStore, "", manifest, err := oras.Copy(ctx(c.out, c.debug), registryStore, parsedRef.String(), memoryStore, "",
oras.WithPullEmptyNameAllowed(), oras.WithPullEmptyNameAllowed(),
oras.WithAllowedMediaTypes(allowedMediaTypes), oras.WithAllowedMediaTypes(allowedMediaTypes),
oras.WithLayerDescriptors(func(l []ocispec.Descriptor) { oras.WithLayerDescriptors(func(l []ocispec.Descriptor) {
@ -314,7 +314,7 @@ func (c *Client) Pull(rawRef string, options ...PullOption) (*PullResult, error)
}, },
Chart: &descriptorPullSummaryWithMeta{}, Chart: &descriptorPullSummaryWithMeta{},
Prov: &descriptorPullSummary{}, Prov: &descriptorPullSummary{},
Ref: ref.String(), Ref: parsedRef.String(),
} }
var getManifestErr error var getManifestErr error
if _, manifestData, ok := memoryStore.Get(manifest); !ok { if _, manifestData, ok := memoryStore.Get(manifest); !ok {
@ -428,8 +428,8 @@ type (
) )
// Push uploads a chart to a registry. // Push uploads a chart to a registry.
func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushResult, error) { func (c *Client) Push(data []byte, ref string, options ...PushOption) (*PushResult, error) {
ref, err := parseReference(rawRef) parsedRef, err := parseReference(ref)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -445,7 +445,7 @@ func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushR
return nil, err return nil, err
} }
if operation.strictMode { if operation.strictMode {
if !strings.HasSuffix(rawRef, fmt.Sprintf("/%s:%s", meta.Name, meta.Version)) { if !strings.HasSuffix(ref, fmt.Sprintf("/%s:%s", meta.Name, meta.Version)) {
return nil, errors.New( return nil, errors.New(
"strict mode enabled, ref basename and tag must match the chart name and version") "strict mode enabled, ref basename and tag must match the chart name and version")
} }
@ -482,12 +482,12 @@ func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushR
return nil, err return nil, err
} }
if err := memoryStore.StoreManifest(ref.String(), manifest, manifestData); err != nil { if err := memoryStore.StoreManifest(parsedRef.String(), manifest, manifestData); err != nil {
return nil, err return nil, err
} }
registryStore := content.Registry{Resolver: c.resolver} registryStore := content.Registry{Resolver: c.resolver}
_, err = oras.Copy(ctx(c.out, c.debug), memoryStore, ref.String(), registryStore, "", _, err = oras.Copy(ctx(c.out, c.debug), memoryStore, parsedRef.String(), registryStore, "",
oras.WithNameValidation(nil)) oras.WithNameValidation(nil))
if err != nil { if err != nil {
return nil, err return nil, err
@ -508,7 +508,7 @@ func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushR
}, },
Chart: chartSummary, Chart: chartSummary,
Prov: &descriptorPushSummary{}, // prevent nil references Prov: &descriptorPushSummary{}, // prevent nil references
Ref: ref.String(), Ref: parsedRef.String(),
} }
if operation.provData != nil { if operation.provData != nil {
result.Prov = &descriptorPushSummary{ result.Prov = &descriptorPushSummary{
@ -518,7 +518,7 @@ func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushR
} }
fmt.Fprintf(c.out, "Pushed: %s\n", result.Ref) fmt.Fprintf(c.out, "Pushed: %s\n", result.Ref)
fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest) fmt.Fprintf(c.out, "Digest: %s\n", result.Manifest.Digest)
if strings.Contains(result.Ref, "_") { if strings.Contains(parsedRef.Reference, "_") {
fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref) fmt.Fprintf(c.out, "%s contains an underscore.\n", result.Ref)
fmt.Fprint(c.out, registryUnderscoreMessage+"\n") fmt.Fprint(c.out, registryUnderscoreMessage+"\n")
} }

Loading…
Cancel
Save