summaryrefslogtreecommitdiff
path: root/vendor/github.com/docker/go-plugins-helpers/sdk/handler.go
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2020-11-16 14:32:12 -0500
committerMatthew Heon <mheon@redhat.com>2020-12-01 12:56:55 -0500
commit594ac4a14658a90ad7bc5541dab6349a0c629a5c (patch)
treed43d561d74c6331166bca6f5101b7d0fd8d8bd1d /vendor/github.com/docker/go-plugins-helpers/sdk/handler.go
parent429d9492f85faf4c3a595b9d7b2a38743a4b8e42 (diff)
downloadpodman-594ac4a14658a90ad7bc5541dab6349a0c629a5c.tar.gz
podman-594ac4a14658a90ad7bc5541dab6349a0c629a5c.tar.bz2
podman-594ac4a14658a90ad7bc5541dab6349a0c629a5c.zip
Add API for communicating with Docker volume plugins
Docker provides extensibility through a plugin system, of which several types are available. This provides an initial library API for communicating with one type of plugins, volume plugins. Volume plugins allow for an external service to create and manage a volume on Podman's behalf. This does not integrate the plugin system into Libpod or Podman yet; that will come in subsequent pull requests. Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'vendor/github.com/docker/go-plugins-helpers/sdk/handler.go')
-rw-r--r--vendor/github.com/docker/go-plugins-helpers/sdk/handler.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/vendor/github.com/docker/go-plugins-helpers/sdk/handler.go b/vendor/github.com/docker/go-plugins-helpers/sdk/handler.go
new file mode 100644
index 000000000..c0d042ed0
--- /dev/null
+++ b/vendor/github.com/docker/go-plugins-helpers/sdk/handler.go
@@ -0,0 +1,88 @@
+package sdk
+
+import (
+ "crypto/tls"
+ "fmt"
+ "net"
+ "net/http"
+ "os"
+)
+
+const activatePath = "/Plugin.Activate"
+
+// Handler is the base to create plugin handlers.
+// It initializes connections and sockets to listen to.
+type Handler struct {
+ mux *http.ServeMux
+}
+
+// NewHandler creates a new Handler with an http mux.
+func NewHandler(manifest string) Handler {
+ mux := http.NewServeMux()
+
+ mux.HandleFunc(activatePath, func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", DefaultContentTypeV1_1)
+ fmt.Fprintln(w, manifest)
+ })
+
+ return Handler{mux: mux}
+}
+
+// Serve sets up the handler to serve requests on the passed in listener
+func (h Handler) Serve(l net.Listener) error {
+ server := http.Server{
+ Addr: l.Addr().String(),
+ Handler: h.mux,
+ }
+ return server.Serve(l)
+}
+
+// ServeTCP makes the handler to listen for request in a given TCP address.
+// It also writes the spec file in the right directory for docker to read.
+// Due to constrains for running Docker in Docker on Windows, data-root directory
+// of docker daemon must be provided. To get default directory, use
+// WindowsDefaultDaemonRootDir() function. On Unix, this parameter is ignored.
+func (h Handler) ServeTCP(pluginName, addr, daemonDir string, tlsConfig *tls.Config) error {
+ l, spec, err := newTCPListener(addr, pluginName, daemonDir, tlsConfig)
+ if err != nil {
+ return err
+ }
+ if spec != "" {
+ defer os.Remove(spec)
+ }
+ return h.Serve(l)
+}
+
+// ServeUnix makes the handler to listen for requests in a unix socket.
+// It also creates the socket file in the right directory for docker to read.
+func (h Handler) ServeUnix(addr string, gid int) error {
+ l, spec, err := newUnixListener(addr, gid)
+ if err != nil {
+ return err
+ }
+ if spec != "" {
+ defer os.Remove(spec)
+ }
+ return h.Serve(l)
+}
+
+// ServeWindows makes the handler to listen for request in a Windows named pipe.
+// It also creates the spec file in the right directory for docker to read.
+// Due to constrains for running Docker in Docker on Windows, data-root directory
+// of docker daemon must be provided. To get default directory, use
+// WindowsDefaultDaemonRootDir() function. On Unix, this parameter is ignored.
+func (h Handler) ServeWindows(addr, pluginName, daemonDir string, pipeConfig *WindowsPipeConfig) error {
+ l, spec, err := newWindowsListener(addr, pluginName, daemonDir, pipeConfig)
+ if err != nil {
+ return err
+ }
+ if spec != "" {
+ defer os.Remove(spec)
+ }
+ return h.Serve(l)
+}
+
+// HandleFunc registers a function to handle a request path with.
+func (h Handler) HandleFunc(path string, fn func(w http.ResponseWriter, r *http.Request)) {
+ h.mux.HandleFunc(path, fn)
+}