mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove Docker from some functions
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
d85f5e7320
commit
de5c80b4f3
10 changed files with 16 additions and 16 deletions
|
@ -50,7 +50,7 @@ func (p *v1Puller) Pull(ctx context.Context, ref reference.Named, platform strin
|
||||||
tr := transport.NewTransport(
|
tr := transport.NewTransport(
|
||||||
// TODO(tiborvass): was ReceiveTimeout
|
// TODO(tiborvass): was ReceiveTimeout
|
||||||
registry.NewTransport(tlsConfig),
|
registry.NewTransport(tlsConfig),
|
||||||
registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)...,
|
registry.Headers(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)...,
|
||||||
)
|
)
|
||||||
client := registry.HTTPClient(tr)
|
client := registry.HTTPClient(tr)
|
||||||
v1Endpoint := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)
|
v1Endpoint := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (p *v1Pusher) Push(ctx context.Context) error {
|
||||||
tr := transport.NewTransport(
|
tr := transport.NewTransport(
|
||||||
// TODO(tiborvass): was NoTimeout
|
// TODO(tiborvass): was NoTimeout
|
||||||
registry.NewTransport(tlsConfig),
|
registry.NewTransport(tlsConfig),
|
||||||
registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)...,
|
registry.Headers(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)...,
|
||||||
)
|
)
|
||||||
client := registry.HTTPClient(tr)
|
client := registry.HTTPClient(tr)
|
||||||
v1Endpoint := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)
|
v1Endpoint := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)
|
||||||
|
|
|
@ -82,7 +82,7 @@ func NewV2Repository(ctx context.Context, repoInfo *registry.RepositoryInfo, end
|
||||||
base.Dial = proxyDialer.Dial
|
base.Dial = proxyDialer.Dial
|
||||||
}
|
}
|
||||||
|
|
||||||
modifiers := registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), metaHeaders)
|
modifiers := registry.Headers(dockerversion.DockerUserAgent(ctx), metaHeaders)
|
||||||
authTransport := transport.NewTransport(base, modifiers...)
|
authTransport := transport.NewTransport(base, modifiers...)
|
||||||
|
|
||||||
challengeManager, foundVersion, err := registry.PingV2Registry(endpoint.URL, authTransport)
|
challengeManager, foundVersion, err := registry.PingV2Registry(endpoint.URL, authTransport)
|
||||||
|
|
|
@ -29,9 +29,9 @@ var (
|
||||||
// ValidateHost validates that the specified string is a valid host and returns it.
|
// ValidateHost validates that the specified string is a valid host and returns it.
|
||||||
func ValidateHost(val string) (string, error) {
|
func ValidateHost(val string) (string, error) {
|
||||||
host := strings.TrimSpace(val)
|
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 != "" {
|
if host != "" {
|
||||||
_, err := parseDockerDaemonHost(host)
|
_, err := parseDaemonHost(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return val, err
|
return val, err
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func ParseHost(defaultToTLS bool, val string) (string, error) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
host, err = parseDockerDaemonHost(host)
|
host, err = parseDaemonHost(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return val, err
|
return val, err
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ func ParseHost(defaultToTLS bool, val string) (string, error) {
|
||||||
return host, nil
|
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.
|
// 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)
|
addrParts := strings.SplitN(addr, "://", 2)
|
||||||
if len(addrParts) == 1 && addrParts[0] != "" {
|
if len(addrParts) == 1 && addrParts[0] != "" {
|
||||||
addrParts = []string{"tcp", addrParts[0]}
|
addrParts = []string{"tcp", addrParts[0]}
|
||||||
|
|
|
@ -83,12 +83,12 @@ func TestParseDockerDaemonHost(t *testing.T) {
|
||||||
"localhost:5555/path": "tcp://localhost:5555/path",
|
"localhost:5555/path": "tcp://localhost:5555/path",
|
||||||
}
|
}
|
||||||
for invalidAddr, expectedError := range invalids {
|
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)
|
t.Errorf("tcp %v address expected error %q return, got %q and addr %v", invalidAddr, expectedError, err, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for validAddr, expectedAddr := range valids {
|
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)
|
t.Errorf("%v -> expected %v, got (%v) addr (%v)", validAddr, expectedAddr, err, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ func (err fallbackError) Error() string {
|
||||||
func loginV2(authConfig *types.AuthConfig, endpoint APIEndpoint, userAgent string) (string, string, error) {
|
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/")
|
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...)
|
authTransport := transport.NewTransport(NewTransport(endpoint.TLSConfig), modifiers...)
|
||||||
|
|
||||||
credentialAuthConfig := *authConfig
|
credentialAuthConfig := *authConfig
|
||||||
|
|
|
@ -77,7 +77,7 @@ func newV1Endpoint(address url.URL, tlsConfig *tls.Config, userAgent string, met
|
||||||
|
|
||||||
// TODO(tiborvass): make sure a ConnectTimeout transport is used
|
// TODO(tiborvass): make sure a ConnectTimeout transport is used
|
||||||
tr := NewTransport(tlsConfig)
|
tr := NewTransport(tlsConfig)
|
||||||
endpoint.client = HTTPClient(transport.NewTransport(tr, DockerHeaders(userAgent, metaHeaders)...))
|
endpoint.client = HTTPClient(transport.NewTransport(tr, Headers(userAgent, metaHeaders)...))
|
||||||
return endpoint
|
return endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,8 @@ func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DockerHeaders returns request modifiers with a User-Agent and metaHeaders
|
// Headers returns request modifiers with a User-Agent and metaHeaders
|
||||||
func DockerHeaders(userAgent string, metaHeaders http.Header) []transport.RequestModifier {
|
func Headers(userAgent string, metaHeaders http.Header) []transport.RequestModifier {
|
||||||
modifiers := []transport.RequestModifier{}
|
modifiers := []transport.RequestModifier{}
|
||||||
if userAgent != "" {
|
if userAgent != "" {
|
||||||
modifiers = append(modifiers, transport.NewHeaderRequestModifier(http.Header{
|
modifiers = append(modifiers, transport.NewHeaderRequestModifier(http.Header{
|
||||||
|
|
|
@ -34,7 +34,7 @@ func spawnTestRegistrySession(t *testing.T) *Session {
|
||||||
}
|
}
|
||||||
userAgent := "docker test client"
|
userAgent := "docker test client"
|
||||||
var tr http.RoundTripper = debugTransport{NewTransport(nil), t.Log}
|
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)
|
client := HTTPClient(tr)
|
||||||
r, err := NewSession(client, authConfig, endpoint)
|
r, err := NewSession(client, authConfig, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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)
|
v2Client, foundV2, err := v2AuthHTTPClient(endpoint.URL, endpoint.client.Transport, modifiers, creds, scopes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if fErr, ok := err.(fallbackError); ok {
|
if fErr, ok := err.(fallbackError); ok {
|
||||||
|
|
Loading…
Reference in a new issue