From c587ba34229948e5c0b8fdc4bbdb1eaf6727aaa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Thu, 5 Oct 2023 10:42:37 +0200 Subject: [PATCH] registry: allow mirror path prefix in config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Path prefixes were originally disallowed in the `--registry-mirrors` option because the /v1 endpoint was assumed to be at the root of the URI. This is no longer the case in v2. Close #36598 Signed-off-by: RĂ©gis Behmo --- registry/config.go | 4 ++-- registry/config_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/registry/config.go b/registry/config.go index 347e7128c4..c29faeb4b9 100644 --- a/registry/config.go +++ b/registry/config.go @@ -330,8 +330,8 @@ func ValidateMirror(val string) (string, error) { if uri.Scheme != "http" && uri.Scheme != "https" { return "", invalidParamf("invalid mirror: unsupported scheme %q in %q", uri.Scheme, uri) } - if (uri.Path != "" && uri.Path != "/") || uri.RawQuery != "" || uri.Fragment != "" { - return "", invalidParamf("invalid mirror: path, query, or fragment at end of the URI %q", uri) + if uri.RawQuery != "" || uri.Fragment != "" { + return "", invalidParamf("invalid mirror: query or fragment at end of the URI %q", uri) } if uri.User != nil { // strip password from output diff --git a/registry/config_test.go b/registry/config_test.go index 77f799df96..f68cfc61b2 100644 --- a/registry/config_test.go +++ b/registry/config_test.go @@ -142,21 +142,21 @@ func TestValidateMirror(t *testing.T) { "https://127.0.0.1", "http://127.0.0.1:5000", "https://127.0.0.1:5000", + "http://mirror-1.example.com/v1/", + "https://mirror-1.example.com/v1/", } invalid := []string{ "!invalid!://%as%", "ftp://mirror-1.example.com", "http://mirror-1.example.com/?q=foo", - "http://mirror-1.example.com/v1/", "http://mirror-1.example.com/v1/?q=foo", "http://mirror-1.example.com/v1/?q=foo#frag", "http://mirror-1.example.com?q=foo", "https://mirror-1.example.com#frag", "https://mirror-1.example.com/#frag", "http://foo:bar@mirror-1.example.com/", - "https://mirror-1.example.com/v1/", - "https://mirror-1.example.com/v1/#", + "https://mirror-1.example.com/v1/#frag", "https://mirror-1.example.com?q", }