diff options
author | Sebastiaan van Stijn <github@gone.nl> | 2022-02-26 00:08:20 +0100 |
---|---|---|
committer | Sebastiaan van Stijn <github@gone.nl> | 2022-03-17 17:09:07 +0100 |
commit | 286992ef535fb18bb61bfb7aa67d45d8ca932e8c (patch) | |
tree | 5487f41b05a7fbe92bd5d4d53e1a42d6fa2e8c6f /registry | |
parent | 6a01a3cfa4e0c4519fe855dbf59c13964f8aa4cf (diff) | |
download | docker-286992ef535fb18bb61bfb7aa67d45d8ca932e8c.tar.gz |
registry: un-export Ping(), PingResult, remove v1Endpoint.Path()
These are only used internally, and the v1Endpoint.Path() function was only
used to get the `_ping` URL, so let's inline that code instead.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'registry')
-rw-r--r-- | registry/endpoint_v1.go | 46 | ||||
-rw-r--r-- | registry/registry_test.go | 2 | ||||
-rw-r--r-- | registry/session.go | 2 | ||||
-rw-r--r-- | registry/types.go | 13 |
4 files changed, 29 insertions, 34 deletions
diff --git a/registry/endpoint_v1.go b/registry/endpoint_v1.go index 5217f4cfbf..0a8b2cdacc 100644 --- a/registry/endpoint_v1.go +++ b/registry/endpoint_v1.go @@ -14,6 +14,19 @@ import ( "github.com/sirupsen/logrus" ) +// v1PingResult contains the information returned when pinging a registry. It +// indicates the registry's version and whether the registry claims to be a +// standalone registry. +type v1PingResult struct { + // Version is the registry version supplied by the registry in an HTTP + // header + Version string `json:"version"` + // Standalone is set to true if the registry indicates it is a + // standalone registry in the X-Docker-Registry-Standalone + // header + Standalone bool `json:"standalone"` +} + // v1Endpoint stores basic information about a V1 registry endpoint. type v1Endpoint struct { client *http.Client @@ -47,7 +60,7 @@ func validateEndpoint(endpoint *v1Endpoint) error { // Try HTTPS ping to registry endpoint.URL.Scheme = "https" - if _, err := endpoint.Ping(); err != nil { + if _, err := endpoint.ping(); err != nil { if endpoint.IsSecure { // If registry is secure and HTTPS failed, show user the error and tell them about `--insecure-registry` // in case that's what they need. DO NOT accept unknown CA certificates, and DO NOT fallback to HTTP. @@ -59,7 +72,7 @@ func validateEndpoint(endpoint *v1Endpoint) error { endpoint.URL.Scheme = "http" var err2 error - if _, err2 = endpoint.Ping(); err2 == nil { + if _, err2 = endpoint.ping(); err2 == nil { return nil } @@ -123,51 +136,46 @@ func (e *v1Endpoint) String() string { return e.URL.String() + "/v1/" } -// Path returns a formatted string for the URL -// of this endpoint with the given path appended. -func (e *v1Endpoint) Path(path string) string { - return e.URL.String() + "/v1/" + path -} - -// Ping returns a PingResult which indicates whether the registry is standalone or not. -func (e *v1Endpoint) Ping() (PingResult, error) { +// ping returns a v1PingResult which indicates whether the registry is standalone or not. +func (e *v1Endpoint) ping() (v1PingResult, error) { if e.String() == IndexServer { // Skip the check, we know this one is valid // (and we never want to fallback to http in case of error) - return PingResult{}, nil + return v1PingResult{}, nil } logrus.Debugf("attempting v1 ping for registry endpoint %s", e) - req, err := http.NewRequest(http.MethodGet, e.Path("_ping"), nil) + pingURL := e.String() + "_ping" + req, err := http.NewRequest(http.MethodGet, pingURL, nil) if err != nil { - return PingResult{}, err + return v1PingResult{}, err } resp, err := e.client.Do(req) if err != nil { - return PingResult{}, err + return v1PingResult{}, err } defer resp.Body.Close() jsonString, err := io.ReadAll(resp.Body) if err != nil { - return PingResult{}, fmt.Errorf("error while reading the http response: %s", err) + return v1PingResult{}, fmt.Errorf("error while reading the http response: %s", err) } // If the header is absent, we assume true for compatibility with earlier // versions of the registry. default to true - info := PingResult{ + info := v1PingResult{ Standalone: true, } if err := json.Unmarshal(jsonString, &info); err != nil { - logrus.Debugf("Error unmarshaling the _ping PingResult: %s", err) + logrus.Debugf("Error unmarshaling the _ping v1PingResult: %s", err) // don't stop here. Just assume sane defaults } if hdr := resp.Header.Get("X-Docker-Registry-Version"); hdr != "" { info.Version = hdr } - logrus.Debugf("PingResult.Version: %q", info.Version) + logrus.Debugf("v1PingResult.Version: %q", info.Version) standalone := resp.Header.Get("X-Docker-Registry-Standalone") @@ -178,6 +186,6 @@ func (e *v1Endpoint) Ping() (PingResult, error) { // there is a header set, and it is not "true" or "1", so assume fails info.Standalone = false } - logrus.Debugf("PingResult.Standalone: %t", info.Standalone) + logrus.Debugf("v1PingResult.Standalone: %t", info.Standalone) return info, nil } diff --git a/registry/registry_test.go b/registry/registry_test.go index 78557216bd..9bed60ca09 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -51,7 +51,7 @@ func TestPingRegistryEndpoint(t *testing.T) { if err != nil { t.Fatal(err) } - regInfo, err := ep.Ping() + regInfo, err := ep.ping() if err != nil { t.Fatal(err) } diff --git a/registry/session.go b/registry/session.go index 3b25cba15b..1c3ed5e119 100644 --- a/registry/session.go +++ b/registry/session.go @@ -153,7 +153,7 @@ func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint // If we're working with a standalone private registry over HTTPS, send Basic Auth headers // alongside all our requests. if endpoint.String() != IndexServer && endpoint.URL.Scheme == "https" { - info, err := endpoint.Ping() + info, err := endpoint.ping() if err != nil { return err } diff --git a/registry/types.go b/registry/types.go index 077d431549..54d74dab6d 100644 --- a/registry/types.go +++ b/registry/types.go @@ -5,19 +5,6 @@ import ( registrytypes "github.com/docker/docker/api/types/registry" ) -// PingResult contains the information returned when pinging a registry. It -// indicates the registry's version and whether the registry claims to be a -// standalone registry. -type PingResult struct { - // Version is the registry version supplied by the registry in an HTTP - // header - Version string `json:"version"` - // Standalone is set to true if the registry indicates it is a - // standalone registry in the X-Docker-Registry-Standalone - // header - Standalone bool `json:"standalone"` -} - // APIVersion is an integral representation of an API version (presently // either 1 or 2) type APIVersion int |