diff --git a/registry/endpoint_test.go b/registry/endpoint_test.go index d8f283974c..e36db56a33 100644 --- a/registry/endpoint_test.go +++ b/registry/endpoint_test.go @@ -63,7 +63,7 @@ func TestValidateEndpoint(t *testing.T) { t.Fatal(err) } - testEndpoint := V1Endpoint{ + testEndpoint := v1Endpoint{ URL: testServerURL, client: httpClient(newTransport(nil)), } diff --git a/registry/endpoint_v1.go b/registry/endpoint_v1.go index 7721d7693a..5217f4cfbf 100644 --- a/registry/endpoint_v1.go +++ b/registry/endpoint_v1.go @@ -14,16 +14,16 @@ import ( "github.com/sirupsen/logrus" ) -// V1Endpoint stores basic information about a V1 registry endpoint. -type V1Endpoint struct { +// v1Endpoint stores basic information about a V1 registry endpoint. +type v1Endpoint struct { client *http.Client URL *url.URL IsSecure bool } -// NewV1Endpoint parses the given address to return a registry endpoint. +// newV1Endpoint parses the given address to return a registry endpoint. // TODO: remove. This is only used by search. -func NewV1Endpoint(index *registrytypes.IndexInfo, userAgent string, metaHeaders http.Header) (*V1Endpoint, error) { +func newV1Endpoint(index *registrytypes.IndexInfo, userAgent string, metaHeaders http.Header) (*v1Endpoint, error) { tlsConfig, err := newTLSConfig(index.Name, index.Secure) if err != nil { return nil, err @@ -42,7 +42,7 @@ func NewV1Endpoint(index *registrytypes.IndexInfo, userAgent string, metaHeaders return endpoint, nil } -func validateEndpoint(endpoint *V1Endpoint) error { +func validateEndpoint(endpoint *v1Endpoint) error { logrus.Debugf("pinging registry endpoint %s", endpoint) // Try HTTPS ping to registry @@ -93,7 +93,7 @@ func trimV1Address(address string) (string, error) { return address, nil } -func newV1EndpointFromStr(address string, tlsConfig *tls.Config, userAgent string, metaHeaders http.Header) (*V1Endpoint, error) { +func newV1EndpointFromStr(address string, tlsConfig *tls.Config, userAgent string, metaHeaders http.Header) (*v1Endpoint, error) { if !strings.HasPrefix(address, "http://") && !strings.HasPrefix(address, "https://") { address = "https://" + address } @@ -111,7 +111,7 @@ func newV1EndpointFromStr(address string, tlsConfig *tls.Config, userAgent strin // TODO(tiborvass): make sure a ConnectTimeout transport is used tr := newTransport(tlsConfig) - return &V1Endpoint{ + return &v1Endpoint{ IsSecure: tlsConfig == nil || !tlsConfig.InsecureSkipVerify, URL: uri, client: httpClient(transport.NewTransport(tr, Headers(userAgent, metaHeaders)...)), @@ -119,18 +119,18 @@ func newV1EndpointFromStr(address string, tlsConfig *tls.Config, userAgent strin } // Get the formatted URL for the root of this registry Endpoint -func (e *V1Endpoint) String() string { +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 { +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) { +func (e *v1Endpoint) Ping() (PingResult, 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) diff --git a/registry/registry_test.go b/registry/registry_test.go index ba06e4145e..78557216bd 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -18,7 +18,7 @@ import ( func spawnTestRegistrySession(t *testing.T) *Session { authConfig := &types.AuthConfig{} - endpoint, err := NewV1Endpoint(makeIndex("/v1/"), "", nil) + endpoint, err := newV1Endpoint(makeIndex("/v1/"), "", nil) if err != nil { t.Fatal(err) } @@ -47,7 +47,7 @@ func spawnTestRegistrySession(t *testing.T) *Session { func TestPingRegistryEndpoint(t *testing.T) { skip.If(t, os.Getuid() != 0, "skipping test that requires root") testPing := func(index *registrytypes.IndexInfo, expectedStandalone bool, assertMessage string) { - ep, err := NewV1Endpoint(index, "", nil) + ep, err := newV1Endpoint(index, "", nil) if err != nil { t.Fatal(err) } @@ -67,8 +67,8 @@ func TestPingRegistryEndpoint(t *testing.T) { func TestEndpoint(t *testing.T) { skip.If(t, os.Getuid() != 0, "skipping test that requires root") // Simple wrapper to fail test if err != nil - expandEndpoint := func(index *registrytypes.IndexInfo) *V1Endpoint { - endpoint, err := NewV1Endpoint(index, "", nil) + expandEndpoint := func(index *registrytypes.IndexInfo) *v1Endpoint { + endpoint, err := newV1Endpoint(index, "", nil) if err != nil { t.Fatal(err) } @@ -77,14 +77,14 @@ func TestEndpoint(t *testing.T) { assertInsecureIndex := func(index *registrytypes.IndexInfo) { index.Secure = true - _, err := NewV1Endpoint(index, "", nil) + _, err := newV1Endpoint(index, "", nil) assert.ErrorContains(t, err, "insecure-registry", index.Name+": Expected insecure-registry error for insecure index") index.Secure = false } assertSecureIndex := func(index *registrytypes.IndexInfo) { index.Secure = true - _, err := NewV1Endpoint(index, "", nil) + _, err := newV1Endpoint(index, "", nil) assert.ErrorContains(t, err, "certificate signed by unknown authority", index.Name+": Expected cert error for secure index") index.Secure = false } @@ -131,7 +131,7 @@ func TestEndpoint(t *testing.T) { } for _, address := range badEndpoints { index.Name = address - _, err := NewV1Endpoint(index, "", nil) + _, err := newV1Endpoint(index, "", nil) assert.Check(t, err != nil, "Expected error while expanding bad endpoint: %s", address) } } diff --git a/registry/service.go b/registry/service.go index 8b5bb9e7b6..8d85c8a2dc 100644 --- a/registry/service.go +++ b/registry/service.go @@ -177,7 +177,7 @@ func (s *defaultService) Search(ctx context.Context, term string, limit int, aut } // *TODO: Search multiple indexes. - endpoint, err := NewV1Endpoint(index, userAgent, headers) + endpoint, err := newV1Endpoint(index, userAgent, headers) if err != nil { return nil, err } diff --git a/registry/session.go b/registry/session.go index 8d9b426bf0..3b25cba15b 100644 --- a/registry/session.go +++ b/registry/session.go @@ -23,7 +23,7 @@ import ( // A Session is used to communicate with a V1 registry type Session struct { - indexEndpoint *V1Endpoint + indexEndpoint *v1Endpoint client *http.Client id string } @@ -147,7 +147,7 @@ func (tr *authTransport) CancelRequest(req *http.Request) { } } -func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) error { +func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint *v1Endpoint) error { var alwaysSetBasicAuth bool // If we're working with a standalone private registry over HTTPS, send Basic Auth headers @@ -176,7 +176,7 @@ func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint return nil } -func newSession(client *http.Client, endpoint *V1Endpoint) *Session { +func newSession(client *http.Client, endpoint *v1Endpoint) *Session { return &Session{ client: client, indexEndpoint: endpoint, @@ -186,7 +186,7 @@ func newSession(client *http.Client, endpoint *V1Endpoint) *Session { // NewSession creates a new session // TODO(tiborvass): remove authConfig param once registry client v2 is vendored -func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) (*Session, error) { +func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *v1Endpoint) (*Session, error) { if err := authorizeClient(client, authConfig, endpoint); err != nil { return nil, err }