forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_attribute_handler.go
46 lines (37 loc) · 1.01 KB
/
user_attribute_handler.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
package auth
import (
"github.com/rancher/rancher/pkg/auth/providerrefresh"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"k8s.io/apimachinery/pkg/runtime"
)
const (
userAttributeController = "mgmt-auth-userattributes-controller"
)
type UserAttributeController struct {
userAttributes v3.UserAttributeInterface
}
func newUserAttributeController(mgmt *config.ManagementContext) *UserAttributeController {
ua := &UserAttributeController{
userAttributes: mgmt.Management.UserAttributes(""),
}
return ua
}
//sync is called periodically and on real updates
func (ua *UserAttributeController) sync(key string, obj *v3.UserAttribute) (runtime.Object, error) {
if obj == nil || obj.DeletionTimestamp != nil {
return nil, nil
}
if !obj.NeedsRefresh {
return obj, nil
}
obj, err := providerrefresh.RefreshAttributes(obj)
if err != nil {
return nil, err
}
updated, err := ua.userAttributes.Update(obj)
if err != nil {
return nil, err
}
return updated, nil
}