"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/github.com/fsouza/go-dockerclient/client.go" between
buildah-1.11.2.tar.gz and buildah-1.11.3.tar.gz

About: Buildah is a tool that facilitates building Open Container Initiative (OCI) container images.

client.go  (buildah-1.11.2):client.go  (buildah-1.11.3)
skipping to change at line 34 skipping to change at line 34
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/homedir" "github.com/docker/docker/pkg/homedir"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/fsouza/go-dockerclient/internal/jsonmessage" "github.com/fsouza/go-dockerclient/internal/jsonmessage"
) )
const ( const (
userAgent = "go-dockerclient" userAgent = "go-dockerclient"
unixProtocol = "unix" unixProtocol = "unix"
namedPipeProtocol = "npipe" namedPipeProtocol = "npipe"
skipping to change at line 73 skipping to change at line 72
// APIVersion is an internal representation of a version of the Remote API. // APIVersion is an internal representation of a version of the Remote API.
type APIVersion []int type APIVersion []int
// NewAPIVersion returns an instance of APIVersion for the given string. // NewAPIVersion returns an instance of APIVersion for the given string.
// //
// The given string must be in the form <major>.<minor>.<patch>, where <major>, // The given string must be in the form <major>.<minor>.<patch>, where <major>,
// <minor> and <patch> are integer numbers. // <minor> and <patch> are integer numbers.
func NewAPIVersion(input string) (APIVersion, error) { func NewAPIVersion(input string) (APIVersion, error) {
if !strings.Contains(input, ".") { if !strings.Contains(input, ".") {
return nil, fmt.Errorf("Unable to parse version %q", input) return nil, fmt.Errorf("unable to parse version %q", input)
} }
raw := strings.Split(input, "-") raw := strings.Split(input, "-")
arr := strings.Split(raw[0], ".") arr := strings.Split(raw[0], ".")
ret := make(APIVersion, len(arr)) ret := make(APIVersion, len(arr))
var err error var err error
for i, val := range arr { for i, val := range arr {
ret[i], err = strconv.Atoi(val) ret[i], err = strconv.Atoi(val)
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to parse version %q: %q is not an integer", input, val) return nil, fmt.Errorf("unable to parse version %q: %q is not an integer", input, val)
} }
} }
return ret, nil return ret, nil
} }
func (version APIVersion) String() string { func (version APIVersion) String() string {
var str string var str string
for i, val := range version { for i, val := range version {
str += strconv.Itoa(val) str += strconv.Itoa(val)
if i < len(version)-1 { if i < len(version)-1 {
skipping to change at line 266 skipping to change at line 265
if _, err := os.Stat(ca); !os.IsNotExist(err) { if _, err := os.Stat(ca); !os.IsNotExist(err) {
caPEMCert, err = ioutil.ReadFile(ca) caPEMCert, err = ioutil.ReadFile(ca)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
return NewVersionedTLSClientFromBytes(endpoint, certPEMBlock, keyPEMBlock , caPEMCert, apiVersionString) return NewVersionedTLSClientFromBytes(endpoint, certPEMBlock, keyPEMBlock , caPEMCert, apiVersionString)
} }
// NewClientFromEnv returns a Client instance ready for communication created fr om // NewClientFromEnv returns a Client instance ready for communication created fr om
// Docker's default logic for the environment variables DOCKER_HOST, DOCKER_TLS_ // Docker's default logic for the environment variables DOCKER_HOST, DOCKER_TLS_
VERIFY, and DOCKER_CERT_PATH. VERIFY, DOCKER_CERT_PATH,
// and DOCKER_API_VERSION.
// //
// See https://github.com/docker/docker/blob/1f963af697e8df3a78217f6fdbf67b8123a 7db94/docker/docker.go#L68. // See https://github.com/docker/docker/blob/1f963af697e8df3a78217f6fdbf67b8123a 7db94/docker/docker.go#L68.
// See https://github.com/docker/compose/blob/81707ef1ad94403789166d2fe042c8a718 a4c748/compose/cli/docker_client.py#L7. // See https://github.com/docker/compose/blob/81707ef1ad94403789166d2fe042c8a718 a4c748/compose/cli/docker_client.py#L7.
// See https://github.com/moby/moby/blob/28d7dba41d0c0d9c7f0dafcc79d3c59f2b3f5dc 3/client/options.go#L51
func NewClientFromEnv() (*Client, error) { func NewClientFromEnv() (*Client, error) {
client, err := NewVersionedClientFromEnv("") client, err := NewVersionedClientFromEnv(os.Getenv("DOCKER_API_VERSION"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
client.SkipServerVersionCheck = true client.SkipServerVersionCheck = true
return client, nil return client, nil
} }
// NewVersionedClientFromEnv returns a Client instance ready for TLS communicati ons created from // NewVersionedClientFromEnv returns a Client instance ready for TLS communicati ons created from
// Docker's default logic for the environment variables DOCKER_HOST, DOCKER_TLS_ VERIFY, and DOCKER_CERT_PATH, // Docker's default logic for the environment variables DOCKER_HOST, DOCKER_TLS_ VERIFY, and DOCKER_CERT_PATH,
// and using a specific remote API version. // and using a specific remote API version.
skipping to change at line 332 skipping to change at line 333
if err != nil { if err != nil {
return nil, err return nil, err
} }
tlsConfig.Certificates = []tls.Certificate{tlsCert} tlsConfig.Certificates = []tls.Certificate{tlsCert}
} }
if caPEMCert == nil { if caPEMCert == nil {
tlsConfig.InsecureSkipVerify = true tlsConfig.InsecureSkipVerify = true
} else { } else {
caPool := x509.NewCertPool() caPool := x509.NewCertPool()
if !caPool.AppendCertsFromPEM(caPEMCert) { if !caPool.AppendCertsFromPEM(caPEMCert) {
return nil, errors.New("Could not add RootCA pem") return nil, errors.New("could not add RootCA pem")
} }
tlsConfig.RootCAs = caPool tlsConfig.RootCAs = caPool
} }
tr := defaultTransport() tr := defaultTransport()
tr.TLSClientConfig = tlsConfig tr.TLSClientConfig = tlsConfig
if err != nil { if err != nil {
return nil, err return nil, err
} }
c := &Client{ c := &Client{
HTTPClient: &http.Client{Transport: tr}, HTTPClient: &http.Client{Transport: tr},
skipping to change at line 390 skipping to change at line 391
// when using functions that get this data from the environment (like // when using functions that get this data from the environment (like
// NewClientFromEnv. // NewClientFromEnv.
func (c *Client) Endpoint() string { func (c *Client) Endpoint() string {
return c.endpoint return c.endpoint
} }
// Ping pings the docker server // Ping pings the docker server
// //
// See https://goo.gl/wYfgY1 for more details. // See https://goo.gl/wYfgY1 for more details.
func (c *Client) Ping() error { func (c *Client) Ping() error {
return c.PingWithContext(nil) return c.PingWithContext(context.TODO())
} }
// PingWithContext pings the docker server // PingWithContext pings the docker server
// The context object can be used to cancel the ping request. // The context object can be used to cancel the ping request.
// //
// See https://goo.gl/wYfgY1 for more details. // See https://goo.gl/wYfgY1 for more details.
func (c *Client) PingWithContext(ctx context.Context) error { func (c *Client) PingWithContext(ctx context.Context) error {
path := "/_ping" path := "/_ping"
resp, err := c.do("GET", path, doOptions{context: ctx}) resp, err := c.do("GET", path, doOptions{context: ctx})
if err != nil { if err != nil {
skipping to change at line 417 skipping to change at line 418
return nil return nil
} }
func (c *Client) getServerAPIVersionString() (version string, err error) { func (c *Client) getServerAPIVersionString() (version string, err error) {
resp, err := c.do("GET", "/version", doOptions{}) resp, err := c.do("GET", "/version", doOptions{})
if err != nil { if err != nil {
return "", err return "", err
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("Received unexpected status %d while trying to retrieve the server version", resp.StatusCode) return "", fmt.Errorf("received unexpected status %d while trying to retrieve the server version", resp.StatusCode)
} }
var versionResponse map[string]interface{} var versionResponse map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&versionResponse); err != nil { if err := json.NewDecoder(resp.Body).Decode(&versionResponse); err != nil {
return "", err return "", err
} }
if version, ok := (versionResponse["ApiVersion"]).(string); ok { if version, ok := (versionResponse["ApiVersion"]).(string); ok {
return version, nil return version, nil
} }
return "", nil return "", nil
} }
skipping to change at line 531 skipping to change at line 532
func (c *Client) stream(method, path string, streamOptions streamOptions) error { func (c *Client) stream(method, path string, streamOptions streamOptions) error {
if (method == "POST" || method == "PUT") && streamOptions.in == nil { if (method == "POST" || method == "PUT") && streamOptions.in == nil {
streamOptions.in = bytes.NewReader(nil) streamOptions.in = bytes.NewReader(nil)
} }
if path != "/version" && !c.SkipServerVersionCheck && c.expectedAPIVersio n == nil { if path != "/version" && !c.SkipServerVersionCheck && c.expectedAPIVersio n == nil {
err := c.checkAPIVersion() err := c.checkAPIVersion()
if err != nil { if err != nil {
return err return err
} }
} }
req, err := http.NewRequest(method, c.getURL(path), streamOptions.in) return c.streamUrl(method, c.getURL(path), streamOptions)
}
func (c *Client) streamUrl(method, url string, streamOptions streamOptions) erro
r {
if (method == "POST" || method == "PUT") && streamOptions.in == nil {
streamOptions.in = bytes.NewReader(nil)
}
if !c.SkipServerVersionCheck && c.expectedAPIVersion == nil {
err := c.checkAPIVersion()
if err != nil {
return err
}
}
req, err := http.NewRequest(method, url, streamOptions.in)
if err != nil { if err != nil {
return err return err
} }
req.Header.Set("User-Agent", userAgent) req.Header.Set("User-Agent", userAgent)
if method == "POST" { if method == "POST" {
req.Header.Set("Content-Type", "plain/text") req.Header.Set("Content-Type", "plain/text")
} }
for key, val := range streamOptions.headers { for key, val := range streamOptions.headers {
req.Header.Set(key, val) req.Header.Set(key, val)
} }
skipping to change at line 642 skipping to change at line 656
_, err = stdcopy.StdCopy(streamOptions.stdout, streamOpti ons.stderr, resp.Body) _, err = stdcopy.StdCopy(streamOptions.stdout, streamOpti ons.stderr, resp.Body)
} }
return err return err
} }
// if we want to get raw json stream, just copy it back to output // if we want to get raw json stream, just copy it back to output
// without decoding it // without decoding it
if streamOptions.rawJSONStream { if streamOptions.rawJSONStream {
_, err = io.Copy(streamOptions.stdout, resp.Body) _, err = io.Copy(streamOptions.stdout, resp.Body)
return err return err
} }
if st, ok := streamOptions.stdout.(interface { if st, ok := streamOptions.stdout.(stream); ok {
io.Writer
FD() uintptr
IsTerminal() bool
}); ok {
err = jsonmessage.DisplayJSONMessagesToStream(resp.Body, st, nil) err = jsonmessage.DisplayJSONMessagesToStream(resp.Body, st, nil)
} else { } else {
err = jsonmessage.DisplayJSONMessagesStream(resp.Body, streamOpti ons.stdout, 0, false, nil) err = jsonmessage.DisplayJSONMessagesStream(resp.Body, streamOpti ons.stdout, 0, false, nil)
} }
return err return err
} }
type stream interface {
io.Writer
FD() uintptr
IsTerminal() bool
}
type proxyReader struct { type proxyReader struct {
io.ReadCloser io.ReadCloser
calls uint64 calls uint64
} }
func (p *proxyReader) callCount() uint64 { func (p *proxyReader) callCount() uint64 {
return atomic.LoadUint64(&p.calls) return atomic.LoadUint64(&p.calls)
} }
func (p *proxyReader) Read(data []byte) (int, error) { func (p *proxyReader) Read(data []byte) (int, error) {
skipping to change at line 763 skipping to change at line 779
} else { } else {
dial, err = c.Dialer.Dial(protocol, address) dial, err = c.Dialer.Dial(protocol, address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
errs := make(chan error, 1) errs := make(chan error, 1)
quit := make(chan struct{}) quit := make(chan struct{})
go func() { go func() {
//lint:ignore SA1019 this is needed here
clientconn := httputil.NewClientConn(dial, nil) clientconn := httputil.NewClientConn(dial, nil)
defer clientconn.Close() defer clientconn.Close()
clientconn.Do(req) clientconn.Do(req)
if hijackOptions.success != nil { if hijackOptions.success != nil {
hijackOptions.success <- struct{}{} hijackOptions.success <- struct{}{}
<-hijackOptions.success <-hijackOptions.success
} }
rwc, br := clientconn.Hijack() rwc, br := clientconn.Hijack()
defer rwc.Close() defer rwc.Close()
skipping to change at line 859 skipping to change at line 876
urlStr := strings.TrimRight(c.endpointURL.String(), "/") urlStr := strings.TrimRight(c.endpointURL.String(), "/")
if c.endpointURL.Scheme == unixProtocol || c.endpointURL.Scheme == namedP ipeProtocol { if c.endpointURL.Scheme == unixProtocol || c.endpointURL.Scheme == namedP ipeProtocol {
urlStr = "" urlStr = ""
} }
if c.requestedAPIVersion != nil { if c.requestedAPIVersion != nil {
return fmt.Sprintf("%s/v%s%s", urlStr, c.requestedAPIVersion, pat h) return fmt.Sprintf("%s/v%s%s", urlStr, c.requestedAPIVersion, pat h)
} }
return fmt.Sprintf("%s%s", urlStr, path) return fmt.Sprintf("%s%s", urlStr, path)
} }
func (c *Client) getPath(basepath string, opts interface{}) (string, error) {
urlStr := strings.TrimRight(c.endpointURL.String(), "/")
if c.endpointURL.Scheme == unixProtocol || c.endpointURL.Scheme == namedP
ipeProtocol {
urlStr = ""
}
queryStr, requiredAPIVersion := queryStringVersion(opts)
if c.requestedAPIVersion != nil {
if c.requestedAPIVersion.GreaterThanOrEqualTo(requiredAPIVersion)
{
return fmt.Sprintf("%s/v%s%s?%s", urlStr, c.requestedAPIV
ersion, basepath, queryStr), nil
} else {
return "", fmt.Errorf("API %s requires version %s, reques
ted version %s is insufficient",
basepath, requiredAPIVersion, c.requestedAPIVersi
on)
}
}
if requiredAPIVersion != nil {
return fmt.Sprintf("%s/v%s%s?%s", urlStr, requiredAPIVersion, bas
epath, queryStr), nil
} else {
return fmt.Sprintf("%s%s?%s", urlStr, basepath, queryStr), nil
}
}
// getFakeNativeURL returns the URL needed to make an HTTP request over a UNIX // getFakeNativeURL returns the URL needed to make an HTTP request over a UNIX
// domain socket to the given path. // domain socket to the given path.
func (c *Client) getFakeNativeURL(path string) string { func (c *Client) getFakeNativeURL(path string) string {
u := *c.endpointURL // Copy. u := *c.endpointURL // Copy.
// Override URL so that net/http will not complain. // Override URL so that net/http will not complain.
u.Scheme = "http" u.Scheme = "http"
u.Host = "unix.sock" // Doesn't matter what this is - it's not used. u.Host = "unix.sock" // Doesn't matter what this is - it's not used.
u.Path = "" u.Path = ""
urlStr := strings.TrimRight(u.String(), "/") urlStr := strings.TrimRight(u.String(), "/")
if c.requestedAPIVersion != nil { if c.requestedAPIVersion != nil {
return fmt.Sprintf("%s/v%s%s", urlStr, c.requestedAPIVersion, pat h) return fmt.Sprintf("%s/v%s%s", urlStr, c.requestedAPIVersion, pat h)
} }
return fmt.Sprintf("%s%s", urlStr, path) return fmt.Sprintf("%s%s", urlStr, path)
} }
type jsonMessage struct { func queryStringVersion(opts interface{}) (string, APIVersion) {
Status string `json:"status,omitempty"`
Progress string `json:"progress,omitempty"`
Error string `json:"error,omitempty"`
Stream string `json:"stream,omitempty"`
}
func queryString(opts interface{}) string {
if opts == nil { if opts == nil {
return "" return "", nil
} }
value := reflect.ValueOf(opts) value := reflect.ValueOf(opts)
if value.Kind() == reflect.Ptr { if value.Kind() == reflect.Ptr {
value = value.Elem() value = value.Elem()
} }
if value.Kind() != reflect.Struct { if value.Kind() != reflect.Struct {
return "" return "", nil
} }
var apiVersion APIVersion = nil
items := url.Values(map[string][]string{}) items := url.Values(map[string][]string{})
for i := 0; i < value.NumField(); i++ { for i := 0; i < value.NumField(); i++ {
field := value.Type().Field(i) field := value.Type().Field(i)
if field.PkgPath != "" { if field.PkgPath != "" {
continue continue
} }
key := field.Tag.Get("qs") key := field.Tag.Get("qs")
if key == "" { if key == "" {
key = strings.ToLower(field.Name) key = strings.ToLower(field.Name)
} else if key == "-" { } else if key == "-" {
continue continue
} }
addQueryStringValue(items, key, value.Field(i)) if addQueryStringValue(items, key, value.Field(i)) {
verstr := field.Tag.Get("ver")
if verstr != "" {
ver, _ := NewAPIVersion(verstr)
if apiVersion == nil {
apiVersion = ver
} else if ver.GreaterThan(apiVersion) {
apiVersion = ver
}
}
}
} }
return items.Encode() return items.Encode(), apiVersion
} }
func addQueryStringValue(items url.Values, key string, v reflect.Value) { func queryString(opts interface{}) string {
s, _ := queryStringVersion(opts)
return s
}
func addQueryStringValue(items url.Values, key string, v reflect.Value) bool {
switch v.Kind() { switch v.Kind() {
case reflect.Bool: case reflect.Bool:
if v.Bool() { if v.Bool() {
items.Add(key, "1") items.Add(key, "1")
return true
} }
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int 64: case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int 64:
if v.Int() > 0 { if v.Int() > 0 {
items.Add(key, strconv.FormatInt(v.Int(), 10)) items.Add(key, strconv.FormatInt(v.Int(), 10))
return true
} }
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect .Uint64: case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect .Uint64:
if v.Uint() > 0 { if v.Uint() > 0 {
items.Add(key, strconv.FormatUint(v.Uint(), 10)) items.Add(key, strconv.FormatUint(v.Uint(), 10))
return true
} }
case reflect.Float32, reflect.Float64: case reflect.Float32, reflect.Float64:
if v.Float() > 0 { if v.Float() > 0 {
items.Add(key, strconv.FormatFloat(v.Float(), 'f', -1, 64 )) items.Add(key, strconv.FormatFloat(v.Float(), 'f', -1, 64 ))
return true
} }
case reflect.String: case reflect.String:
if v.String() != "" { if v.String() != "" {
items.Add(key, v.String()) items.Add(key, v.String())
return true
} }
case reflect.Ptr: case reflect.Ptr:
if !v.IsNil() { if !v.IsNil() {
if b, err := json.Marshal(v.Interface()); err == nil { if b, err := json.Marshal(v.Interface()); err == nil {
items.Add(key, string(b)) items.Add(key, string(b))
return true
} }
} }
case reflect.Map: case reflect.Map:
if len(v.MapKeys()) > 0 { if len(v.MapKeys()) > 0 {
if b, err := json.Marshal(v.Interface()); err == nil { if b, err := json.Marshal(v.Interface()); err == nil {
items.Add(key, string(b)) items.Add(key, string(b))
return true
} }
} }
case reflect.Array, reflect.Slice: case reflect.Array, reflect.Slice:
vLen := v.Len() vLen := v.Len()
var valuesAdded int
if vLen > 0 { if vLen > 0 {
for i := 0; i < vLen; i++ { for i := 0; i < vLen; i++ {
addQueryStringValue(items, key, v.Index(i)) if addQueryStringValue(items, key, v.Index(i)) {
valuesAdded += 1
}
} }
} }
return valuesAdded > 0
} }
return false
} }
// Error represents failures in the API. It represents a failure from the API. // Error represents failures in the API. It represents a failure from the API.
type Error struct { type Error struct {
Status int Status int
Message string Message string
} }
func newError(resp *http.Response) *Error { func newError(resp *http.Response) *Error {
type ErrMsg struct { type ErrMsg struct {
skipping to change at line 1032 skipping to change at line 1092
type dockerEnv struct { type dockerEnv struct {
dockerHost string dockerHost string
dockerTLSVerify bool dockerTLSVerify bool
dockerCertPath string dockerCertPath string
} }
func getDockerEnv() (*dockerEnv, error) { func getDockerEnv() (*dockerEnv, error) {
dockerHost := os.Getenv("DOCKER_HOST") dockerHost := os.Getenv("DOCKER_HOST")
var err error var err error
if dockerHost == "" { if dockerHost == "" {
dockerHost = opts.DefaultHost dockerHost = defaultHost
} }
dockerTLSVerify := os.Getenv("DOCKER_TLS_VERIFY") != "" dockerTLSVerify := os.Getenv("DOCKER_TLS_VERIFY") != ""
var dockerCertPath string var dockerCertPath string
if dockerTLSVerify { if dockerTLSVerify {
dockerCertPath = os.Getenv("DOCKER_CERT_PATH") dockerCertPath = os.Getenv("DOCKER_CERT_PATH")
if dockerCertPath == "" { if dockerCertPath == "" {
home := homedir.Get() home := homedir.Get()
if home == "" { if home == "" {
return nil, errors.New("environment variable HOME must be set if DOCKER_CERT_PATH is not set") return nil, errors.New("environment variable HOME must be set if DOCKER_CERT_PATH is not set")
} }
 End of changes. 33 change blocks. 
30 lines changed or deleted 97 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)