From 1658c119f0c4a44b65b8aa9513529d1220f649c6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Jun 2024 16:10:18 +0200 Subject: [PATCH 1/6] add go.mod Using the lowest version of docker/docker still maintained (23.0 is maintained as LTS version by mirantis) Signed-off-by: Sebastiaan van Stijn --- Makefile | 5 ++--- go.mod | 18 ++++++++++++++++++ go.sum | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/Makefile b/Makefile index 623d509..2a94779 100644 --- a/Makefile +++ b/Makefile @@ -12,12 +12,11 @@ test-local: install-deps fmt lint vet @go test -v ./... test: - @docker run -e GO111MODULE=off -v ${shell pwd}:/go/src/${PKG_NAME} -w /go/src/${PKG_NAME} ${IMAGE} make test-local + @docker run --rm -v ${shell pwd}:/go/src/${PKG_NAME} -w /go/src/${PKG_NAME} ${IMAGE} make test-local install-deps: @echo "+ $@" - @go get -u golang.org/x/lint/golint - @go get -d -t ./... + @go install golang.org/x/lint/golint@latest lint: @echo "+ $@" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9721ab3 --- /dev/null +++ b/go.mod @@ -0,0 +1,18 @@ +module github.com/docker/go-plugins-helpers + +go 1.21 + +require ( + github.com/Microsoft/go-winio v0.6.2 + github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf + github.com/docker/docker v23.0.13+incompatible + github.com/docker/go-connections v0.5.0 + github.com/stretchr/testify v1.9.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.10.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ffd8795 --- /dev/null +++ b/go.sum @@ -0,0 +1,20 @@ +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU= +github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/docker v23.0.13+incompatible h1:il+Z3USrag/LJkF5apR6APO5sVpjm82jm/wp5XvO4hQ= +github.com/docker/docker v23.0.13+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 4164228077914a72100f6be665a8d942c97fdf23 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Jun 2024 15:25:45 +0200 Subject: [PATCH 2/6] sdk: update to github.com/coreos/go-systemd/v22 Update to use the currently maintained version of this dependency, which is also used elsewhere. Signed-off-by: Sebastiaan van Stijn --- go.mod | 2 +- go.sum | 5 +++-- sdk/unix_listener_systemd.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 9721ab3..0efdce5 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/Microsoft/go-winio v0.6.2 - github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf + github.com/coreos/go-systemd/v22 v22.5.0 github.com/docker/docker v23.0.13+incompatible github.com/docker/go-connections v0.5.0 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index ffd8795..eb6036d 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,14 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU= -github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docker/docker v23.0.13+incompatible h1:il+Z3USrag/LJkF5apR6APO5sVpjm82jm/wp5XvO4hQ= github.com/docker/docker v23.0.13+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= diff --git a/sdk/unix_listener_systemd.go b/sdk/unix_listener_systemd.go index 59c53bf..8117673 100644 --- a/sdk/unix_listener_systemd.go +++ b/sdk/unix_listener_systemd.go @@ -7,7 +7,7 @@ import ( "net" "os" - "github.com/coreos/go-systemd/activation" + "github.com/coreos/go-systemd/v22/activation" ) // isRunningSystemd checks whether the host was booted with systemd as its init From 633a1690dab88fafd665ace17f04adb954485188 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Jun 2024 16:48:02 +0200 Subject: [PATCH 3/6] authorization: remove github.com/stretchr/testify/require dependency It was only used for basic assertions; replace those with stdlib Signed-off-by: Sebastiaan van Stijn --- authorization/api_test.go | 37 +++++++++++++++++++++++++++---------- go.mod | 8 +------- go.sum | 10 ---------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/authorization/api_test.go b/authorization/api_test.go index 5532b2b..dd8e39b 100644 --- a/authorization/api_test.go +++ b/authorization/api_test.go @@ -17,7 +17,6 @@ import ( "time" "github.com/docker/go-plugins-helpers/sdk" - "github.com/stretchr/testify/require" ) type TestPlugin struct { @@ -150,21 +149,29 @@ func TestPeerCertificateMarshalJSON(t *testing.T) { } // generate private key privatekey, err := rsa.GenerateKey(rand.Reader, 2048) - require.NoError(t, err) + if err != nil { + t.Fatal(err) + } publickey := &privatekey.PublicKey // create a self-signed certificate. template = parent parent := template raw, err := x509.CreateCertificate(rand.Reader, template, parent, publickey, privatekey) - require.NoError(t, err) + if err != nil { + t.Fatal(err) + } cert, err := x509.ParseCertificate(raw) - require.NoError(t, err) + if err != nil { + t.Fatal(err) + } certs := []*x509.Certificate{cert} addr := "www.authz.com/auth" req, err := http.NewRequest("GET", addr, nil) - require.NoError(t, err) + if err != nil { + t.Fatal(err) + } req.RequestURI = addr req.TLS = &tls.ConnectionState{} @@ -176,15 +183,25 @@ func TestPeerCertificateMarshalJSON(t *testing.T) { t.Run("Marshalling :", func(t *testing.T) { raw, err = pcObj.MarshalJSON() - require.NotNil(t, raw) - require.Nil(t, err) + if raw == nil { + t.Fatalf("Failed to marshal peer certificate") + } + if err != nil { + t.Fatal(err) + } }) t.Run("UnMarshalling :", func(t *testing.T) { err := pcObj.UnmarshalJSON(raw) - require.Nil(t, err) - require.Equal(t, "Earth", pcObj.Subject.Country[0]) - require.Equal(t, true, pcObj.IsCA) + if err != nil { + t.Fatal(err) + } + if expected := "Earth"; pcObj.Subject.Country[0] != expected { + t.Fatalf("Expected %s, got %s\n", expected, pcObj.Subject.Country[0]) + } + if pcObj.IsCA != true { + t.Fatalf("Expected %t, got %t\n", true, pcObj.IsCA) + } }) } diff --git a/go.mod b/go.mod index 0efdce5..3c58365 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,6 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 github.com/docker/docker v23.0.13+incompatible github.com/docker/go-connections v0.5.0 - github.com/stretchr/testify v1.9.0 ) -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.10.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +require golang.org/x/sys v0.10.0 // indirect diff --git a/go.sum b/go.sum index eb6036d..75702d5 100644 --- a/go.sum +++ b/go.sum @@ -2,20 +2,10 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docker/docker v23.0.13+incompatible h1:il+Z3USrag/LJkF5apR6APO5sVpjm82jm/wp5XvO4hQ= github.com/docker/docker v23.0.13+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 420084521c3b58c12d1b30c8baa2d1364c21fe31 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Jun 2024 17:59:51 +0200 Subject: [PATCH 4/6] sdk: remove code for systemd socket-activation It was added in 008703b825c10311af1840deeaf5f4769df7b59e, but none of the functions are exported, and none of them are currently called. Signed-off-by: Sebastiaan van Stijn --- go.mod | 1 - go.sum | 3 --- sdk/unix_listener_nosystemd.go | 10 -------- sdk/unix_listener_systemd.go | 45 ---------------------------------- 4 files changed, 59 deletions(-) delete mode 100644 sdk/unix_listener_nosystemd.go delete mode 100644 sdk/unix_listener_systemd.go diff --git a/go.mod b/go.mod index 3c58365..b5b5252 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.21 require ( github.com/Microsoft/go-winio v0.6.2 - github.com/coreos/go-systemd/v22 v22.5.0 github.com/docker/docker v23.0.13+incompatible github.com/docker/go-connections v0.5.0 ) diff --git a/go.sum b/go.sum index 75702d5..b66c8c8 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/docker/docker v23.0.13+incompatible h1:il+Z3USrag/LJkF5apR6APO5sVpjm82jm/wp5XvO4hQ= github.com/docker/docker v23.0.13+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/sdk/unix_listener_nosystemd.go b/sdk/unix_listener_nosystemd.go deleted file mode 100644 index 1a9247b..0000000 --- a/sdk/unix_listener_nosystemd.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build (linux || freebsd) && nosystemd - -package sdk - -import "net" - -// FIXME(thaJeztah): this code was added in https://github.com/docker/go-plugins-helpers/commit/008703b825c10311af1840deeaf5f4769df7b59e, but is not used anywhere -func setupSocketActivation() (net.Listener, error) { - return nil, nil -} diff --git a/sdk/unix_listener_systemd.go b/sdk/unix_listener_systemd.go deleted file mode 100644 index 8117673..0000000 --- a/sdk/unix_listener_systemd.go +++ /dev/null @@ -1,45 +0,0 @@ -//go:build (linux || freebsd) && !nosystemd - -package sdk - -import ( - "fmt" - "net" - "os" - - "github.com/coreos/go-systemd/v22/activation" -) - -// isRunningSystemd checks whether the host was booted with systemd as its init -// system. This functions similarly to systemd's `sd_booted(3)`: internally, it -// checks whether /run/systemd/system/ exists and is a directory. -// http://www.freedesktop.org/software/systemd/man/sd_booted.html -// -// Copied from github.com/coreos/go-systemd/util.IsRunningSystemd -func isRunningSystemd() bool { - fi, err := os.Lstat("/run/systemd/system") - if err != nil { - return false - } - return fi.IsDir() -} - -// FIXME(thaJeztah): this code was added in https://github.com/docker/go-plugins-helpers/commit/008703b825c10311af1840deeaf5f4769df7b59e, but is not used anywhere -func setupSocketActivation() (net.Listener, error) { - if !isRunningSystemd() { - return nil, nil - } - listenFds := activation.Files(false) - if len(listenFds) > 1 { - return nil, fmt.Errorf("expected only one socket from systemd, got %d", len(listenFds)) - } - var listener net.Listener - if len(listenFds) == 1 { - l, err := net.FileListener(listenFds[0]) - if err != nil { - return nil, err - } - listener = l - } - return listener, nil -} From 834777b80500ba046cc735675b7d826618d469c9 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Wed, 13 Aug 2025 18:33:47 +0200 Subject: [PATCH 5/6] volume/shim: drop it The volume shim driver was introduced in commit 61113e3. It's supposed to help plugin authors focus on the volume driver API, rather than the plugin API. However, this means the plugins SDK is pulling in github.com/docker/docker. Since moby/moby@04f5276, the Engine's volume package has been moved into the daemon package, and is considered an implementation detail that no one should import. Looking at the use of `NewHandlerFromVolumeDriver` on grep.app, and Sourcegraph, it seems no one is using it. So drop it unceremoniously. Signed-off-by: Albin Kerouanton --- volume/shim/shim.go | 109 --------------------------------------- volume/shim/shim_test.go | 59 --------------------- 2 files changed, 168 deletions(-) delete mode 100644 volume/shim/shim.go delete mode 100644 volume/shim/shim_test.go diff --git a/volume/shim/shim.go b/volume/shim/shim.go deleted file mode 100644 index 0dec1a1..0000000 --- a/volume/shim/shim.go +++ /dev/null @@ -1,109 +0,0 @@ -package shim - -import ( - "github.com/docker/docker/volume" - volumeplugin "github.com/docker/go-plugins-helpers/volume" -) - -type shimDriver struct { - d volume.Driver -} - -// NewHandlerFromVolumeDriver creates a plugin handler from an existing volume -// driver. This could be used, for instance, by the `local` volume driver built-in -// to Docker Engine and it would create a plugin from it that maps plugin API calls -// directly to any volume driver that satisfies the volume.Driver interface from -// Docker Engine. -func NewHandlerFromVolumeDriver(d volume.Driver) *volumeplugin.Handler { - return volumeplugin.NewHandler(&shimDriver{d}) -} - -func (d *shimDriver) Create(req *volumeplugin.CreateRequest) error { - _, err := d.d.Create(req.Name, req.Options) - return err -} - -func (d *shimDriver) List() (*volumeplugin.ListResponse, error) { - var res *volumeplugin.ListResponse - ls, err := d.d.List() - if err != nil { - return &volumeplugin.ListResponse{}, err - } - vols := make([]*volumeplugin.Volume, len(ls)) - - for i, v := range ls { - vol := &volumeplugin.Volume{ - Name: v.Name(), - Mountpoint: v.Path(), - } - vols[i] = vol - } - res.Volumes = vols - return res, nil -} - -func (d *shimDriver) Get(req *volumeplugin.GetRequest) (*volumeplugin.GetResponse, error) { - var res *volumeplugin.GetResponse - v, err := d.d.Get(req.Name) - if err != nil { - return &volumeplugin.GetResponse{}, err - } - res.Volume = &volumeplugin.Volume{ - Name: v.Name(), - Mountpoint: v.Path(), - Status: v.Status(), - } - return &volumeplugin.GetResponse{}, nil -} - -func (d *shimDriver) Remove(req *volumeplugin.RemoveRequest) error { - v, err := d.d.Get(req.Name) - if err != nil { - return err - } - if err := d.d.Remove(v); err != nil { - return err - } - return nil -} - -func (d *shimDriver) Path(req *volumeplugin.PathRequest) (*volumeplugin.PathResponse, error) { - var res *volumeplugin.PathResponse - v, err := d.d.Get(req.Name) - if err != nil { - return &volumeplugin.PathResponse{}, err - } - res.Mountpoint = v.Path() - return res, nil -} - -func (d *shimDriver) Mount(req *volumeplugin.MountRequest) (*volumeplugin.MountResponse, error) { - var res *volumeplugin.MountResponse - v, err := d.d.Get(req.Name) - if err != nil { - return &volumeplugin.MountResponse{}, err - } - pth, err := v.Mount(req.ID) - if err != nil { - return &volumeplugin.MountResponse{}, err - } - res.Mountpoint = pth - return res, nil -} - -func (d *shimDriver) Unmount(req *volumeplugin.UnmountRequest) error { - v, err := d.d.Get(req.Name) - if err != nil { - return err - } - if err := v.Unmount(req.ID); err != nil { - return err - } - return nil -} - -func (d *shimDriver) Capabilities() *volumeplugin.CapabilitiesResponse { - var res *volumeplugin.CapabilitiesResponse - res.Capabilities = volumeplugin.Capability{Scope: d.d.Scope()} - return res -} diff --git a/volume/shim/shim_test.go b/volume/shim/shim_test.go deleted file mode 100644 index bb765fb..0000000 --- a/volume/shim/shim_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package shim - -import ( - "bytes" - "encoding/json" - "net/http" - "testing" - - "github.com/docker/docker/volume" - "github.com/docker/go-connections/sockets" - volumeplugin "github.com/docker/go-plugins-helpers/volume" -) - -type testVolumeDriver struct{} - -func (testVolumeDriver) Name() string { return "" } -func (testVolumeDriver) Create(string, map[string]string) (volume.Volume, error) { return nil, nil } -func (testVolumeDriver) Remove(volume.Volume) error { return nil } -func (testVolumeDriver) List() ([]volume.Volume, error) { return nil, nil } -func (testVolumeDriver) Get(name string) (volume.Volume, error) { return nil, nil } -func (testVolumeDriver) Scope() string { return "local" } - -func TestVolumeDriver(t *testing.T) { - h := NewHandlerFromVolumeDriver(testVolumeDriver{}) - l := sockets.NewInmemSocket("test", 0) - go h.Serve(l) - defer l.Close() - - client := &http.Client{Transport: &http.Transport{ - Dial: l.Dial, - }} - - resp, err := pluginRequest(client, "/VolumeDriver.Create", &volumeplugin.CreateRequest{Name: "foo"}) - if err != nil { - t.Fatalf(err.Error()) - } - - if resp.Err != "" { - t.Fatalf("error while creating volume: %v", err) - } -} - -func pluginRequest(client *http.Client, method string, req *volumeplugin.CreateRequest) (*volumeplugin.ErrorResponse, error) { - b, err := json.Marshal(req) - if err != nil { - return nil, err - } - resp, err := client.Post("http://localhost"+method, "application/json", bytes.NewReader(b)) - if err != nil { - return nil, err - } - var vResp volumeplugin.ErrorResponse - err = json.NewDecoder(resp.Body).Decode(&vResp) - if err != nil { - return nil, err - } - - return &vResp, nil -} From 7349107bc43adc14cb63ab230fb0e9c3ca084575 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Wed, 13 Aug 2025 18:46:04 +0200 Subject: [PATCH 6/6] go.mod: remove dependency on github.com/docker/docker This makes it possible to import this module into github.com/moby/moby such that we can avoid duplicating Go API types across repos. Signed-off-by: Albin Kerouanton --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index b5b5252..9588de4 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.21 require ( github.com/Microsoft/go-winio v0.6.2 - github.com/docker/docker v23.0.13+incompatible github.com/docker/go-connections v0.5.0 ) diff --git a/go.sum b/go.sum index b66c8c8..9fc01b3 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/docker/docker v23.0.13+incompatible h1:il+Z3USrag/LJkF5apR6APO5sVpjm82jm/wp5XvO4hQ= -github.com/docker/docker v23.0.13+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=