Skip to content

Commit

Permalink
ensure consistency in registry client Push/Pull function signatures. …
Browse files Browse the repository at this point in the history
…ensure message is only printed when tags contain a replaced character

Signed-off-by: Josh Wolf <josh@wolfs.io>
  • Loading branch information
joshrwolf committed Jan 10, 2022
1 parent 157ac85 commit fed0d31
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions internal/experimental/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ type (
)

// Pull downloads a chart from a registry
func (c *Client) Pull(rawRef string, options ...PullOption) (*PullResult, error) {
ref, err := parseReference(rawRef)
func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
parsedRef, err := parseReference(ref)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func (c *Client) Pull(rawRef string, options ...PullOption) (*PullResult, error)
var descriptors, layers []ocispec.Descriptor
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.WithAllowedMediaTypes(allowedMediaTypes),
oras.WithLayerDescriptors(func(l []ocispec.Descriptor) {
Expand Down Expand Up @@ -314,7 +314,7 @@ func (c *Client) Pull(rawRef string, options ...PullOption) (*PullResult, error)
},
Chart: &descriptorPullSummaryWithMeta{},
Prov: &descriptorPullSummary{},
Ref: ref.String(),
Ref: parsedRef.String(),
}
var getManifestErr error
if _, manifestData, ok := memoryStore.Get(manifest); !ok {
Expand Down Expand Up @@ -428,8 +428,8 @@ type (
)

// Push uploads a chart to a registry.
func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushResult, error) {
ref, err := parseReference(rawRef)
func (c *Client) Push(data []byte, ref string, options ...PushOption) (*PushResult, error) {
parsedRef, err := parseReference(ref)
if err != nil {
return nil, err
}
Expand All @@ -445,7 +445,7 @@ func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushR
return nil, err
}
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(
"strict mode enabled, ref basename and tag must match the chart name and version")
}
Expand Down Expand Up @@ -482,12 +482,12 @@ func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushR
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
}

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))
if err != nil {
return nil, err
Expand All @@ -508,7 +508,7 @@ func (c *Client) Push(data []byte, rawRef string, options ...PushOption) (*PushR
},
Chart: chartSummary,
Prov: &descriptorPushSummary{}, // prevent nil references
Ref: ref.String(),
Ref: parsedRef.String(),
}
if operation.provData != nil {
result.Prov = &descriptorPushSummary{
Expand All @@ -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, "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.Fprint(c.out, registryUnderscoreMessage+"\n")
}
Expand Down

0 comments on commit fed0d31

Please sign in to comment.