From 86b5b528a60e65e580fb2baf8f0d3401bacb076d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 25 Jul 2025 23:50:41 +0200 Subject: [PATCH] internal/registry: ParseRepositoryInfo: remove unused error return Removed the error return from the `ParseRepositoryInfo` function. There are no validation steps inside `ParseRepositoryInfo` which could cause an error, so we always returned a nil error. Signed-off-by: Sebastiaan van Stijn --- cli/command/image/push.go | 2 +- cli/command/plugin/install.go | 3 +-- cli/command/plugin/push.go | 2 +- cli/command/service/trust.go | 2 +- cli/registry/client/endpoint.go | 2 +- cli/registry/client/fetcher.go | 4 ++-- cli/trust/trust.go | 2 +- internal/registry/config.go | 8 +++----- internal/registry/registry_test.go | 3 +-- 9 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index c3fd7611d9..4a0f8c8ae2 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -105,7 +105,7 @@ To push the complete multi-platform image, remove the --platform flag. } // Resolve the Repository name from fqn to RepositoryInfo - repoInfo, _ := registry.ParseRepositoryInfo(ref) + repoInfo := registry.ParseRepositoryInfo(ref) // Resolve the Auth config relevant for this server authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), repoInfo.Index) diff --git a/cli/command/plugin/install.go b/cli/command/plugin/install.go index 52ed13917a..573a2e0e78 100644 --- a/cli/command/plugin/install.go +++ b/cli/command/plugin/install.go @@ -66,8 +66,7 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti return client.PluginInstallOptions{}, err } - repoInfo, _ := registry.ParseRepositoryInfo(ref) - + repoInfo := registry.ParseRepositoryInfo(ref) remote := ref.String() _, isCanonical := ref.(reference.Canonical) diff --git a/cli/command/plugin/push.go b/cli/command/plugin/push.go index 6101f51837..aec5ef7a51 100644 --- a/cli/command/plugin/push.go +++ b/cli/command/plugin/push.go @@ -49,7 +49,7 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error named = reference.TagNameOnly(named) - repoInfo, _ := registry.ParseRepositoryInfo(named) + repoInfo := registry.ParseRepositoryInfo(named) authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), repoInfo.Index) encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig) if err != nil { diff --git a/cli/command/service/trust.go b/cli/command/service/trust.go index f9c8bae33c..9bd0aa840e 100644 --- a/cli/command/service/trust.go +++ b/cli/command/service/trust.go @@ -51,7 +51,7 @@ func resolveServiceImageDigestContentTrust(dockerCli command.Cli, service *swarm } func trustedResolveDigest(cli command.Cli, ref reference.NamedTagged) (reference.Canonical, error) { - repoInfo, _ := registry.ParseRepositoryInfo(ref) + repoInfo := registry.ParseRepositoryInfo(ref) authConfig := command.ResolveAuthConfig(cli.ConfigFile(), repoInfo.Index) notaryRepo, err := trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), repoInfo, &authConfig, "pull") diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index 5b6cf4a5ad..28223d2733 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -34,7 +34,7 @@ func (r repositoryEndpoint) BaseURL() string { func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositoryEndpoint, error) { repoName := reference.TrimNamed(ref) - repoInfo, _ := registry.ParseRepositoryInfo(ref) + repoInfo := registry.ParseRepositoryInfo(ref) indexInfo := repoInfo.Index endpoint, err := getDefaultEndpoint(ref, !indexInfo.Secure) diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index c8687d9d91..28fa4f89ec 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -221,7 +221,7 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named, } repoName := reference.TrimNamed(namedRef) - repoInfo, _ := registry.ParseRepositoryInfo(namedRef) + repoInfo := registry.ParseRepositoryInfo(namedRef) indexInfo := repoInfo.Index confirmedTLSRegistries := make(map[string]bool) @@ -285,7 +285,7 @@ func allEndpoints(namedRef reference.Named, insecure bool) ([]registry.APIEndpoi if err != nil { return nil, err } - repoInfo, _ := registry.ParseRepositoryInfo(namedRef) + repoInfo := registry.ParseRepositoryInfo(namedRef) endpoints, err := registryService.Endpoints(context.TODO(), reference.Domain(repoInfo.Name)) logrus.Debugf("endpoints for %s: %v", namedRef, endpoints) return endpoints, err diff --git a/cli/trust/trust.go b/cli/trust/trust.go index b8525f0513..fa4ee9069a 100644 --- a/cli/trust/trust.go +++ b/cli/trust/trust.go @@ -321,7 +321,7 @@ func GetImageReferencesAndAuth(ctx context.Context, } // Resolve the Repository name from fqn to RepositoryInfo - repoInfo, _ := registry.ParseRepositoryInfo(ref) + repoInfo := registry.ParseRepositoryInfo(ref) authConfig := authResolver(ctx, repoInfo.Index) return ImageRefAndAuth{ original: imgName, diff --git a/internal/registry/config.go b/internal/registry/config.go index b2f3070b1c..ddc8118389 100644 --- a/internal/registry/config.go +++ b/internal/registry/config.go @@ -254,9 +254,7 @@ func validateHostPort(s string) error { // ParseRepositoryInfo performs the breakdown of a repository name into a // [RepositoryInfo], but lacks registry configuration. -// -// It is used by the Docker cli to interact with registry-related endpoints. -func ParseRepositoryInfo(reposName reference.Named) (*RepositoryInfo, error) { +func ParseRepositoryInfo(reposName reference.Named) *RepositoryInfo { indexName := normalizeIndexName(reference.Domain(reposName)) if indexName == IndexName { return &RepositoryInfo{ @@ -266,7 +264,7 @@ func ParseRepositoryInfo(reposName reference.Named) (*RepositoryInfo, error) { Secure: true, Official: true, }, - }, nil + } } return &RepositoryInfo{ @@ -275,7 +273,7 @@ func ParseRepositoryInfo(reposName reference.Named) (*RepositoryInfo, error) { Name: indexName, Secure: !isInsecure(indexName), }, - }, nil + } } // isInsecure is used to detect whether a registry domain or IP-address is allowed diff --git a/internal/registry/registry_test.go b/internal/registry/registry_test.go index 31c4483c40..9edd682675 100644 --- a/internal/registry/registry_test.go +++ b/internal/registry/registry_test.go @@ -269,8 +269,7 @@ func TestParseRepositoryInfo(t *testing.T) { named, err := reference.ParseNormalizedNamed(reposName) assert.NilError(t, err) - repoInfo, err := ParseRepositoryInfo(named) - assert.NilError(t, err) + repoInfo := ParseRepositoryInfo(named) assert.Check(t, is.DeepEqual(repoInfo.Index, expected.Index)) assert.Check(t, is.Equal(reference.Path(repoInfo.Name), expected.RemoteName))