-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathldap_models.go
86 lines (71 loc) · 1.51 KB
/
ldap_models.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import "go.ytsaurus.tech/yt/go/yson"
type LdapUser struct {
Username string `yson:"username"`
UID string `yson:"uid"`
FirstName string `yson:"first_name"`
// TODO(nadya73): Add more fields.
}
func NewLdapUser(attributes map[string]any) (*LdapUser, error) {
bytes, err := yson.Marshal(attributes)
if err != nil {
return nil, err
}
var user LdapUser
err = yson.Unmarshal(bytes, &user)
if err != nil {
return nil, err
}
return &user, nil
}
func (lu LdapUser) GetID() ObjectID {
return lu.UID
}
func (lu LdapUser) GetName() string {
return lu.Username
}
func (lu LdapUser) GetRaw() (map[string]any, error) {
bytes, err := yson.Marshal(lu)
if err != nil {
return nil, err
}
raw := make(map[string]any)
err = yson.Unmarshal(bytes, &raw)
if err != nil {
return nil, err
}
return raw, nil
}
type LdapGroup struct {
Groupname string `yson:"groupname"`
}
func NewLdapGroup(attributes map[string]any) (*LdapGroup, error) {
bytes, err := yson.Marshal(attributes)
if err != nil {
return nil, err
}
var group LdapGroup
err = yson.Unmarshal(bytes, &group)
if err != nil {
return nil, err
}
return &group, nil
}
func (lg LdapGroup) GetID() ObjectID {
return lg.Groupname
}
func (lg LdapGroup) GetName() string {
return lg.Groupname
}
func (lg LdapGroup) GetRaw() (map[string]any, error) {
bytes, err := yson.Marshal(lg)
if err != nil {
return nil, err
}
raw := make(map[string]any)
err = yson.Unmarshal(bytes, &raw)
if err != nil {
return nil, err
}
return raw, nil
}