forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
attributes.go
37 lines (32 loc) · 976 Bytes
/
attributes.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 util
import (
"strings"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer"
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
)
// ToDefaultAuthorizationAttributes coerces Action to authorizer.Attributes.
func ToDefaultAuthorizationAttributes(user user.Info, namespace string, in authorizationapi.Action) authorizer.Attributes {
tokens := strings.SplitN(in.Resource, "/", 2)
resource := ""
subresource := ""
switch {
case len(tokens) == 2:
subresource = tokens[1]
fallthrough
case len(tokens) == 1:
resource = tokens[0]
}
return authorizer.AttributesRecord{
User: user,
Verb: in.Verb,
Namespace: namespace,
APIGroup: in.Group,
APIVersion: in.Version,
Resource: resource,
Subresource: subresource,
Name: in.ResourceName,
ResourceRequest: !in.IsNonResourceURL,
Path: in.Path,
}
}