From 78311eeeafa2825d535faa461983096aea5db84f Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Tue, 29 Nov 2016 17:31:29 -0800 Subject: [PATCH] Support plugins in `docker inspect` This fix tries to address the proposal raised in 28946 to support plugins in `docker inspect`. The command `docker inspect` already supports "container", "image", "node", "network", "service", "volume", "task". However, `--type plugin` is not supported yet at the moment. This fix address this issue by adding the support of `--type plugin` for `docker inspect`. An additional integration test has been added to cover the changes. This fix fixes 28946. Signed-off-by: Yong Tang Upstream-commit: 47f0fde2cf0c09e571d476c680229086a9e994ef Component: cli --- components/cli/errors.go | 21 +++++++++++++++++++++ components/cli/plugin_inspect.go | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/components/cli/errors.go b/components/cli/errors.go index 854516669c..bf6923f134 100644 --- a/components/cli/errors.go +++ b/components/cli/errors.go @@ -255,3 +255,24 @@ func IsErrSecretNotFound(err error) bool { _, ok := err.(secretNotFoundError) return ok } + +// pluginNotFoundError implements an error returned when a plugin is not in the docker host. +type pluginNotFoundError struct { + name string +} + +// NotFound indicates that this error type is of NotFound +func (e pluginNotFoundError) NotFound() bool { + return true +} + +// Error returns a string representation of a pluginNotFoundError +func (e pluginNotFoundError) Error() string { + return fmt.Sprintf("Error: No such plugin: %s", e.name) +} + +// IsErrPluginNotFound returns true if the error is caused +// when a plugin is not found in the docker host. +func IsErrPluginNotFound(err error) bool { + return IsErrNotFound(err) +} diff --git a/components/cli/plugin_inspect.go b/components/cli/plugin_inspect.go index e9474b5a98..72900a1310 100644 --- a/components/cli/plugin_inspect.go +++ b/components/cli/plugin_inspect.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "io/ioutil" + "net/http" "github.com/docker/docker/api/types" "golang.org/x/net/context" @@ -13,6 +14,9 @@ import ( func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) { resp, err := cli.get(ctx, "/plugins/"+name, nil, nil) if err != nil { + if resp.statusCode == http.StatusNotFound { + return nil, nil, pluginNotFoundError{name} + } return nil, nil, err }