Merge pull request #22770 from twistlock/22729_dynamic_authz_reload

Enable to dynamically reload authorization plugins via daemon.config
Upstream-commit: b2b3cb7be92b97150c9be96c606c0ab0a383d2ec
Component: engine
This commit is contained in:
Vincent Demeester
2016-08-05 19:38:40 +02:00
committed by GitHub
5 changed files with 29 additions and 14 deletions
@@ -14,17 +14,26 @@ type Middleware struct {
}
// NewMiddleware creates a new Middleware
// with a slice of plugins.
func NewMiddleware(p []Plugin) Middleware {
return Middleware{
plugins: p,
// with a slice of plugins names.
func NewMiddleware(names []string) *Middleware {
return &Middleware{
plugins: newPlugins(names),
}
}
// SetPlugins sets the plugin used for authorization
func (m *Middleware) SetPlugins(names []string) {
m.plugins = newPlugins(names)
}
// WrapHandler returns a new handler function wrapping the previous one in the request chain.
func (m Middleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
func (m *Middleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if len(m.plugins) == 0 {
return handler(ctx, w, r, vars)
}
user := ""
userAuthNMethod := ""
@@ -19,8 +19,8 @@ type Plugin interface {
AuthZResponse(*Request) (*Response, error)
}
// NewPlugins constructs and initializes the authorization plugins based on plugin names
func NewPlugins(names []string) []Plugin {
// newPlugins constructs and initializes the authorization plugins based on plugin names
func newPlugins(names []string) []Plugin {
plugins := []Plugin{}
pluginsMap := make(map[string]struct{})
for _, name := range names {