/
federated_clusterrole.go
56 lines (44 loc) · 1.26 KB
/
federated_clusterrole.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
44
45
46
47
48
49
50
51
52
53
54
55
56
package api
import (
rbac "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"yunion.io/x/jsonutils"
)
type FederatedClusterRoleSpec struct {
Template ClusterRoleTemplate `json:"template"`
}
type ClusterRoleTemplate struct {
Rules []rbac.PolicyRule `json:"rules"`
}
func (spec *FederatedClusterRoleSpec) String() string {
return jsonutils.Marshal(spec).String()
}
func (spec *FederatedClusterRoleSpec) IsZero() bool {
if spec == nil {
return true
}
return false
}
func (spec *FederatedClusterRoleSpec) ToClusterRole(objMeta metav1.ObjectMeta) *rbac.ClusterRole {
return &rbac.ClusterRole{
ObjectMeta: objMeta,
Rules: spec.Template.Rules,
}
}
type FederatedClusterRoleCreateInput struct {
FederatedResourceCreateInput
Spec *FederatedClusterRoleSpec `json:"spec"`
}
func (input FederatedClusterRoleCreateInput) ToClusterRole() *rbac.ClusterRole {
return input.Spec.ToClusterRole(input.ToObjectMeta())
}
type FederatedClusterRoleClusterListInput struct {
FedJointClusterListInput
}
type FedClusterRoleUpdateInput struct {
FedResourceUpdateInput
Spec *FederatedClusterRoleSpec `json:"spec"`
}
func (input FedClusterRoleUpdateInput) ToClusterRole(objMeta metav1.ObjectMeta) *rbac.ClusterRole {
return input.Spec.ToClusterRole(objMeta)
}