forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
43 lines (35 loc) · 1.05 KB
/
util.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
38
39
40
41
42
43
package util
import (
restclient "k8s.io/client-go/rest"
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
authorizationclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
)
func CanRequestProjects(config *restclient.Config, defaultNamespace string) (bool, error) {
oClient, err := authorizationclient.NewForConfig(config)
if err != nil {
return false, err
}
sar := &authorizationapi.SubjectAccessReview{
Action: authorizationapi.Action{
Namespace: defaultNamespace,
Verb: "list",
Resource: "projectrequests",
},
}
listResponse, err := oClient.SubjectAccessReviews().Create(sar)
if err != nil {
return false, err
}
sar = &authorizationapi.SubjectAccessReview{
Action: authorizationapi.Action{
Namespace: defaultNamespace,
Verb: "create",
Resource: "projectrequests",
},
}
createResponse, err := oClient.SubjectAccessReviews().Create(sar)
if err != nil {
return false, err
}
return (listResponse.Allowed && createResponse.Allowed), nil
}