Merge pull request #3511 from thaJeztah/remove_engine_active_deadcode

registry: remove some dead code / leftovers from "engine activate"
This commit is contained in:
Sebastiaan van Stijn 2022-03-31 14:21:24 +02:00 committed by GitHub
commit 58d425d3bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 55 deletions

View File

@ -15,7 +15,6 @@ type fakeRegistryClient struct {
getManifestListFunc func(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error) getManifestListFunc func(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error)
mountBlobFunc func(ctx context.Context, source reference.Canonical, target reference.Named) error mountBlobFunc func(ctx context.Context, source reference.Canonical, target reference.Named) error
putManifestFunc func(ctx context.Context, source reference.Named, mf distribution.Manifest) (digest.Digest, error) putManifestFunc func(ctx context.Context, source reference.Named, mf distribution.Manifest) (digest.Digest, error)
getTagsFunc func(ctx context.Context, ref reference.Named) ([]string, error)
} }
func (c *fakeRegistryClient) GetManifest(ctx context.Context, ref reference.Named) (manifesttypes.ImageManifest, error) { func (c *fakeRegistryClient) GetManifest(ctx context.Context, ref reference.Named) (manifesttypes.ImageManifest, error) {
@ -46,11 +45,4 @@ func (c *fakeRegistryClient) PutManifest(ctx context.Context, ref reference.Name
return digest.Digest(""), nil return digest.Digest(""), nil
} }
func (c *fakeRegistryClient) GetTags(ctx context.Context, ref reference.Named) ([]string, error) {
if c.getTagsFunc != nil {
return c.getTagsFunc(ctx, ref)
}
return nil, nil
}
var _ client.RegistryClient = &fakeRegistryClient{} var _ client.RegistryClient = &fakeRegistryClient{}

View File

@ -7,7 +7,6 @@ import (
"strings" "strings"
manifesttypes "github.com/docker/cli/cli/manifest/types" manifesttypes "github.com/docker/cli/cli/manifest/types"
"github.com/docker/cli/cli/trust"
"github.com/docker/distribution" "github.com/docker/distribution"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
distributionclient "github.com/docker/distribution/registry/client" distributionclient "github.com/docker/distribution/registry/client"
@ -25,7 +24,6 @@ type RegistryClient interface {
GetManifestList(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error) GetManifestList(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error)
MountBlob(ctx context.Context, source reference.Canonical, target reference.Named) error MountBlob(ctx context.Context, source reference.Canonical, target reference.Named) error
PutManifest(ctx context.Context, ref reference.Named, manifest distribution.Manifest) (digest.Digest, error) PutManifest(ctx context.Context, ref reference.Named, manifest distribution.Manifest) (digest.Digest, error)
GetTags(ctx context.Context, ref reference.Named) ([]string, error)
} }
// NewRegistryClient returns a new RegistryClient with a resolver // NewRegistryClient returns a new RegistryClient with a resolver
@ -124,19 +122,6 @@ func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest
return dgst, errors.Wrapf(err, "failed to put manifest %s", ref) return dgst, errors.Wrapf(err, "failed to put manifest %s", ref)
} }
func (c *client) GetTags(ctx context.Context, ref reference.Named) ([]string, error) {
repoEndpoint, err := newDefaultRepositoryEndpoint(ref, c.insecureRegistry)
if err != nil {
return nil, err
}
repo, err := c.getRepositoryForReference(ctx, ref, repoEndpoint)
if err != nil {
return nil, err
}
return repo.Tags(ctx).All(ctx)
}
func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) { func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) {
repoName, err := reference.WithName(repoEndpoint.Name()) repoName, err := reference.WithName(repoEndpoint.Name())
if err != nil { if err != nil {
@ -207,16 +192,3 @@ func getManifestOptionsFromReference(ref reference.Named) (digest.Digest, []dist
} }
return "", nil, errors.Errorf("%s no tag or digest", ref) return "", nil, errors.Errorf("%s no tag or digest", ref)
} }
// GetRegistryAuth returns the auth config given an input image
func GetRegistryAuth(ctx context.Context, resolver AuthConfigResolver, imageName string) (*types.AuthConfig, error) {
distributionRef, err := reference.ParseNormalizedNamed(imageName)
if err != nil {
return nil, fmt.Errorf("Failed to parse image name: %s: %s", imageName, err)
}
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, resolver, distributionRef.String())
if err != nil {
return nil, fmt.Errorf("Failed to get imgRefAndAuth: %s", err)
}
return imgRefAndAuth.AuthConfig(), nil
}

View File

@ -3,7 +3,6 @@ package client
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"github.com/docker/cli/cli/manifest/types" "github.com/docker/cli/cli/manifest/types"
"github.com/docker/distribution" "github.com/docker/distribution"
@ -128,7 +127,7 @@ func validateManifestDigest(ref reference.Named, mfst distribution.Manifest) (oc
// If pull by digest, then verify the manifest digest. // If pull by digest, then verify the manifest digest.
if digested, isDigested := ref.(reference.Canonical); isDigested { if digested, isDigested := ref.(reference.Canonical); isDigested {
if digested.Digest() != desc.Digest { if digested.Digest() != desc.Digest {
err := fmt.Errorf("manifest verification failed for digest %s", digested.Digest()) err := errors.Errorf("manifest verification failed for digest %s", digested.Digest())
return ocispec.Descriptor{}, err return ocispec.Descriptor{}, err
} }
} }
@ -156,7 +155,7 @@ func pullManifestList(ctx context.Context, ref reference.Named, repo distributio
} }
v, ok := manifest.(*schema2.DeserializedManifest) v, ok := manifest.(*schema2.DeserializedManifest)
if !ok { if !ok {
return nil, fmt.Errorf("unsupported manifest format: %v", v) return nil, errors.Errorf("unsupported manifest format: %v", v)
} }
manifestRef, err := reference.WithDigest(ref, manifestDescriptor.Digest) manifestRef, err := reference.WithDigest(ref, manifestDescriptor.Digest)
@ -278,27 +277,17 @@ func allEndpoints(namedRef reference.Named, insecure bool) ([]registry.APIEndpoi
return endpoints, err return endpoints, err
} }
type notFoundError struct { func newNotFoundError(ref string) *notFoundError {
object string return &notFoundError{err: errors.New("no such manifest: " + ref)}
} }
func newNotFoundError(ref string) *notFoundError { type notFoundError struct {
return &notFoundError{object: ref} err error
} }
func (n *notFoundError) Error() string { func (n *notFoundError) Error() string {
return fmt.Sprintf("no such manifest: %s", n.object) return n.err.Error()
} }
// NotFound interface // NotFound satisfies interface github.com/docker/docker/errdefs.ErrNotFound
func (n *notFoundError) NotFound() {} func (n *notFoundError) NotFound() {}
// IsNotFound returns true if the error is a not found error
func IsNotFound(err error) bool {
_, ok := err.(notFound)
return ok
}
type notFound interface {
NotFound()
}