Merge pull request #27293 from anusha-ragunathan/use-pluginv2-authz
Make authz use pluginv2 Upstream-commit: 8658748ef716e43a5f6d834825d818012ed6e2c4 Component: engine
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/pkg/plugingetter"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
@ -17,7 +18,8 @@ type Middleware struct {
|
||||
|
||||
// NewMiddleware creates a new Middleware
|
||||
// with a slice of plugins names.
|
||||
func NewMiddleware(names []string) *Middleware {
|
||||
func NewMiddleware(names []string, pg plugingetter.PluginGetter) *Middleware {
|
||||
SetPluginGetter(pg)
|
||||
return &Middleware{
|
||||
plugins: newPlugins(names),
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package authorization
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/docker/docker/pkg/plugingetter"
|
||||
"github.com/docker/docker/pkg/plugins"
|
||||
)
|
||||
|
||||
@ -33,6 +34,18 @@ func newPlugins(names []string) []Plugin {
|
||||
return plugins
|
||||
}
|
||||
|
||||
var getter plugingetter.PluginGetter
|
||||
|
||||
// SetPluginGetter sets the plugingetter
|
||||
func SetPluginGetter(pg plugingetter.PluginGetter) {
|
||||
getter = pg
|
||||
}
|
||||
|
||||
// GetPluginGetter gets the plugingetter
|
||||
func GetPluginGetter() plugingetter.PluginGetter {
|
||||
return getter
|
||||
}
|
||||
|
||||
// authorizationPlugin is an internal adapter to docker plugin system
|
||||
type authorizationPlugin struct {
|
||||
plugin *plugins.Client
|
||||
@ -80,7 +93,14 @@ func (a *authorizationPlugin) initPlugin() error {
|
||||
var err error
|
||||
a.once.Do(func() {
|
||||
if a.plugin == nil {
|
||||
plugin, e := plugins.Get(a.name, AuthZApiImplements)
|
||||
var plugin plugingetter.CompatPlugin
|
||||
var e error
|
||||
|
||||
if pg := GetPluginGetter(); pg != nil {
|
||||
plugin, e = pg.Get(a.name, AuthZApiImplements, plugingetter.LOOKUP)
|
||||
} else {
|
||||
plugin, e = plugins.Get(a.name, AuthZApiImplements)
|
||||
}
|
||||
if e != nil {
|
||||
err = e
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user