Browse code

Make authorization plugins use pluginv2.

Signed-off-by: Anusha Ragunathan <anusha@docker.com>

Anusha Ragunathan authored on 2016/10/08 06:53:17
Showing 6 changed files
... ...
@@ -275,10 +275,12 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
275 275
 		"graphdriver": d.GraphDriverName(),
276 276
 	}).Info("Docker daemon")
277 277
 
278
+	cli.d = d
279
+
280
+	// initMiddlewares needs cli.d to be populated. Dont change this init order.
278 281
 	cli.initMiddlewares(api, serverConfig)
279 282
 	initRouter(api, d, c)
280 283
 
281
-	cli.d = d
282 284
 	cli.setupConfigReloadTrap()
283 285
 
284 286
 	// The serve API routine never exits unless an error occurs
... ...
@@ -438,6 +440,6 @@ func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config
438 438
 	u := middleware.NewUserAgentMiddleware(v)
439 439
 	s.UseMiddleware(u)
440 440
 
441
-	cli.authzMiddleware = authorization.NewMiddleware(cli.Config.AuthorizationPlugins)
441
+	cli.authzMiddleware = authorization.NewMiddleware(cli.Config.AuthorizationPlugins, cli.d.PluginStore)
442 442
 	s.UseMiddleware(cli.authzMiddleware)
443 443
 }
... ...
@@ -96,7 +96,7 @@ type Daemon struct {
96 96
 	gidMaps                   []idtools.IDMap
97 97
 	layerStore                layer.Store
98 98
 	imageStore                image.Store
99
-	pluginStore               *pluginstore.Store
99
+	PluginStore               *pluginstore.Store
100 100
 	nameIndex                 *registrar.Registrar
101 101
 	linkIndex                 *linkIndex
102 102
 	containerd                libcontainerd.Client
... ...
@@ -559,7 +559,7 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
559 559
 		driverName = config.GraphDriver
560 560
 	}
561 561
 
562
-	d.pluginStore = pluginstore.NewStore(config.Root)
562
+	d.PluginStore = pluginstore.NewStore(config.Root)
563 563
 
564 564
 	d.layerStore, err = layer.NewStoreFromOptions(layer.StoreOptions{
565 565
 		StorePath:                 config.Root,
... ...
@@ -568,7 +568,7 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
568 568
 		GraphDriverOptions:        config.GraphOptions,
569 569
 		UIDMaps:                   uidMaps,
570 570
 		GIDMaps:                   gidMaps,
571
-		PluginGetter:              d.pluginStore,
571
+		PluginGetter:              d.PluginStore,
572 572
 	})
573 573
 	if err != nil {
574 574
 		return nil, err
... ...
@@ -926,7 +926,7 @@ func (daemon *Daemon) configureVolumes(rootUID, rootGID int) (*store.VolumeStore
926 926
 		return nil, err
927 927
 	}
928 928
 
929
-	volumedrivers.RegisterPluginGetter(daemon.pluginStore)
929
+	volumedrivers.RegisterPluginGetter(daemon.PluginStore)
930 930
 
931 931
 	if !volumedrivers.Register(volumesDriver, volumesDriver.Name()) {
932 932
 		return nil, fmt.Errorf("local volume driver could not be registered")
... ...
@@ -1102,7 +1102,7 @@ func (daemon *Daemon) reloadClusterDiscovery(config *Config) error {
1102 1102
 	if daemon.netController == nil {
1103 1103
 		return nil
1104 1104
 	}
1105
-	netOptions, err := daemon.networkOptions(daemon.configStore, daemon.pluginStore, nil)
1105
+	netOptions, err := daemon.networkOptions(daemon.configStore, daemon.PluginStore, nil)
1106 1106
 	if err != nil {
1107 1107
 		logrus.WithError(err).Warnf("failed to get options with network controller")
1108 1108
 		return nil
... ...
@@ -13,7 +13,7 @@ func (daemon *Daemon) verifyExperimentalContainerSettings(hostConfig *container.
13 13
 }
14 14
 
15 15
 func pluginInit(d *Daemon, cfg *Config, remote libcontainerd.Remote) error {
16
-	return plugin.Init(cfg.Root, d.pluginStore, remote, d.RegistryService, cfg.LiveRestoreEnabled, d.LogPluginEvent)
16
+	return plugin.Init(cfg.Root, d.PluginStore, remote, d.RegistryService, cfg.LiveRestoreEnabled, d.LogPluginEvent)
17 17
 }
18 18
 
19 19
 func pluginShutdown() {
... ...
@@ -613,7 +613,7 @@ func configureKernelSecuritySupport(config *Config, driverName string) error {
613 613
 }
614 614
 
615 615
 func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) {
616
-	netOptions, err := daemon.networkOptions(config, daemon.pluginStore, activeSandboxes)
616
+	netOptions, err := daemon.networkOptions(config, daemon.PluginStore, activeSandboxes)
617 617
 	if err != nil {
618 618
 		return nil, err
619 619
 	}
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"net/http"
5 5
 
6 6
 	"github.com/Sirupsen/logrus"
7
+	"github.com/docker/docker/pkg/plugingetter"
7 8
 	"golang.org/x/net/context"
8 9
 )
9 10
 
... ...
@@ -15,7 +16,8 @@ type Middleware struct {
15 15
 
16 16
 // NewMiddleware creates a new Middleware
17 17
 // with a slice of plugins names.
18
-func NewMiddleware(names []string) *Middleware {
18
+func NewMiddleware(names []string, pg plugingetter.PluginGetter) *Middleware {
19
+	SetPluginGetter(pg)
19 20
 	return &Middleware{
20 21
 		plugins: newPlugins(names),
21 22
 	}
... ...
@@ -3,6 +3,7 @@ package authorization
3 3
 import (
4 4
 	"sync"
5 5
 
6
+	"github.com/docker/docker/pkg/plugingetter"
6 7
 	"github.com/docker/docker/pkg/plugins"
7 8
 )
8 9
 
... ...
@@ -33,6 +34,18 @@ func newPlugins(names []string) []Plugin {
33 33
 	return plugins
34 34
 }
35 35
 
36
+var getter plugingetter.PluginGetter
37
+
38
+// SetPluginGetter sets the plugingetter
39
+func SetPluginGetter(pg plugingetter.PluginGetter) {
40
+	getter = pg
41
+}
42
+
43
+// GetPluginGetter gets the plugingetter
44
+func GetPluginGetter() plugingetter.PluginGetter {
45
+	return getter
46
+}
47
+
36 48
 // authorizationPlugin is an internal adapter to docker plugin system
37 49
 type authorizationPlugin struct {
38 50
 	plugin *plugins.Client
... ...
@@ -80,7 +93,14 @@ func (a *authorizationPlugin) initPlugin() error {
80 80
 	var err error
81 81
 	a.once.Do(func() {
82 82
 		if a.plugin == nil {
83
-			plugin, e := plugins.Get(a.name, AuthZApiImplements)
83
+			var plugin plugingetter.CompatPlugin
84
+			var e error
85
+
86
+			if pg := GetPluginGetter(); pg != nil {
87
+				plugin, e = pg.Get(a.name, AuthZApiImplements, plugingetter.LOOKUP)
88
+			} else {
89
+				plugin, e = plugins.Get(a.name, AuthZApiImplements)
90
+			}
84 91
 			if e != nil {
85 92
 				err = e
86 93
 				return