From de5c80b4f3ca51343fb4b698362ad232478b43be Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Wed, 25 Oct 2017 14:39:51 +0200 Subject: [PATCH] Remove Docker from some functions Signed-off-by: Vincent Demeester --- distribution/pull_v1.go | 2 +- distribution/push_v1.go | 2 +- distribution/registry.go | 2 +- opts/hosts.go | 10 +++++----- opts/hosts_test.go | 4 ++-- registry/auth.go | 2 +- registry/endpoint_v1.go | 2 +- registry/registry.go | 4 ++-- registry/registry_test.go | 2 +- registry/service.go | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/distribution/pull_v1.go b/distribution/pull_v1.go index 34d892c3d8..6f1c2eee0e 100644 --- a/distribution/pull_v1.go +++ b/distribution/pull_v1.go @@ -50,7 +50,7 @@ func (p *v1Puller) Pull(ctx context.Context, ref reference.Named, platform strin tr := transport.NewTransport( // TODO(tiborvass): was ReceiveTimeout registry.NewTransport(tlsConfig), - registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)..., + registry.Headers(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)..., ) client := registry.HTTPClient(tr) v1Endpoint := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders) diff --git a/distribution/push_v1.go b/distribution/push_v1.go index 6cc4f1588f..dccc7b094f 100644 --- a/distribution/push_v1.go +++ b/distribution/push_v1.go @@ -38,7 +38,7 @@ func (p *v1Pusher) Push(ctx context.Context) error { tr := transport.NewTransport( // TODO(tiborvass): was NoTimeout registry.NewTransport(tlsConfig), - registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)..., + registry.Headers(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)..., ) client := registry.HTTPClient(tr) v1Endpoint := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders) diff --git a/distribution/registry.go b/distribution/registry.go index bce270a5ed..03d05240e6 100644 --- a/distribution/registry.go +++ b/distribution/registry.go @@ -82,7 +82,7 @@ func NewV2Repository(ctx context.Context, repoInfo *registry.RepositoryInfo, end base.Dial = proxyDialer.Dial } - modifiers := registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), metaHeaders) + modifiers := registry.Headers(dockerversion.DockerUserAgent(ctx), metaHeaders) authTransport := transport.NewTransport(base, modifiers...) challengeManager, foundVersion, err := registry.PingV2Registry(endpoint.URL, authTransport) diff --git a/opts/hosts.go b/opts/hosts.go index 594cccf2fb..f46b8ee711 100644 --- a/opts/hosts.go +++ b/opts/hosts.go @@ -29,9 +29,9 @@ var ( // ValidateHost validates that the specified string is a valid host and returns it. func ValidateHost(val string) (string, error) { host := strings.TrimSpace(val) - // The empty string means default and is not handled by parseDockerDaemonHost + // The empty string means default and is not handled by parseDaemonHost if host != "" { - _, err := parseDockerDaemonHost(host) + _, err := parseDaemonHost(host) if err != nil { return val, err } @@ -52,7 +52,7 @@ func ParseHost(defaultToTLS bool, val string) (string, error) { } } else { var err error - host, err = parseDockerDaemonHost(host) + host, err = parseDaemonHost(host) if err != nil { return val, err } @@ -60,9 +60,9 @@ func ParseHost(defaultToTLS bool, val string) (string, error) { return host, nil } -// parseDockerDaemonHost parses the specified address and returns an address that will be used as the host. +// parseDaemonHost parses the specified address and returns an address that will be used as the host. // Depending of the address specified, this may return one of the global Default* strings defined in hosts.go. -func parseDockerDaemonHost(addr string) (string, error) { +func parseDaemonHost(addr string) (string, error) { addrParts := strings.SplitN(addr, "://", 2) if len(addrParts) == 1 && addrParts[0] != "" { addrParts = []string{"tcp", addrParts[0]} diff --git a/opts/hosts_test.go b/opts/hosts_test.go index 8aada6a953..f3ae848bf6 100644 --- a/opts/hosts_test.go +++ b/opts/hosts_test.go @@ -83,12 +83,12 @@ func TestParseDockerDaemonHost(t *testing.T) { "localhost:5555/path": "tcp://localhost:5555/path", } for invalidAddr, expectedError := range invalids { - if addr, err := parseDockerDaemonHost(invalidAddr); err == nil || err.Error() != expectedError { + if addr, err := parseDaemonHost(invalidAddr); err == nil || err.Error() != expectedError { t.Errorf("tcp %v address expected error %q return, got %q and addr %v", invalidAddr, expectedError, err, addr) } } for validAddr, expectedAddr := range valids { - if addr, err := parseDockerDaemonHost(validAddr); err != nil || addr != expectedAddr { + if addr, err := parseDaemonHost(validAddr); err != nil || addr != expectedAddr { t.Errorf("%v -> expected %v, got (%v) addr (%v)", validAddr, expectedAddr, err, addr) } } diff --git a/registry/auth.go b/registry/auth.go index b0a03d0480..11937d801a 100644 --- a/registry/auth.go +++ b/registry/auth.go @@ -125,7 +125,7 @@ func (err fallbackError) Error() string { func loginV2(authConfig *types.AuthConfig, endpoint APIEndpoint, userAgent string) (string, string, error) { logrus.Debugf("attempting v2 login to registry endpoint %s", strings.TrimRight(endpoint.URL.String(), "/")+"/v2/") - modifiers := DockerHeaders(userAgent, nil) + modifiers := Headers(userAgent, nil) authTransport := transport.NewTransport(NewTransport(endpoint.TLSConfig), modifiers...) credentialAuthConfig := *authConfig diff --git a/registry/endpoint_v1.go b/registry/endpoint_v1.go index d6a51bfaf7..9b4838a9b4 100644 --- a/registry/endpoint_v1.go +++ b/registry/endpoint_v1.go @@ -77,7 +77,7 @@ func newV1Endpoint(address url.URL, tlsConfig *tls.Config, userAgent string, met // TODO(tiborvass): make sure a ConnectTimeout transport is used tr := NewTransport(tlsConfig) - endpoint.client = HTTPClient(transport.NewTransport(tr, DockerHeaders(userAgent, metaHeaders)...)) + endpoint.client = HTTPClient(transport.NewTransport(tr, Headers(userAgent, metaHeaders)...)) return endpoint } diff --git a/registry/registry.go b/registry/registry.go index 5fef0dbccb..fc49a6e519 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -102,8 +102,8 @@ func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error { return nil } -// DockerHeaders returns request modifiers with a User-Agent and metaHeaders -func DockerHeaders(userAgent string, metaHeaders http.Header) []transport.RequestModifier { +// Headers returns request modifiers with a User-Agent and metaHeaders +func Headers(userAgent string, metaHeaders http.Header) []transport.RequestModifier { modifiers := []transport.RequestModifier{} if userAgent != "" { modifiers = append(modifiers, transport.NewHeaderRequestModifier(http.Header{ diff --git a/registry/registry_test.go b/registry/registry_test.go index e9c407d4b4..4cbfb110e3 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -34,7 +34,7 @@ func spawnTestRegistrySession(t *testing.T) *Session { } userAgent := "docker test client" var tr http.RoundTripper = debugTransport{NewTransport(nil), t.Log} - tr = transport.NewTransport(AuthTransport(tr, authConfig, false), DockerHeaders(userAgent, nil)...) + tr = transport.NewTransport(AuthTransport(tr, authConfig, false), Headers(userAgent, nil)...) client := HTTPClient(tr) r, err := NewSession(client, authConfig, endpoint) if err != nil { diff --git a/registry/service.go b/registry/service.go index a991a8fc39..f3f1b4a567 100644 --- a/registry/service.go +++ b/registry/service.go @@ -199,7 +199,7 @@ func (s *DefaultService) Search(ctx context.Context, term string, limit int, aut }, } - modifiers := DockerHeaders(userAgent, nil) + modifiers := Headers(userAgent, nil) v2Client, foundV2, err := v2AuthHTTPClient(endpoint.URL, endpoint.client.Transport, modifiers, creds, scopes) if err != nil { if fErr, ok := err.(fallbackError); ok {