mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add capability
filter to docker plugin ls
This fix adds `--filter capability=[volumedriver|authz]` to `docker plugin ls`. The related docs has been updated. An integration test has been added. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
a66e0dc349
commit
99d91ada97
5 changed files with 70 additions and 3 deletions
|
@ -31,6 +31,10 @@ func TestPluginList(t *testing.T) {
|
||||||
enabledFilters := filters.NewArgs()
|
enabledFilters := filters.NewArgs()
|
||||||
enabledFilters.Add("enabled", "true")
|
enabledFilters.Add("enabled", "true")
|
||||||
|
|
||||||
|
capabilityFilters := filters.NewArgs()
|
||||||
|
capabilityFilters.Add("capability", "volumedriver")
|
||||||
|
capabilityFilters.Add("capability", "authz")
|
||||||
|
|
||||||
listCases := []struct {
|
listCases := []struct {
|
||||||
filters filters.Args
|
filters filters.Args
|
||||||
expectedQueryParams map[string]string
|
expectedQueryParams map[string]string
|
||||||
|
@ -51,6 +55,14 @@ func TestPluginList(t *testing.T) {
|
||||||
"filters": `{"enabled":{"true":true}}`,
|
"filters": `{"enabled":{"true":true}}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filters: capabilityFilters,
|
||||||
|
expectedQueryParams: map[string]string{
|
||||||
|
"all": "",
|
||||||
|
"filter": "",
|
||||||
|
"filters": `{"capability":{"authz":true,"volumedriver":true}}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, listCase := range listCases {
|
for _, listCase := range listCases {
|
||||||
|
|
|
@ -51,9 +51,13 @@ Config provides the base accessible fields for working with V0 plugin format
|
||||||
|
|
||||||
currently supported:
|
currently supported:
|
||||||
|
|
||||||
- **docker.volumedriver/1.0**
|
- **docker.volumedriver/1.0**
|
||||||
|
|
||||||
- **docker.authz/1.0**
|
- **docker.networkdriver/1.0**
|
||||||
|
|
||||||
|
- **docker.ipamdriver/1.0**
|
||||||
|
|
||||||
|
- **docker.authz/1.0**
|
||||||
|
|
||||||
- **`socket`** *string*
|
- **`socket`** *string*
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,26 @@ than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "b
|
||||||
The currently supported filters are:
|
The currently supported filters are:
|
||||||
|
|
||||||
* enabled (boolean - true or false, 0 or 1)
|
* enabled (boolean - true or false, 0 or 1)
|
||||||
|
* capability (string - currently `volumedriver`, `networkdriver`, `ipamdriver`, or `authz`)
|
||||||
|
|
||||||
### enabled
|
### enabled
|
||||||
|
|
||||||
The `enabled` filter matches on plugins enabled or disabled.
|
The `enabled` filter matches on plugins enabled or disabled.
|
||||||
|
|
||||||
|
### capability
|
||||||
|
|
||||||
|
The `capability` filter matches on plugin capabilities. One plugin
|
||||||
|
might have multiple capabilities. Currently `volumedriver`, `networkdriver`,
|
||||||
|
`ipamdriver`, and `authz` are supported capabilities.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker plugin install --disable tiborvass/no-remove
|
||||||
|
tiborvass/no-remove
|
||||||
|
|
||||||
|
$ docker plugin ls --filter enabled=true
|
||||||
|
NAME TAG DESCRIPTION ENABLED
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Formatting
|
## Formatting
|
||||||
|
|
||||||
|
|
|
@ -313,3 +313,30 @@ func (s *DockerDaemonSuite) TestPluginListFilterEnabled(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(out, checker.Contains, pName)
|
c.Assert(out, checker.Contains, pName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerDaemonSuite) TestPluginListFilterCapability(c *check.C) {
|
||||||
|
testRequires(c, Network)
|
||||||
|
|
||||||
|
s.d.Start(c)
|
||||||
|
|
||||||
|
out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pNameWithTag, "--disable")
|
||||||
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if out, err := s.d.Cmd("plugin", "remove", pNameWithTag); err != nil {
|
||||||
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
out, err = s.d.Cmd("plugin", "ls", "--filter", "capability=volumedriver")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(out, checker.Contains, pName)
|
||||||
|
|
||||||
|
out, err = s.d.Cmd("plugin", "ls", "--filter", "capability=authz")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(out, checker.Not(checker.Contains), pName)
|
||||||
|
|
||||||
|
out, err = s.d.Cmd("plugin", "ls")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(out, checker.Contains, pName)
|
||||||
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var acceptedPluginFilterTags = map[string]bool{
|
var acceptedPluginFilterTags = map[string]bool{
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
"capability": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable deactivates a plugin. This means resources (volumes, networks) cant use them.
|
// Disable deactivates a plugin. This means resources (volumes, networks) cant use them.
|
||||||
|
@ -284,6 +285,7 @@ func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) {
|
||||||
plugins := pm.config.Store.GetAll()
|
plugins := pm.config.Store.GetAll()
|
||||||
out := make([]types.Plugin, 0, len(plugins))
|
out := make([]types.Plugin, 0, len(plugins))
|
||||||
|
|
||||||
|
next:
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
if enabledOnly && !p.PluginObj.Enabled {
|
if enabledOnly && !p.PluginObj.Enabled {
|
||||||
continue
|
continue
|
||||||
|
@ -291,6 +293,13 @@ func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) {
|
||||||
if disabledOnly && p.PluginObj.Enabled {
|
if disabledOnly && p.PluginObj.Enabled {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if pluginFilters.Include("capability") {
|
||||||
|
for _, f := range p.GetTypes() {
|
||||||
|
if !pluginFilters.Match("capability", f.Capability) {
|
||||||
|
continue next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
out = append(out, p.PluginObj)
|
out = append(out, p.PluginObj)
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
|
|
Loading…
Reference in a new issue