From ba86626642f54dbea51413a7153173254f51f382 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Mon, 15 Jan 2024 10:59:33 +0900 Subject: [PATCH] vendor.mod: github.com/rootless-containers/rootlesskit/v2 v2.0.0 https://github.com/rootless-containers/rootlesskit/releases/tag/v2.0.0 Signed-off-by: Akihiro Suda --- daemon/info_unix.go | 2 +- vendor.mod | 2 +- vendor.sum | 6 +- .../rootlesskit/{ => v2}/LICENSE | 0 .../rootlesskit/{ => v2}/pkg/api/api.go | 5 - .../{ => v2}/pkg/api/client/client.go | 81 ++-------------- .../rootlesskit/{ => v2}/pkg/api/openapi.yaml | 0 .../rootlesskit/v2/pkg/httputil/httputil.go | 96 +++++++++++++++++++ .../rootlesskit/{ => v2}/pkg/port/port.go | 7 +- vendor/modules.txt | 9 +- 10 files changed, 118 insertions(+), 90 deletions(-) rename vendor/github.com/rootless-containers/rootlesskit/{ => v2}/LICENSE (100%) rename vendor/github.com/rootless-containers/rootlesskit/{ => v2}/pkg/api/api.go (89%) rename vendor/github.com/rootless-containers/rootlesskit/{ => v2}/pkg/api/client/client.go (60%) rename vendor/github.com/rootless-containers/rootlesskit/{ => v2}/pkg/api/openapi.yaml (100%) create mode 100644 vendor/github.com/rootless-containers/rootlesskit/v2/pkg/httputil/httputil.go rename vendor/github.com/rootless-containers/rootlesskit/{ => v2}/pkg/port/port.go (87%) diff --git a/daemon/info_unix.go b/daemon/info_unix.go index eeedbbd6d8..b12de6f601 100644 --- a/daemon/info_unix.go +++ b/daemon/info_unix.go @@ -21,7 +21,7 @@ import ( "github.com/docker/docker/pkg/rootless" "github.com/docker/docker/pkg/sysinfo" "github.com/pkg/errors" - rkclient "github.com/rootless-containers/rootlesskit/pkg/api/client" + rkclient "github.com/rootless-containers/rootlesskit/v2/pkg/api/client" ) // fillPlatformInfo fills the platform related info. diff --git a/vendor.mod b/vendor.mod index 4536aaca69..353460ed99 100644 --- a/vendor.mod +++ b/vendor.mod @@ -82,7 +82,7 @@ require ( github.com/pelletier/go-toml v1.9.5 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 - github.com/rootless-containers/rootlesskit v1.1.1 + github.com/rootless-containers/rootlesskit/v2 v2.0.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 diff --git a/vendor.sum b/vendor.sum index 720ebfe6bb..a54391a61b 100644 --- a/vendor.sum +++ b/vendor.sum @@ -117,8 +117,8 @@ github.com/Graylog2/go-gelf v0.0.0-20191017102106-1550ee647df0/go.mod h1:fBaQWrf github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver/v3 v3.0.3/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/semver/v3 v3.1.0 h1:Y2lUDsFKVRSYGojLJ1yLxSXdMmMYTYls0rCvoqmMUQk= github.com/Masterminds/semver/v3 v3.1.0/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= github.com/Microsoft/go-winio v0.4.15-0.20200908182639-5b44b70ab3ab/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= @@ -1102,8 +1102,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rootless-containers/rootlesskit v1.1.1 h1:F5psKWoWY9/VjZ3ifVcaosjvFZJOagX85U22M0/EQZE= -github.com/rootless-containers/rootlesskit v1.1.1/go.mod h1:UD5GoA3dqKCJrnvnhVgQQnweMF2qZnf9KLw8EewcMZI= +github.com/rootless-containers/rootlesskit/v2 v2.0.0 h1:oAtnD6sgsNmdxXCm5zont5nEYTAkSqExmQOalZYiYJM= +github.com/rootless-containers/rootlesskit/v2 v2.0.0/go.mod h1:G7x0sK6onoLhFYZahpSsM/HaWEAh664SK5nCeQs4MQE= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rubiojr/go-vhd v0.0.0-20160810183302-0bfd3b39853c/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= diff --git a/vendor/github.com/rootless-containers/rootlesskit/LICENSE b/vendor/github.com/rootless-containers/rootlesskit/v2/LICENSE similarity index 100% rename from vendor/github.com/rootless-containers/rootlesskit/LICENSE rename to vendor/github.com/rootless-containers/rootlesskit/v2/LICENSE diff --git a/vendor/github.com/rootless-containers/rootlesskit/pkg/api/api.go b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/api.go similarity index 89% rename from vendor/github.com/rootless-containers/rootlesskit/pkg/api/api.go rename to vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/api.go index 5d74cae493..d310e6d312 100644 --- a/vendor/github.com/rootless-containers/rootlesskit/pkg/api/api.go +++ b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/api.go @@ -8,11 +8,6 @@ const ( Version = "1.1.1" ) -// ErrorJSON is returned with "application/json" content type and non-2XX status code -type ErrorJSON struct { - Message string `json:"message"` -} - // Info is the structure returned by `GET /info` type Info struct { APIVersion string `json:"apiVersion"` // REST API version diff --git a/vendor/github.com/rootless-containers/rootlesskit/pkg/api/client/client.go b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/client/client.go similarity index 60% rename from vendor/github.com/rootless-containers/rootlesskit/pkg/api/client/client.go rename to vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/client/client.go index 53dcadd5e4..0624312480 100644 --- a/vendor/github.com/rootless-containers/rootlesskit/pkg/api/client/client.go +++ b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/client/client.go @@ -4,15 +4,12 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" - "io" - "net" "net/http" - "os" - "github.com/rootless-containers/rootlesskit/pkg/api" - "github.com/rootless-containers/rootlesskit/pkg/port" + "github.com/rootless-containers/rootlesskit/v2/pkg/api" + "github.com/rootless-containers/rootlesskit/v2/pkg/httputil" + "github.com/rootless-containers/rootlesskit/v2/pkg/port" ) type Client interface { @@ -24,17 +21,10 @@ type Client interface { // New creates a client. // socketPath is a path to the UNIX socket, without unix:// prefix. func New(socketPath string) (Client, error) { - if _, err := os.Stat(socketPath); err != nil { + hc, err := httputil.NewHTTPClient(socketPath) + if err != nil { return nil, err } - hc := &http.Client{ - Transport: &http.Transport{ - DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { - var d net.Dialer - return d.DialContext(ctx, "unix", socketPath) - }, - }, - } return NewWithHTTPClient(hc), nil } @@ -76,7 +66,7 @@ func (c *client) Info(ctx context.Context) (*api.Info, error) { return nil, err } defer resp.Body.Close() - if err := successful(resp); err != nil { + if err := httputil.Successful(resp); err != nil { return nil, err } var info api.Info @@ -87,59 +77,6 @@ func (c *client) Info(ctx context.Context) (*api.Info, error) { return &info, nil } -func readAtMost(r io.Reader, maxBytes int) ([]byte, error) { - lr := &io.LimitedReader{ - R: r, - N: int64(maxBytes), - } - b, err := io.ReadAll(lr) - if err != nil { - return b, err - } - if lr.N == 0 { - return b, fmt.Errorf("expected at most %d bytes, got more", maxBytes) - } - return b, nil -} - -// HTTPStatusErrorBodyMaxLength specifies the maximum length of HTTPStatusError.Body -const HTTPStatusErrorBodyMaxLength = 64 * 1024 - -// HTTPStatusError is created from non-2XX HTTP response -type HTTPStatusError struct { - // StatusCode is non-2XX status code - StatusCode int - // Body is at most HTTPStatusErrorBodyMaxLength - Body string -} - -// Error implements error. -// If e.Body is a marshalled string of api.ErrorJSON, Error returns ErrorJSON.Message . -// Otherwise Error returns a human-readable string that contains e.StatusCode and e.Body. -func (e *HTTPStatusError) Error() string { - if e.Body != "" && len(e.Body) < HTTPStatusErrorBodyMaxLength { - var ej api.ErrorJSON - if json.Unmarshal([]byte(e.Body), &ej) == nil { - return ej.Message - } - } - return fmt.Sprintf("unexpected HTTP status %s, body=%q", http.StatusText(e.StatusCode), e.Body) -} - -func successful(resp *http.Response) error { - if resp == nil { - return errors.New("nil response") - } - if resp.StatusCode/100 != 2 { - b, _ := readAtMost(resp.Body, HTTPStatusErrorBodyMaxLength) - return &HTTPStatusError{ - StatusCode: resp.StatusCode, - Body: string(b), - } - } - return nil -} - type portManager struct { *client } @@ -161,7 +98,7 @@ func (pm *portManager) AddPort(ctx context.Context, spec port.Spec) (*port.Statu return nil, err } defer resp.Body.Close() - if err := successful(resp); err != nil { + if err := httputil.Successful(resp); err != nil { return nil, err } dec := json.NewDecoder(resp.Body) @@ -183,7 +120,7 @@ func (pm *portManager) ListPorts(ctx context.Context) ([]port.Status, error) { return nil, err } defer resp.Body.Close() - if err := successful(resp); err != nil { + if err := httputil.Successful(resp); err != nil { return nil, err } var statuses []port.Status @@ -205,7 +142,7 @@ func (pm *portManager) RemovePort(ctx context.Context, id int) error { return err } defer resp.Body.Close() - if err := successful(resp); err != nil { + if err := httputil.Successful(resp); err != nil { return err } return nil diff --git a/vendor/github.com/rootless-containers/rootlesskit/pkg/api/openapi.yaml b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/openapi.yaml similarity index 100% rename from vendor/github.com/rootless-containers/rootlesskit/pkg/api/openapi.yaml rename to vendor/github.com/rootless-containers/rootlesskit/v2/pkg/api/openapi.yaml diff --git a/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/httputil/httputil.go b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/httputil/httputil.go new file mode 100644 index 0000000000..e2f4d1a58b --- /dev/null +++ b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/httputil/httputil.go @@ -0,0 +1,96 @@ +package httputil + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "net" + "net/http" + "os" +) + +// ErrorJSON is returned with "application/json" content type and non-2XX status code +type ErrorJSON struct { + Message string `json:"message"` +} + +func readAtMost(r io.Reader, maxBytes int) ([]byte, error) { + lr := &io.LimitedReader{ + R: r, + N: int64(maxBytes), + } + b, err := io.ReadAll(lr) + if err != nil { + return b, err + } + if lr.N == 0 { + return b, fmt.Errorf("expected at most %d bytes, got more", maxBytes) + } + return b, nil +} + +// HTTPStatusErrorBodyMaxLength specifies the maximum length of HTTPStatusError.Body +const HTTPStatusErrorBodyMaxLength = 64 * 1024 + +// HTTPStatusError is created from non-2XX HTTP response +type HTTPStatusError struct { + // StatusCode is non-2XX status code + StatusCode int + // Body is at most HTTPStatusErrorBodyMaxLength + Body string +} + +// Error implements error. +// If e.Body is a marshalled string of api.ErrorJSON, Error returns ErrorJSON.Message . +// Otherwise Error returns a human-readable string that contains e.StatusCode and e.Body. +func (e *HTTPStatusError) Error() string { + if e.Body != "" && len(e.Body) < HTTPStatusErrorBodyMaxLength { + var ej ErrorJSON + if json.Unmarshal([]byte(e.Body), &ej) == nil { + return ej.Message + } + } + return fmt.Sprintf("unexpected HTTP status %s, body=%q", http.StatusText(e.StatusCode), e.Body) +} + +// Successful returns an error if the status code is not 2xx. +func Successful(resp *http.Response) error { + if resp == nil { + return errors.New("nil response") + } + if resp.StatusCode/100 != 2 { + b, _ := readAtMost(resp.Body, HTTPStatusErrorBodyMaxLength) + return &HTTPStatusError{ + StatusCode: resp.StatusCode, + Body: string(b), + } + } + return nil +} + +func NewHTTPClient(socketPath string) (*http.Client, error) { + if _, err := os.Stat(socketPath); err != nil { + return nil, err + } + return &http.Client{ + Transport: &http.Transport{ + DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { + var d net.Dialer + return d.DialContext(ctx, "unix", socketPath) + }, + }, + }, nil +} + +// WriteError writes an error. +// WriteError sould not be used if an error may contain sensitive information and the client is not reliable. +func WriteError(w http.ResponseWriter, r *http.Request, err error, ec int) { + w.WriteHeader(ec) + w.Header().Set("Content-Type", "application/json") + e := ErrorJSON{ + Message: err.Error(), + } + _ = json.NewEncoder(w).Encode(e) +} diff --git a/vendor/github.com/rootless-containers/rootlesskit/pkg/port/port.go b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/port/port.go similarity index 87% rename from vendor/github.com/rootless-containers/rootlesskit/pkg/port/port.go rename to vendor/github.com/rootless-containers/rootlesskit/v2/pkg/port/port.go index c95bfc7c74..d0213aed1e 100644 --- a/vendor/github.com/rootless-containers/rootlesskit/pkg/port/port.go +++ b/vendor/github.com/rootless-containers/rootlesskit/v2/pkg/port/port.go @@ -4,7 +4,7 @@ import ( "context" "net" - "github.com/rootless-containers/rootlesskit/pkg/api" + "github.com/rootless-containers/rootlesskit/v2/pkg/api" ) type Spec struct { @@ -35,8 +35,6 @@ type Manager interface { // ChildContext is used for RunParentDriver type ChildContext struct { - // PID of the child, can be used for ns-entering to the child namespaces. - PID int // IP of the tap device IP net.IP } @@ -57,5 +55,6 @@ type ParentDriver interface { } type ChildDriver interface { - RunChildDriver(opaque map[string]string, quit <-chan struct{}) error + // RunChildDriver is executed in the child's namespaces, excluding detached-netns. + RunChildDriver(opaque map[string]string, quit <-chan struct{}, detachedNetNSPath string) error } diff --git a/vendor/modules.txt b/vendor/modules.txt index f0e7879131..5c70b78cc6 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1002,11 +1002,12 @@ github.com/prometheus/common/model github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/rootless-containers/rootlesskit v1.1.1 +# github.com/rootless-containers/rootlesskit/v2 v2.0.0 ## explicit; go 1.19 -github.com/rootless-containers/rootlesskit/pkg/api -github.com/rootless-containers/rootlesskit/pkg/api/client -github.com/rootless-containers/rootlesskit/pkg/port +github.com/rootless-containers/rootlesskit/v2/pkg/api +github.com/rootless-containers/rootlesskit/v2/pkg/api/client +github.com/rootless-containers/rootlesskit/v2/pkg/httputil +github.com/rootless-containers/rootlesskit/v2/pkg/port # github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 ## explicit github.com/sean-/seed