Merge pull request #5882 from thaJeztah/regclient_cleanup

cli/registry/client: remove unused types, and deprecate RepoNameForReference
This commit is contained in:
Sebastiaan van Stijn 2025-03-04 14:00:55 +01:00 committed by GitHub
commit d962a90517
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 29 deletions

View File

@ -99,17 +99,10 @@ func buildPushRequest(manifests []types.ImageManifest, targetRef reference.Named
return req, err
}
targetRepoName, err := registryclient.RepoNameForReference(targetRef)
if err != nil {
return req, err
}
targetRepoName := reference.Path(reference.TrimNamed(targetRef))
for _, imageManifest := range manifests {
manifestRepoName, err := registryclient.RepoNameForReference(imageManifest.Ref)
if err != nil {
return req, err
}
manifestRepoName := reference.Path(reference.TrimNamed(imageManifest.Ref))
repoName, _ := reference.WithName(manifestRepoName)
if repoName.Name() != targetRepoName {
blobs, err := buildBlobRequestList(imageManifest, repoName)

View File

@ -37,12 +37,6 @@ func NewRegistryClient(resolver AuthConfigResolver, userAgent string, insecure b
// AuthConfigResolver returns Auth Configuration for an index
type AuthConfigResolver func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig
// PutManifestOptions is the data sent to push a manifest
type PutManifestOptions struct {
MediaType string
Payload []byte
}
type client struct {
authConfigResolver AuthConfigResolver
insecureRegistry bool
@ -60,13 +54,13 @@ func (err ErrBlobCreated) Error() string {
err.From, err.Target)
}
// ErrHTTPProto returned if attempting to use TLS with a non-TLS registry
type ErrHTTPProto struct {
OrigErr string
// httpProtoError returned if attempting to use TLS with a non-TLS registry
type httpProtoError struct {
cause error
}
func (err ErrHTTPProto) Error() string {
return err.OrigErr
func (e httpProtoError) Error() string {
return e.cause.Error()
}
var _ RegistryClient = &client{}
@ -137,7 +131,7 @@ func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Na
return nil, err
}
if !repoEndpoint.endpoint.TLSConfig.InsecureSkipVerify {
return nil, ErrHTTPProto{OrigErr: err.Error()}
return nil, httpProtoError{cause: err}
}
// --insecure was set; fall back to plain HTTP
if url := repoEndpoint.endpoint.URL; url != nil && url.Scheme == "https" {

View File

@ -103,14 +103,11 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API
return transport.NewTransport(base, modifiers...), nil
}
// RepoNameForReference returns the repository name from a reference
// RepoNameForReference returns the repository name from a reference.
//
// Deprecated: this function is no longer used and will be removed in the next release.
func RepoNameForReference(ref reference.Named) (string, error) {
// insecure is fine since this only returns the name
repo, err := newDefaultRepositoryEndpoint(ref, false)
if err != nil {
return "", err
}
return repo.Name(), nil
return reference.Path(reference.TrimNamed(ref)), nil
}
type existingTokenHandler struct {

View File

@ -241,7 +241,8 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
repo, err := c.getRepositoryForReference(ctx, namedRef, repoEndpoint)
if err != nil {
logrus.Debugf("error %s with repo endpoint %+v", err, repoEndpoint)
if _, ok := err.(ErrHTTPProto); ok {
var protoErr httpProtoError
if errors.As(err, &protoErr) {
continue
}
return err