pkg: authorization: cleanup
Signed-off-by: Antonio Murdaca <runcom@redhat.com> Upstream-commit: 8435ea52893ef69c5a264bfbf0a1d3472f377ba2 Component: engine
This commit is contained in:
@ -8,12 +8,11 @@ import (
|
||||
// Plugin allows third party plugins to authorize requests and responses
|
||||
// in the context of docker API
|
||||
type Plugin interface {
|
||||
|
||||
// AuthZRequest authorize the request from the client to the daemon
|
||||
AuthZRequest(authReq *Request) (authRes *Response, err error)
|
||||
AuthZRequest(*Request) (*Response, error)
|
||||
|
||||
// AuthZResponse authorize the response from the daemon to the client
|
||||
AuthZResponse(authReq *Request) (authRes *Response, err error)
|
||||
AuthZResponse(*Request) (*Response, error)
|
||||
}
|
||||
|
||||
// NewPlugins constructs and initialize the authorization plugins based on plugin names
|
||||
@ -35,38 +34,30 @@ func newAuthorizationPlugin(name string) Plugin {
|
||||
return &authorizationPlugin{name: name}
|
||||
}
|
||||
|
||||
func (a *authorizationPlugin) AuthZRequest(authReq *Request) (authRes *Response, err error) {
|
||||
|
||||
func (a *authorizationPlugin) AuthZRequest(authReq *Request) (*Response, error) {
|
||||
logrus.Debugf("AuthZ requset using plugins %s", a.name)
|
||||
|
||||
err = a.initPlugin()
|
||||
if err != nil {
|
||||
if err := a.initPlugin(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
authRes = &Response{}
|
||||
err = a.plugin.Client.Call(AuthZApiRequest, authReq, authRes)
|
||||
|
||||
if err != nil {
|
||||
authRes := &Response{}
|
||||
if err := a.plugin.Client.Call(AuthZApiRequest, authReq, authRes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return authRes, nil
|
||||
}
|
||||
|
||||
func (a *authorizationPlugin) AuthZResponse(authReq *Request) (authRes *Response, err error) {
|
||||
|
||||
func (a *authorizationPlugin) AuthZResponse(authReq *Request) (*Response, error) {
|
||||
logrus.Debugf("AuthZ response using plugins %s", a.name)
|
||||
|
||||
err = a.initPlugin()
|
||||
if err != nil {
|
||||
if err := a.initPlugin(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
authRes = &Response{}
|
||||
err = a.plugin.Client.Call(AuthZApiResponse, authReq, authRes)
|
||||
|
||||
if err != nil {
|
||||
authRes := &Response{}
|
||||
if err := a.plugin.Client.Call(AuthZApiResponse, authReq, authRes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -74,10 +65,10 @@ func (a *authorizationPlugin) AuthZResponse(authReq *Request) (authRes *Response
|
||||
}
|
||||
|
||||
// initPlugin initialize the authorization plugin if needed
|
||||
func (a *authorizationPlugin) initPlugin() (err error) {
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user