pkg: authorization: lock when lazy loading

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-06-12 17:19:43 +02:00
parent 9b79cbe713
commit 32a661fee9

View file

@ -1,6 +1,10 @@
package authorization package authorization
import "github.com/docker/docker/pkg/plugins" import (
"sync"
"github.com/docker/docker/pkg/plugins"
)
// Plugin allows third party plugins to authorize requests and responses // Plugin allows third party plugins to authorize requests and responses
// in the context of docker API // in the context of docker API
@ -33,6 +37,7 @@ func NewPlugins(names []string) []Plugin {
type authorizationPlugin struct { type authorizationPlugin struct {
plugin *plugins.Plugin plugin *plugins.Plugin
name string name string
once sync.Once
} }
func newAuthorizationPlugin(name string) Plugin { func newAuthorizationPlugin(name string) Plugin {
@ -72,12 +77,11 @@ func (a *authorizationPlugin) AuthZResponse(authReq *Request) (*Response, error)
// initPlugin initializes the authorization plugin if needed // initPlugin initializes the authorization plugin if needed
func (a *authorizationPlugin) initPlugin() error { func (a *authorizationPlugin) initPlugin() error {
// Lazy loading of plugins // Lazy loading of plugins
if a.plugin == nil { var err error
var err error a.once.Do(func() {
a.plugin, err = plugins.Get(a.name, AuthZApiImplements) if a.plugin == nil {
if err != nil { a.plugin, err = plugins.Get(a.name, AuthZApiImplements)
return err
} }
} })
return nil return err
} }