Debian Codegraph @

auth/rbac/reconciliation/role_interfaces.go

raw symbols SCIP
1 /*
2 Copyright 2017 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package reconciliation
18
19 import (
20 "context"
21
22 rbacv1 "k8s.io/api/rbac/v1"
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/apimachinery/pkg/runtime"
25 corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
26 rbacv1client "k8s.io/client-go/kubernetes/typed/rbac/v1"
27 )
28
29 // +k8s:deepcopy-gen=true
30 // +k8s:deepcopy-gen:interfaces=k8s.io/component-helpers/auth/rbac/reconciliation.RuleOwner
31 // +k8s:deepcopy-gen:nonpointer-interfaces=true
32 type RoleRuleOwner struct {
33 Role *rbacv1.Role
34 }
35
36 func (o RoleRuleOwner) GetObject() runtime.Object {
37 return o.Role
38 }
39
40 func (o RoleRuleOwner) GetNamespace() string {
41 return o.Role.Namespace
42 }
43
44 func (o RoleRuleOwner) GetName() string {
45 return o.Role.Name
46 }
47
48 func (o RoleRuleOwner) GetLabels() map[string]string {
49 return o.Role.Labels
50 }
51
52 func (o RoleRuleOwner) SetLabels(in map[string]string) {
53 o.Role.Labels = in
54 }
55
56 func (o RoleRuleOwner) GetAnnotations() map[string]string {
57 return o.Role.Annotations
58 }
59
60 func (o RoleRuleOwner) SetAnnotations(in map[string]string) {
61 o.Role.Annotations = in
62 }
63
64 func (o RoleRuleOwner) GetRules() []rbacv1.PolicyRule {
65 return o.Role.Rules
66 }
67
68 func (o RoleRuleOwner) SetRules(in []rbacv1.PolicyRule) {
69 o.Role.Rules = in
70 }
71
72 func (o RoleRuleOwner) GetAggregationRule() *rbacv1.AggregationRule {
73 return nil
74 }
75
76 func (o RoleRuleOwner) SetAggregationRule(in *rbacv1.AggregationRule) {
77 }
78
79 type RoleModifier struct {
80 Client rbacv1client.RolesGetter
81 NamespaceClient corev1client.NamespaceInterface
82 }
83
84 func (c RoleModifier) Get(namespace, name string) (RuleOwner, error) {
85 ret, err := c.Client.Roles(namespace).Get(context.TODO(), name, metav1.GetOptions{})
86 if err != nil {
87 return nil, err
88 }
89 return RoleRuleOwner{Role: ret}, err
90 }
91
92 func (c RoleModifier) Create(in RuleOwner) (RuleOwner, error) {
93 if err := tryEnsureNamespace(c.NamespaceClient, in.GetNamespace()); err != nil {
94 return nil, err
95 }
96
97 ret, err := c.Client.Roles(in.GetNamespace()).Create(context.TODO(), in.(RoleRuleOwner).Role, metav1.CreateOptions{})
98 if err != nil {
99 return nil, err
100 }
101 return RoleRuleOwner{Role: ret}, err
102 }
103
104 func (c RoleModifier) Update(in RuleOwner) (RuleOwner, error) {
105 ret, err := c.Client.Roles(in.GetNamespace()).Update(context.TODO(), in.(RoleRuleOwner).Role, metav1.UpdateOptions{})
106 if err != nil {
107 return nil, err
108 }
109 return RoleRuleOwner{Role: ret}, err
110
111 }