1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

registry: un-export V1Endpoint and NewV1Endpoint()

They're deprecated, and only used internally for the v1 search.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-26 00:02:37 +01:00
parent 8b8bbbd445
commit 6a01a3cfa4
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
5 changed files with 23 additions and 23 deletions

View file

@ -63,7 +63,7 @@ func TestValidateEndpoint(t *testing.T) {
t.Fatal(err)
}
testEndpoint := V1Endpoint{
testEndpoint := v1Endpoint{
URL: testServerURL,
client: httpClient(newTransport(nil)),
}

View file

@ -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)

View file

@ -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)
}
}

View file

@ -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
}

View file

@ -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
}