mirror of
https://github.com/docker/cli.git
synced 2026-11-06 13:10:41 -04:00
Merge pull request #7348 from thaJeztah/bump_client
vendor: github.com/moby/moby/client v0.6.1, moby/api v1.56.1
This commit is contained in:
+2
-2
@@ -33,8 +33,8 @@ require (
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/mattn/go-runewidth v0.0.29
|
||||
github.com/moby/go-archive v0.3.3
|
||||
github.com/moby/moby/api v1.56.0
|
||||
github.com/moby/moby/client v0.6.0
|
||||
github.com/moby/moby/api v1.56.1
|
||||
github.com/moby/moby/client v0.6.1
|
||||
github.com/moby/patternmatcher v0.6.1
|
||||
github.com/moby/swarmkit/v2 v2.1.2
|
||||
github.com/moby/sys/atomicwriter v0.1.0
|
||||
|
||||
+4
-4
@@ -88,10 +88,10 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N
|
||||
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
||||
github.com/moby/go-archive v0.3.3 h1:OxxR9paxsluYi+zDUEXTTaIxtkK3viymW+Ka7vRhhME=
|
||||
github.com/moby/go-archive v0.3.3/go.mod h1:Npdv43fFqlhZW7Xo8fbm3ZMYFvAGNviUPqX21VERbcE=
|
||||
github.com/moby/moby/api v1.56.0 h1:GQzua3NA599ASSIICx0iFgiJeO9YkdDARvQsm23ZZuQ=
|
||||
github.com/moby/moby/api v1.56.0/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk=
|
||||
github.com/moby/moby/client v0.6.0 h1:AJjEB21QPbXSXjDsZorFBoDZPhMrfbpaPLgSMAW9Bgs=
|
||||
github.com/moby/moby/client v0.6.0/go.mod h1:OCo00wNRyA3m4lmJ228W3JbyCN4ZNNYjpOXiJydBdcQ=
|
||||
github.com/moby/moby/api v1.56.1 h1:PpWkvVPB7Fr/No8w+TfyJ/I6rWZ2YPZhT3JorIg+06c=
|
||||
github.com/moby/moby/api v1.56.1/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk=
|
||||
github.com/moby/moby/client v0.6.1 h1:gvfKmdcWw+9MzXYP0vAUKQtBTGu1L8475K2nsmL7O98=
|
||||
github.com/moby/moby/client v0.6.1/go.mod h1:XHgTFqz9NCgS/VuoxXMmEDVmVgXQ4vFEc15wsCIwb24=
|
||||
github.com/moby/patternmatcher v0.6.1 h1:qlhtafmr6kgMIJjKJMDmMWq7WLkKIo23hsrpR3x084U=
|
||||
github.com/moby/patternmatcher v0.6.1/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
|
||||
github.com/moby/swarmkit/v2 v2.1.2 h1:1WDZAI6HVYNKdCG4zlXnTAPyLsLwuhRGWlHoOUf5Z6I=
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ func Encode(authConfig registry.AuthConfig) (string, error) {
|
||||
//
|
||||
// FIXME(thaJeztah): find exactly what code-paths are impacted by this.
|
||||
// if authConfig == (AuthConfig{}) { return "", nil }
|
||||
buf, err := json.Marshal(authConfig)
|
||||
buf, err := json.Marshal(authConfig) // #nosec G117 -- intentionally marshaling auth.
|
||||
if err != nil {
|
||||
return "", errInvalidParameter{err}
|
||||
}
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package build
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// DiskUsage represents system data usage for build cache resources.
|
||||
//
|
||||
// swagger:model DiskUsage
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package common
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ErrorResponse Represents an error.
|
||||
// Example: {"message":"Something went wrong."}
|
||||
//
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package common
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// IDResponse Response to an API call that returns just an Id
|
||||
//
|
||||
// swagger:model IDResponse
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ChangeType Kind of change
|
||||
//
|
||||
// Can be one of:
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// CreateResponse ContainerCreateResponse
|
||||
//
|
||||
// # OK response to ContainerCreate operation
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// DiskUsage represents system data usage information for container resources.
|
||||
//
|
||||
// swagger:model DiskUsage
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// FilesystemChange Change in the container's filesystem.
|
||||
//
|
||||
// swagger:model FilesystemChange
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// TopResponse ContainerTopResponse
|
||||
//
|
||||
// Container "top" response.
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// UpdateResponse ContainerUpdateResponse
|
||||
//
|
||||
// Response for a successful container-update.
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// WaitExitError container waiting error, if any
|
||||
//
|
||||
// swagger:model WaitExitError
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// WaitResponse ContainerWaitResponse
|
||||
//
|
||||
// # OK response to ContainerWait operation
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package image
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// DeleteResponse delete response
|
||||
//
|
||||
// swagger:model DeleteResponse
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package image
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// DiskUsage represents system data usage for image resources.
|
||||
//
|
||||
// swagger:model DiskUsage
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package image
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// HistoryResponseItem HistoryResponseItem
|
||||
//
|
||||
// individual image layer information in response to ImageHistory operation
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ConfigReference The config-only network source to provide the configuration for
|
||||
// this network.
|
||||
//
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ConnectRequest NetworkConnectRequest represents the data to be used to connect a container to a network.
|
||||
//
|
||||
// swagger:model ConnectRequest
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// CreateResponse NetworkCreateResponse
|
||||
//
|
||||
// # OK response to NetworkCreate operation
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// DisconnectRequest NetworkDisconnectRequest represents the data to be used to disconnect a container from a network.
|
||||
//
|
||||
// swagger:model DisconnectRequest
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Inspect The body of the "get network" http response message.
|
||||
//
|
||||
// swagger:model Inspect
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// IPAMStatus IPAM status
|
||||
//
|
||||
// swagger:model IPAMStatus
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
timeext "time"
|
||||
)
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Status provides runtime information about the network such as the number of allocated IPs.
|
||||
//
|
||||
// swagger:model Status
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// SubnetStatus subnet status
|
||||
//
|
||||
// swagger:model SubnetStatus
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Summary Network list response item
|
||||
//
|
||||
// swagger:model Summary
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package network
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package plugin
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Device device
|
||||
//
|
||||
// swagger:model Device
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package plugin
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Env env
|
||||
//
|
||||
// swagger:model Env
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package plugin
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Mount mount
|
||||
//
|
||||
// swagger:model Mount
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package plugin
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Plugin A plugin for the Engine API
|
||||
//
|
||||
// swagger:model Plugin
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package registry
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// AuthResponse An identity token was generated successfully.
|
||||
//
|
||||
// swagger:model AuthResponse
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package storage
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// DriverData Information about the storage driver used to store the container's and
|
||||
// image's filesystem.
|
||||
//
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package storage
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// RootFSStorage Information about the storage used for the container's root filesystem.
|
||||
//
|
||||
// swagger:model RootFSStorage
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package storage
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// RootFSStorageSnapshot Information about a snapshot backend of the container's root filesystem.
|
||||
//
|
||||
// swagger:model RootFSStorageSnapshot
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package storage
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Storage Information about the storage used by the container.
|
||||
//
|
||||
// swagger:model Storage
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package swarm
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ServiceCreateResponse contains the information returned to a client on the
|
||||
// creation of a new service.
|
||||
//
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package swarm
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ServiceUpdateResponse service update response
|
||||
// Example: {"Warnings":["unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"]}
|
||||
//
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package volume
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// CreateRequest VolumeConfig
|
||||
//
|
||||
// # Volume configuration
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package volume
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// DiskUsage represents system data usage for volume resources.
|
||||
//
|
||||
// swagger:model DiskUsage
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package volume
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ListResponse VolumeListResponse
|
||||
//
|
||||
// # Volume list response
|
||||
|
||||
-3
@@ -2,9 +2,6 @@
|
||||
|
||||
package volume
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// Volume volume
|
||||
//
|
||||
// swagger:model Volume
|
||||
|
||||
+5
-5
@@ -60,7 +60,6 @@ import (
|
||||
"net/url"
|
||||
"path"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -250,10 +249,11 @@ func New(ops ...Opt) (*Client, error) {
|
||||
|
||||
c.client.Transport = otelhttp.NewTransport(c.client.Transport, c.traceOpts...)
|
||||
|
||||
if len(cfg.responseHooks) > 0 {
|
||||
c.client.Transport = &responseHookTransport{
|
||||
base: c.client.Transport,
|
||||
hooks: slices.Clone(cfg.responseHooks),
|
||||
if len(cfg.requestHooks) > 0 || len(cfg.responseHooks) > 0 {
|
||||
c.client.Transport = &hookTransport{
|
||||
base: c.client.Transport,
|
||||
reqHooks: cfg.requestHooks,
|
||||
respHooks: cfg.responseHooks,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type hookTransport struct {
|
||||
base http.RoundTripper
|
||||
reqHooks []RequestHook
|
||||
respHooks []ResponseHook
|
||||
}
|
||||
|
||||
func (t *hookTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if len(t.reqHooks) > 0 {
|
||||
hookReq := req.Clone(req.Context())
|
||||
|
||||
if hookReq.Body != nil {
|
||||
hookReq.Body = hookBody{}
|
||||
}
|
||||
if hookReq.GetBody != nil {
|
||||
hookReq.GetBody = func() (io.ReadCloser, error) {
|
||||
return hookBody{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
for _, h := range t.reqHooks {
|
||||
if err := h(hookReq); err != nil {
|
||||
// The base transport never takes ownership, so close the original
|
||||
// request body before returning the hook error.
|
||||
if req.Body != nil {
|
||||
_ = req.Body.Close()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// Restore the actual request body after the hooks have run. The
|
||||
// modified request metadata is preserved on hookReq.
|
||||
hookReq.Body = req.Body
|
||||
hookReq.GetBody = req.GetBody
|
||||
req = hookReq
|
||||
}
|
||||
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if len(t.respHooks) > 0 {
|
||||
hookResp := *resp
|
||||
if hookResp.Body != nil {
|
||||
hookResp.Body = hookBody{}
|
||||
}
|
||||
|
||||
for _, h := range t.respHooks {
|
||||
h(&hookResp)
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type hookBody struct{}
|
||||
|
||||
func (hookBody) Read([]byte) (int, error) {
|
||||
return 0, errors.New("hooks must not read HTTP message body")
|
||||
}
|
||||
|
||||
func (hookBody) Close() error { return nil }
|
||||
+35
-3
@@ -58,13 +58,23 @@ type clientConfig struct {
|
||||
// takes precedence. Either field disables API-version negotiation.
|
||||
envAPIVersion string
|
||||
|
||||
// responseHooks is a list of custom response hooks to call on responses.
|
||||
// requestHooks contains hooks to call before requests are made.
|
||||
requestHooks []RequestHook
|
||||
// responseHooks contains hooks to call on responses.
|
||||
responseHooks []ResponseHook
|
||||
|
||||
// traceOpts is a list of options to configure the tracing span.
|
||||
traceOpts []otelhttp.Option
|
||||
}
|
||||
|
||||
// RequestHook is called for each HTTP request made by the client.
|
||||
// Hooks are invoked in the order they were added.
|
||||
//
|
||||
// Hooks may inspect the request and modify request metadata, such as headers,
|
||||
// before the request is sent. The request body cannot be read or closed by
|
||||
// the hook.
|
||||
type RequestHook func(*http.Request) error
|
||||
|
||||
// ResponseHook is called for each HTTP response returned by the daemon.
|
||||
// Hooks are invoked in the order they were added.
|
||||
//
|
||||
@@ -411,12 +421,25 @@ func WithTraceOptions(opts ...otelhttp.Option) Opt {
|
||||
}
|
||||
}
|
||||
|
||||
// WithResponseHook adds a ResponseHook to the client. ResponseHooks are called
|
||||
// WithHTTPRequestHook adds a [RequestHook] to the client. RequestHooks are called
|
||||
// before an HTTP request is made to the daemon. Hooks are invoked in the order
|
||||
// they were added.
|
||||
func WithHTTPRequestHook(h RequestHook) Opt {
|
||||
return func(c *clientConfig) error {
|
||||
if h == nil {
|
||||
return errors.New("invalid request hook: hook is nil")
|
||||
}
|
||||
c.requestHooks = append(c.requestHooks, h)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithHTTPResponseHook adds a [ResponseHook] to the client. ResponseHooks are called
|
||||
// for each HTTP response returned by the daemon. Hooks are invoked in the order
|
||||
// they were added.
|
||||
//
|
||||
// Hooks must not read or close resp.Body.
|
||||
func WithResponseHook(h ResponseHook) Opt {
|
||||
func WithHTTPResponseHook(h ResponseHook) Opt {
|
||||
return func(c *clientConfig) error {
|
||||
if h == nil {
|
||||
return errors.New("invalid response hook: hook is nil")
|
||||
@@ -425,3 +448,12 @@ func WithResponseHook(h ResponseHook) Opt {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithResponseHook is equivalent to [WithHTTPResponseHook].
|
||||
//
|
||||
// Deprecated: use [WithHTTPResponseHook] instead.
|
||||
//
|
||||
//go:fix inline
|
||||
func WithResponseHook(h ResponseHook) Opt {
|
||||
return WithHTTPResponseHook(h)
|
||||
}
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type responseHookTransport struct {
|
||||
base http.RoundTripper
|
||||
hooks []ResponseHook
|
||||
}
|
||||
|
||||
func (t *responseHookTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
for _, h := range t.hooks {
|
||||
h(resp)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
+2
-3
@@ -75,9 +75,8 @@ func (cli *Client) ContainerAttach(ctx context.Context, containerID string, opti
|
||||
query.Set("logs", "1")
|
||||
}
|
||||
|
||||
hijacked, err := cli.postHijacked(ctx, "/containers/"+containerID+"/attach", query, nil, http.Header{
|
||||
"Content-Type": {"text/plain"},
|
||||
})
|
||||
headers := http.Header{"Content-Type": {"text/plain"}}
|
||||
hijacked, err := cli.postHijacked(ctx, "/containers/"+containerID+"/attach", query, headers, nil)
|
||||
if err != nil {
|
||||
return ContainerAttachResult{}, err
|
||||
}
|
||||
|
||||
+2
-4
@@ -134,13 +134,11 @@ func (cli *Client) ExecAttach(ctx context.Context, execID string, options ExecAt
|
||||
if err != nil {
|
||||
return ExecAttachResult{}, err
|
||||
}
|
||||
req := container.ExecStartRequest{
|
||||
headers := http.Header{"Content-Type": {"application/json"}}
|
||||
response, err := cli.postHijacked(ctx, "/exec/"+execID+"/start", nil, headers, container.ExecStartRequest{
|
||||
Detach: false,
|
||||
Tty: options.TTY,
|
||||
ConsoleSize: consoleSize,
|
||||
}
|
||||
response, err := cli.postHijacked(ctx, "/exec/"+execID+"/start", nil, req, http.Header{
|
||||
"Content-Type": {"application/json"},
|
||||
})
|
||||
return ExecAttachResult{HijackedResponse: response}, err
|
||||
}
|
||||
|
||||
+18
-6
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// postHijacked sends a POST request and hijacks the connection.
|
||||
func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body any, headers map[string][]string) (HijackedResponse, error) {
|
||||
func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, headers map[string][]string, body any) (HijackedResponse, error) {
|
||||
jsonBody, err := jsonEncode(body)
|
||||
if err != nil {
|
||||
return HijackedResponse{}, err
|
||||
@@ -22,7 +22,7 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
|
||||
if err != nil {
|
||||
return HijackedResponse{}, err
|
||||
}
|
||||
conn, mediaType, err := setupHijackConn(cli.dialer(), req, "tcp")
|
||||
conn, mediaType, err := cli.setupHijackConn(req, "tcp")
|
||||
if err != nil {
|
||||
return HijackedResponse{}, err
|
||||
}
|
||||
@@ -38,16 +38,17 @@ func (cli *Client) DialHijack(ctx context.Context, url, proto string, meta map[s
|
||||
}
|
||||
req = cli.addHeaders(req, meta)
|
||||
|
||||
conn, _, err := setupHijackConn(cli.Dialer(), req, proto)
|
||||
conn, _, err := cli.setupHijackConn(req, proto)
|
||||
return conn, err
|
||||
}
|
||||
|
||||
func setupHijackConn(dialer func(context.Context) (net.Conn, error), req *http.Request, proto string) (_ net.Conn, _ string, retErr error) {
|
||||
func (cli *Client) setupHijackConn(req *http.Request, proto string) (_ net.Conn, _ string, retErr error) {
|
||||
ctx := req.Context()
|
||||
req.Header.Set("Connection", "Upgrade")
|
||||
req.Header.Set("Upgrade", proto)
|
||||
|
||||
conn, err := dialer(ctx)
|
||||
dial := cli.dialer()
|
||||
conn, err := dial(ctx)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: %w", err)
|
||||
}
|
||||
@@ -69,8 +70,19 @@ func setupHijackConn(dialer func(context.Context) (net.Conn, error), req *http.R
|
||||
|
||||
hc := &hijackedConn{conn, bufio.NewReader(conn)}
|
||||
|
||||
cfg := &cli.clientConfig
|
||||
|
||||
var rt http.RoundTripper = otelhttp.NewTransport(hc, cli.traceOpts...)
|
||||
if len(cfg.requestHooks) > 0 || len(cfg.responseHooks) > 0 {
|
||||
rt = &hookTransport{
|
||||
base: rt,
|
||||
reqHooks: cfg.requestHooks,
|
||||
respHooks: cfg.responseHooks,
|
||||
}
|
||||
}
|
||||
|
||||
// Server hijacks the connection, error 'connection closed' expected
|
||||
resp, err := otelhttp.NewTransport(hc).RoundTrip(req)
|
||||
resp, err := rt.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
+1
-3
@@ -19,12 +19,10 @@ type PluginCreateResult struct {
|
||||
|
||||
// PluginCreate creates a plugin
|
||||
func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions PluginCreateOptions) (PluginCreateResult, error) {
|
||||
headers := http.Header(make(map[string][]string))
|
||||
headers.Set("Content-Type", "application/x-tar")
|
||||
|
||||
query := url.Values{}
|
||||
query.Set("name", createOptions.RepoName)
|
||||
|
||||
headers := http.Header{"Content-Type": {"application/x-tar"}}
|
||||
resp, err := cli.postRaw(ctx, "/plugins/create", query, headers, createContext)
|
||||
defer ensureReaderClosed(resp)
|
||||
return PluginCreateResult{}, err
|
||||
|
||||
Vendored
+2
-2
@@ -167,7 +167,7 @@ github.com/moby/go-archive
|
||||
github.com/moby/go-archive/compression
|
||||
github.com/moby/go-archive/internal/archiveoptions
|
||||
github.com/moby/go-archive/tarheader
|
||||
# github.com/moby/moby/api v1.56.0
|
||||
# github.com/moby/moby/api v1.56.1
|
||||
## explicit; go 1.24
|
||||
github.com/moby/moby/api/pkg/authconfig
|
||||
github.com/moby/moby/api/pkg/stdcopy
|
||||
@@ -189,7 +189,7 @@ github.com/moby/moby/api/types/storage
|
||||
github.com/moby/moby/api/types/swarm
|
||||
github.com/moby/moby/api/types/system
|
||||
github.com/moby/moby/api/types/volume
|
||||
# github.com/moby/moby/client v0.6.0
|
||||
# github.com/moby/moby/client v0.6.1
|
||||
## explicit; go 1.24
|
||||
github.com/moby/moby/client
|
||||
github.com/moby/moby/client/internal
|
||||
|
||||
Reference in New Issue
Block a user