summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Murdaca <runcom@redhat.com>2016-06-12 17:19:43 +0200
committerAntonio Murdaca <runcom@redhat.com>2016-06-12 17:19:43 +0200
commitceb9c5a88b5fa7d0b6c0901fa6b44ec89e81c2dc (patch)
treec6e513ace0ae85ed78da8e713fb8d71589e0a02e
parent04f5ce5152dbbe303e95216fb5a2a420656c3297 (diff)
downloaddocker-ceb9c5a88b5fa7d0b6c0901fa6b44ec89e81c2dc.tar.gz
pkg: authorization: lock when lazy loading
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
-rw-r--r--pkg/authorization/plugin.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/pkg/authorization/plugin.go b/pkg/authorization/plugin.go
index a67c83f076..940699d9a3 100644
--- a/pkg/authorization/plugin.go
+++ b/pkg/authorization/plugin.go
@@ -1,6 +1,10 @@
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
// in the context of docker API
@@ -33,6 +37,7 @@ func NewPlugins(names []string) []Plugin {
type authorizationPlugin struct {
plugin *plugins.Plugin
name string
+ once sync.Once
}
func newAuthorizationPlugin(name string) Plugin {
@@ -72,12 +77,11 @@ func (a *authorizationPlugin) AuthZResponse(authReq *Request) (*Response, error)
// initPlugin initializes the authorization plugin if needed
func (a *authorizationPlugin) initPlugin() error {
// Lazy loading of plugins
- if a.plugin == nil {
- var err error
- a.plugin, err = plugins.Get(a.name, AuthZApiImplements)
- if err != nil {
- return err
+ var err error
+ a.once.Do(func() {
+ if a.plugin == nil {
+ a.plugin, err = plugins.Get(a.name, AuthZApiImplements)
}
- }
- return nil
+ })
+ return err
}