Vendor main dependencies.
This commit is contained in:
parent
49a09ab7dd
commit
dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions
27
vendor/github.com/docker/engine-api/client/transport/cancellable/LICENSE
generated
vendored
Normal file
27
vendor/github.com/docker/engine-api/client/transport/cancellable/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
vendor/github.com/docker/engine-api/client/transport/cancellable/canceler.go
generated
vendored
Normal file
23
vendor/github.com/docker/engine-api/client/transport/cancellable/canceler.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build go1.5
|
||||
|
||||
package cancellable
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/engine-api/client/transport"
|
||||
)
|
||||
|
||||
func canceler(client transport.Sender, req *http.Request) func() {
|
||||
// TODO(djd): Respect any existing value of req.Cancel.
|
||||
ch := make(chan struct{})
|
||||
req.Cancel = ch
|
||||
|
||||
return func() {
|
||||
close(ch)
|
||||
}
|
||||
}
|
27
vendor/github.com/docker/engine-api/client/transport/cancellable/canceler_go14.go
generated
vendored
Normal file
27
vendor/github.com/docker/engine-api/client/transport/cancellable/canceler_go14.go
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !go1.5
|
||||
|
||||
package cancellable
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/engine-api/client/transport"
|
||||
)
|
||||
|
||||
type requestCanceler interface {
|
||||
CancelRequest(*http.Request)
|
||||
}
|
||||
|
||||
func canceler(client transport.Sender, req *http.Request) func() {
|
||||
rc, ok := client.(requestCanceler)
|
||||
if !ok {
|
||||
return func() {}
|
||||
}
|
||||
return func() {
|
||||
rc.CancelRequest(req)
|
||||
}
|
||||
}
|
113
vendor/github.com/docker/engine-api/client/transport/cancellable/cancellable.go
generated
vendored
Normal file
113
vendor/github.com/docker/engine-api/client/transport/cancellable/cancellable.go
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package cancellable provides helper function to cancel http requests.
|
||||
package cancellable
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/engine-api/client/transport"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func nop() {}
|
||||
|
||||
var (
|
||||
testHookContextDoneBeforeHeaders = nop
|
||||
testHookDoReturned = nop
|
||||
testHookDidBodyClose = nop
|
||||
)
|
||||
|
||||
// Do sends an HTTP request with the provided transport.Sender and returns an HTTP response.
|
||||
// If the client is nil, http.DefaultClient is used.
|
||||
// If the context is canceled or times out, ctx.Err() will be returned.
|
||||
//
|
||||
// FORK INFORMATION:
|
||||
//
|
||||
// This function deviates from the upstream version in golang.org/x/net/context/ctxhttp by
|
||||
// taking a Sender interface rather than a *http.Client directly. That allow us to use
|
||||
// this function with mocked clients and hijacked connections.
|
||||
func Do(ctx context.Context, client transport.Sender, req *http.Request) (*http.Response, error) {
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
}
|
||||
|
||||
// Request cancelation changed in Go 1.5, see canceler.go and canceler_go14.go.
|
||||
cancel := canceler(client, req)
|
||||
|
||||
type responseAndError struct {
|
||||
resp *http.Response
|
||||
err error
|
||||
}
|
||||
result := make(chan responseAndError, 1)
|
||||
|
||||
go func() {
|
||||
resp, err := client.Do(req)
|
||||
testHookDoReturned()
|
||||
result <- responseAndError{resp, err}
|
||||
}()
|
||||
|
||||
var resp *http.Response
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
testHookContextDoneBeforeHeaders()
|
||||
cancel()
|
||||
// Clean up after the goroutine calling client.Do:
|
||||
go func() {
|
||||
if r := <-result; r.resp != nil && r.resp.Body != nil {
|
||||
testHookDidBodyClose()
|
||||
r.resp.Body.Close()
|
||||
}
|
||||
}()
|
||||
return nil, ctx.Err()
|
||||
case r := <-result:
|
||||
var err error
|
||||
resp, err = r.resp, r.err
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
||||
c := make(chan struct{})
|
||||
go func() {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
cancel()
|
||||
case <-c:
|
||||
// The response's Body is closed.
|
||||
}
|
||||
}()
|
||||
resp.Body = ¬ifyingReader{resp.Body, c}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// notifyingReader is an io.ReadCloser that closes the notify channel after
|
||||
// Close is called or a Read fails on the underlying ReadCloser.
|
||||
type notifyingReader struct {
|
||||
io.ReadCloser
|
||||
notify chan<- struct{}
|
||||
}
|
||||
|
||||
func (r *notifyingReader) Read(p []byte) (int, error) {
|
||||
n, err := r.ReadCloser.Read(p)
|
||||
if err != nil && r.notify != nil {
|
||||
close(r.notify)
|
||||
r.notify = nil
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (r *notifyingReader) Close() error {
|
||||
err := r.ReadCloser.Close()
|
||||
if r.notify != nil {
|
||||
close(r.notify)
|
||||
r.notify = nil
|
||||
}
|
||||
return err
|
||||
}
|
47
vendor/github.com/docker/engine-api/client/transport/client.go
generated
vendored
Normal file
47
vendor/github.com/docker/engine-api/client/transport/client.go
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
package transport
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Sender is an interface that clients must implement
|
||||
// to be able to send requests to a remote connection.
|
||||
type Sender interface {
|
||||
// Do sends request to a remote endpoint.
|
||||
Do(*http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
// Client is an interface that abstracts all remote connections.
|
||||
type Client interface {
|
||||
Sender
|
||||
// Secure tells whether the connection is secure or not.
|
||||
Secure() bool
|
||||
// Scheme returns the connection protocol the client uses.
|
||||
Scheme() string
|
||||
// TLSConfig returns any TLS configuration the client uses.
|
||||
TLSConfig() *tls.Config
|
||||
}
|
||||
|
||||
// tlsInfo returns information about the TLS configuration.
|
||||
type tlsInfo struct {
|
||||
tlsConfig *tls.Config
|
||||
}
|
||||
|
||||
// TLSConfig returns the TLS configuration.
|
||||
func (t *tlsInfo) TLSConfig() *tls.Config {
|
||||
return t.tlsConfig
|
||||
}
|
||||
|
||||
// Scheme returns protocol scheme to use.
|
||||
func (t *tlsInfo) Scheme() string {
|
||||
if t.tlsConfig != nil {
|
||||
return "https"
|
||||
}
|
||||
return "http"
|
||||
}
|
||||
|
||||
// Secure returns true if there is a TLS configuration.
|
||||
func (t *tlsInfo) Secure() bool {
|
||||
return t.tlsConfig != nil
|
||||
}
|
57
vendor/github.com/docker/engine-api/client/transport/transport.go
generated
vendored
Normal file
57
vendor/github.com/docker/engine-api/client/transport/transport.go
generated
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Package transport provides function to send request to remote endpoints.
|
||||
package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/go-connections/sockets"
|
||||
)
|
||||
|
||||
// apiTransport holds information about the http transport to connect with the API.
|
||||
type apiTransport struct {
|
||||
*http.Client
|
||||
*tlsInfo
|
||||
transport *http.Transport
|
||||
}
|
||||
|
||||
// NewTransportWithHTTP creates a new transport based on the provided proto, address and http client.
|
||||
// It uses Docker's default http transport configuration if the client is nil.
|
||||
// It does not modify the client's transport if it's not nil.
|
||||
func NewTransportWithHTTP(proto, addr string, client *http.Client) (Client, error) {
|
||||
var transport *http.Transport
|
||||
|
||||
if client != nil {
|
||||
tr, ok := client.Transport.(*http.Transport)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to verify TLS configuration, invalid transport %v", client.Transport)
|
||||
}
|
||||
transport = tr
|
||||
} else {
|
||||
transport = defaultTransport(proto, addr)
|
||||
client = &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
}
|
||||
|
||||
return &apiTransport{
|
||||
Client: client,
|
||||
tlsInfo: &tlsInfo{transport.TLSClientConfig},
|
||||
transport: transport,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CancelRequest stops a request execution.
|
||||
func (a *apiTransport) CancelRequest(req *http.Request) {
|
||||
a.transport.CancelRequest(req)
|
||||
}
|
||||
|
||||
// defaultTransport creates a new http.Transport with Docker's
|
||||
// default transport configuration.
|
||||
func defaultTransport(proto, addr string) *http.Transport {
|
||||
tr := new(http.Transport)
|
||||
sockets.ConfigureTransport(tr, proto, addr)
|
||||
return tr
|
||||
}
|
||||
|
||||
var _ Client = &apiTransport{}
|
Loading…
Add table
Add a link
Reference in a new issue