Skip to content

Commit d962a90

Browse files
authored
Merge pull request #5882 from thaJeztah/regclient_cleanup
cli/registry/client: remove unused types, and deprecate RepoNameForReference
2 parents 43a2fcf + 6f46cd2 commit d962a90

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

cli/command/manifest/push.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,10 @@ func buildPushRequest(manifests []types.ImageManifest, targetRef reference.Named
9999
return req, err
100100
}
101101

102-
targetRepoName, err := registryclient.RepoNameForReference(targetRef)
103-
if err != nil {
104-
return req, err
105-
}
102+
targetRepoName := reference.Path(reference.TrimNamed(targetRef))
106103

107104
for _, imageManifest := range manifests {
108-
manifestRepoName, err := registryclient.RepoNameForReference(imageManifest.Ref)
109-
if err != nil {
110-
return req, err
111-
}
112-
105+
manifestRepoName := reference.Path(reference.TrimNamed(imageManifest.Ref))
113106
repoName, _ := reference.WithName(manifestRepoName)
114107
if repoName.Name() != targetRepoName {
115108
blobs, err := buildBlobRequestList(imageManifest, repoName)

cli/registry/client/client.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ func NewRegistryClient(resolver AuthConfigResolver, userAgent string, insecure b
3737
// AuthConfigResolver returns Auth Configuration for an index
3838
type AuthConfigResolver func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig
3939

40-
// PutManifestOptions is the data sent to push a manifest
41-
type PutManifestOptions struct {
42-
MediaType string
43-
Payload []byte
44-
}
45-
4640
type client struct {
4741
authConfigResolver AuthConfigResolver
4842
insecureRegistry bool
@@ -60,13 +54,13 @@ func (err ErrBlobCreated) Error() string {
6054
err.From, err.Target)
6155
}
6256

63-
// ErrHTTPProto returned if attempting to use TLS with a non-TLS registry
64-
type ErrHTTPProto struct {
65-
OrigErr string
57+
// httpProtoError returned if attempting to use TLS with a non-TLS registry
58+
type httpProtoError struct {
59+
cause error
6660
}
6761

68-
func (err ErrHTTPProto) Error() string {
69-
return err.OrigErr
62+
func (e httpProtoError) Error() string {
63+
return e.cause.Error()
7064
}
7165

7266
var _ RegistryClient = &client{}
@@ -137,7 +131,7 @@ func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Na
137131
return nil, err
138132
}
139133
if !repoEndpoint.endpoint.TLSConfig.InsecureSkipVerify {
140-
return nil, ErrHTTPProto{OrigErr: err.Error()}
134+
return nil, httpProtoError{cause: err}
141135
}
142136
// --insecure was set; fall back to plain HTTP
143137
if url := repoEndpoint.endpoint.URL; url != nil && url.Scheme == "https" {

cli/registry/client/endpoint.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,11 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API
103103
return transport.NewTransport(base, modifiers...), nil
104104
}
105105

106-
// RepoNameForReference returns the repository name from a reference
106+
// RepoNameForReference returns the repository name from a reference.
107+
//
108+
// Deprecated: this function is no longer used and will be removed in the next release.
107109
func RepoNameForReference(ref reference.Named) (string, error) {
108-
// insecure is fine since this only returns the name
109-
repo, err := newDefaultRepositoryEndpoint(ref, false)
110-
if err != nil {
111-
return "", err
112-
}
113-
return repo.Name(), nil
110+
return reference.Path(reference.TrimNamed(ref)), nil
114111
}
115112

116113
type existingTokenHandler struct {

cli/registry/client/fetcher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
241241
repo, err := c.getRepositoryForReference(ctx, namedRef, repoEndpoint)
242242
if err != nil {
243243
logrus.Debugf("error %s with repo endpoint %+v", err, repoEndpoint)
244-
if _, ok := err.(ErrHTTPProto); ok {
244+
var protoErr httpProtoError
245+
if errors.As(err, &protoErr) {
245246
continue
246247
}
247248
return err

0 commit comments

Comments
 (0)