From e83d6cd2c8a4fb29acde76a0f46b5c11e1f906dd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Feb 2022 10:57:30 +0100 Subject: [PATCH 1/3] cli/registry/client: remove unused GetRegistryAuth() This was added in fd2f1b3b6650b53ed1367b84910e0f81e89220cd as part of the `docker engine` sub-commands, which were deprecated, and removed in 43b2f52d0ca4b57bddd0fd541d8440e1f17fd0a6. This function is not used by anyone, so safe to remove. Signed-off-by: Sebastiaan van Stijn --- cli/registry/client/client.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/cli/registry/client/client.go b/cli/registry/client/client.go index 3ed139840d..4c411b9da6 100644 --- a/cli/registry/client/client.go +++ b/cli/registry/client/client.go @@ -7,7 +7,6 @@ import ( "strings" manifesttypes "github.com/docker/cli/cli/manifest/types" - "github.com/docker/cli/cli/trust" "github.com/docker/distribution" "github.com/docker/distribution/reference" distributionclient "github.com/docker/distribution/registry/client" @@ -207,16 +206,3 @@ func getManifestOptionsFromReference(ref reference.Named) (digest.Digest, []dist } 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 -} From 48745da16c0d0ab0809f28da234018e5072ea06e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Feb 2022 11:21:00 +0100 Subject: [PATCH 2/3] cli/registry/client: remove unused RegistryClient.GetTags() This was added in fd2f1b3b6650b53ed1367b84910e0f81e89220cd as part of the `docker engine` sub-commands, which were deprecated, and removed in 43b2f52d0ca4b57bddd0fd541d8440e1f17fd0a6. This function is not used by anyone, so safe to remove. Signed-off-by: Sebastiaan van Stijn --- cli/command/manifest/client_test.go | 8 -------- cli/registry/client/client.go | 14 -------------- 2 files changed, 22 deletions(-) diff --git a/cli/command/manifest/client_test.go b/cli/command/manifest/client_test.go index c5cb9ea1b6..07967c29ab 100644 --- a/cli/command/manifest/client_test.go +++ b/cli/command/manifest/client_test.go @@ -15,7 +15,6 @@ type fakeRegistryClient struct { getManifestListFunc func(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, 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) - getTagsFunc func(ctx context.Context, ref reference.Named) ([]string, 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 } -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{} diff --git a/cli/registry/client/client.go b/cli/registry/client/client.go index 4c411b9da6..ba76a34fc8 100644 --- a/cli/registry/client/client.go +++ b/cli/registry/client/client.go @@ -24,7 +24,6 @@ type RegistryClient interface { GetManifestList(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, 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) - GetTags(ctx context.Context, ref reference.Named) ([]string, error) } // NewRegistryClient returns a new RegistryClient with a resolver @@ -123,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) } -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) { repoName, err := reference.WithName(repoEndpoint.Name()) if err != nil { From 801113fb8de1fc5f775d3b870f6abc4d77d692b3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Feb 2022 11:27:50 +0100 Subject: [PATCH 3/3] cli/registry/client: remove unused IsNotFound(), and slight refactor This function was not used anywhere, and the error type already satisfied the github.com/docker/docker/errdefs.ErrNotFound interface, so let's remove this utility and (if needed at some point) use errdefs.IsNotFound() instead. Signed-off-by: Sebastiaan van Stijn --- cli/registry/client/fetcher.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index 190aada58c..ef8011d1fb 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -3,7 +3,6 @@ package client import ( "context" "encoding/json" - "fmt" "github.com/docker/cli/cli/manifest/types" "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 digested, isDigested := ref.(reference.Canonical); isDigested { 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 } } @@ -156,7 +155,7 @@ func pullManifestList(ctx context.Context, ref reference.Named, repo distributio } v, ok := manifest.(*schema2.DeserializedManifest) 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) @@ -278,27 +277,17 @@ func allEndpoints(namedRef reference.Named, insecure bool) ([]registry.APIEndpoi return endpoints, err } -type notFoundError struct { - object string +func newNotFoundError(ref string) *notFoundError { + return ¬FoundError{err: errors.New("no such manifest: " + ref)} } -func newNotFoundError(ref string) *notFoundError { - return ¬FoundError{object: ref} +type notFoundError struct { + err error } 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() {} - -// 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() -}