mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Allow docker plugin inspect
to search based on ID or name
This fix tries to address the issue raised in discussion of
PR 28735 where it was not possible to manage plugin based on
plugin ID. Previously it was not possible to invoke
`docker plugin inspect` with a plugin ID (or ID prefix).
This fix updates the implementation of `docker plugin inspect`
so that it is possbile to search based on a plugin name, or a
plugin ID. A short format of plugin ID (prefix) is also possible,
as long as there is no ambiguity.
Previously the check of `docker plugin inspect` was mostly done
on the client side. This could potentially cause inconsistency
between API and CMD. This fix move all the checks to daemon side
so that API and CMD will be consistent.
An integration test has been added to cover the changes.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 0ce6e070f7
)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
12aa5ea8b1
commit
3477da0cdb
5 changed files with 129 additions and 25 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api/types"
|
||||
|
@ -23,6 +24,11 @@ import (
|
|||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var (
|
||||
validFullID = regexp.MustCompile(`^([a-f0-9]{64})$`)
|
||||
validPartialID = regexp.MustCompile(`^([a-f0-9]{1,64})$`)
|
||||
)
|
||||
|
||||
// Disable deactivates a plugin, which implies that they cannot be used by containers.
|
||||
func (pm *Manager) Disable(name string) error {
|
||||
p, err := pm.pluginStore.GetByName(name)
|
||||
|
@ -53,12 +59,32 @@ func (pm *Manager) Enable(name string, config *types.PluginEnableConfig) error {
|
|||
}
|
||||
|
||||
// Inspect examines a plugin config
|
||||
func (pm *Manager) Inspect(name string) (tp types.Plugin, err error) {
|
||||
p, err := pm.pluginStore.GetByName(name)
|
||||
if err != nil {
|
||||
func (pm *Manager) Inspect(refOrID string) (tp types.Plugin, err error) {
|
||||
// Match on full ID
|
||||
if validFullID.MatchString(refOrID) {
|
||||
p, err := pm.pluginStore.GetByID(refOrID)
|
||||
if err == nil {
|
||||
return p.PluginObj, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Match on full name
|
||||
if pluginName, err := getPluginName(refOrID); err == nil {
|
||||
if p, err := pm.pluginStore.GetByName(pluginName); err == nil {
|
||||
return p.PluginObj, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Match on partial ID
|
||||
if validPartialID.MatchString(refOrID) {
|
||||
p, err := pm.pluginStore.Search(refOrID)
|
||||
if err == nil {
|
||||
return p.PluginObj, nil
|
||||
}
|
||||
return tp, err
|
||||
}
|
||||
return p.PluginObj, nil
|
||||
|
||||
return tp, fmt.Errorf("no plugin name or ID associated with %q", refOrID)
|
||||
}
|
||||
|
||||
func (pm *Manager) pull(ref reference.Named, metaHeader http.Header, authConfig *types.AuthConfig, pluginID string) (types.PluginPrivileges, error) {
|
||||
|
@ -244,3 +270,18 @@ func (pm *Manager) createFromContext(ctx context.Context, pluginID, pluginDir st
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPluginName(name string) (string, error) {
|
||||
named, err := reference.ParseNamed(name) // FIXME: validate
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if reference.IsNameOnly(named) {
|
||||
named = reference.WithDefaultTag(named)
|
||||
}
|
||||
ref, ok := named.(reference.NamedTagged)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid name: %s", named.String())
|
||||
}
|
||||
return ref.String(), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue