forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
37 lines (31 loc) · 1.01 KB
/
user.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 clusterauthtoken
import (
clusterv3 "github.com/rancher/types/apis/cluster.cattle.io/v3"
managementv3 "github.com/rancher/types/apis/management.cattle.io/v3"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
)
type userHandler struct {
namespace string
clusterUserAttribute clusterv3.ClusterUserAttributeInterface
clusterUserAttributeLister clusterv3.ClusterUserAttributeLister
}
func (h *userHandler) Sync(key string, user *managementv3.User) (runtime.Object, error) {
if user == nil || user.DeletionTimestamp != nil {
return nil, nil
}
clusterUserAttribute, err := h.clusterUserAttributeLister.Get(h.namespace, user.Name)
if errors.IsNotFound(err) {
return nil, nil
}
if err != nil {
return nil, err
}
userEnabled := user.Enabled == nil || *user.Enabled
if clusterUserAttribute.Enabled == userEnabled {
return nil, nil
}
clusterUserAttribute.Enabled = userEnabled
_, err = h.clusterUserAttribute.Update(clusterUserAttribute)
return nil, err
}