forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authorizer.go
37 lines (27 loc) · 962 Bytes
/
authorizer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package adapter
import (
"errors"
"github.com/golang/glog"
kauthorizer "k8s.io/kubernetes/pkg/auth/authorizer"
oauthorizer "github.com/openshift/origin/pkg/authorization/authorizer"
)
type AdapterAuthorizer struct {
originAuthorizer oauthorizer.Authorizer
}
// NewAuthorizer adapts an Origin Authorizer interface to a Kubernetes Authorizer interface
func NewAuthorizer(originAuthorizer oauthorizer.Authorizer) (kauthorizer.Authorizer, error) {
return &AdapterAuthorizer{originAuthorizer}, nil
}
func (z *AdapterAuthorizer) Authorize(kattrs kauthorizer.Attributes) error {
allowed, reason, err := z.originAuthorizer.Authorize(OriginAuthorizerAttributes(kattrs))
if err != nil {
glog.V(5).Infof("evaluation error: %v", err)
return err
}
glog.V(5).Infof("allowed=%v, reason=%s", allowed, reason)
if allowed {
return nil
}
// Turn the reason into an error so we can reject with the most information possible
return errors.New(reason)
}