mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #35136 from ripcurld0/refactor_plugin_store_get
Refactor plugin store to reduce nested if's in Get
This commit is contained in:
commit
34d502eb9e
1 changed files with 11 additions and 17 deletions
|
@ -111,14 +111,9 @@ func (ps *Store) Remove(p *v2.Plugin) {
|
|||
|
||||
// Get returns an enabled plugin matching the given name and capability.
|
||||
func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlugin, error) {
|
||||
var (
|
||||
p *v2.Plugin
|
||||
err error
|
||||
)
|
||||
|
||||
// Lookup using new model.
|
||||
if ps != nil {
|
||||
p, err = ps.GetV2Plugin(name)
|
||||
p, err := ps.GetV2Plugin(name)
|
||||
if err == nil {
|
||||
p.AddRefCount(mode)
|
||||
if p.IsEnabled() {
|
||||
|
@ -133,19 +128,18 @@ func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlug
|
|||
}
|
||||
}
|
||||
|
||||
// Lookup using legacy model.
|
||||
if allowV1PluginsFallback {
|
||||
p, err := plugins.Get(name, capability)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == plugins.ErrNotFound {
|
||||
return nil, errNotFound(name)
|
||||
}
|
||||
return nil, errors.Wrap(systemError{err}, "legacy plugin")
|
||||
}
|
||||
return p, nil
|
||||
if !allowV1PluginsFallback {
|
||||
return nil, errNotFound(name)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
p, err := plugins.Get(name, capability)
|
||||
if err == nil {
|
||||
return p, nil
|
||||
}
|
||||
if errors.Cause(err) == plugins.ErrNotFound {
|
||||
return nil, errNotFound(name)
|
||||
}
|
||||
return nil, errors.Wrap(systemError{err}, "legacy plugin")
|
||||
}
|
||||
|
||||
// GetAllManagedPluginsByCap returns a list of managed plugins matching the given capability.
|
||||
|
|
Loading…
Reference in a new issue