From 7c006ff288e1e7889a2687219c55d0d552840efe Mon Sep 17 00:00:00 2001 From: Anusha Ragunathan Date: Tue, 4 Oct 2016 12:01:19 -0700 Subject: [PATCH] Add plugin create functionality. Signed-off-by: Anusha Ragunathan Upstream-commit: 3d7a95829efba4f088ea8632d6fd1cdfbb5db366 Component: cli --- components/cli/interface_experimental.go | 3 +++ components/cli/plugin_create.go | 26 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 components/cli/plugin_create.go diff --git a/components/cli/interface_experimental.go b/components/cli/interface_experimental.go index 4f5cf853b8..709b5d8ffb 100644 --- a/components/cli/interface_experimental.go +++ b/components/cli/interface_experimental.go @@ -1,6 +1,8 @@ package client import ( + "io" + "github.com/docker/docker/api/types" "golang.org/x/net/context" ) @@ -27,4 +29,5 @@ type PluginAPIClient interface { PluginPush(ctx context.Context, name string, registryAuth string) error PluginSet(ctx context.Context, name string, args []string) error PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) + PluginCreate(ctx context.Context, createContext io.Reader, options types.PluginCreateOptions) error } diff --git a/components/cli/plugin_create.go b/components/cli/plugin_create.go new file mode 100644 index 0000000000..a660ba5733 --- /dev/null +++ b/components/cli/plugin_create.go @@ -0,0 +1,26 @@ +package client + +import ( + "io" + "net/http" + "net/url" + + "github.com/docker/docker/api/types" + "golang.org/x/net/context" +) + +// PluginCreate creates a plugin +func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error { + headers := http.Header(make(map[string][]string)) + headers.Set("Content-Type", "application/tar") + + query := url.Values{} + query.Set("name", createOptions.RepoName) + + resp, err := cli.postRaw(ctx, "/plugins/create", query, createContext, headers) + if err != nil { + return err + } + ensureReaderClosed(resp) + return err +}