/
models_user.go
57 lines (43 loc) · 1.13 KB
/
models_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package proxy
import (
"encoding/json"
"fmt"
)
type userModelType string
var normalUserModelType userModelType = "NormalUser"
var servicePrincipalUserModelType userModelType = "ServicePrincipal"
type userModel struct {
Username string
ObjectID string
Groups []groupModel
Type userModelType
}
func (i userModel) MarshalBinary() ([]byte, error) {
return json.Marshal(i)
}
func (i *userModel) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, &i)
}
type groupIdentifier string
var nameGroupIdentifier groupIdentifier = "NAME"
var objectIDGroupIdentifier groupIdentifier = "OBJECTID"
func getGroupIdentifier(s string) (groupIdentifier, error) {
switch s {
case "NAME":
return nameGroupIdentifier, nil
case "OBJECTID":
return objectIDGroupIdentifier, nil
default:
return "", fmt.Errorf("Unknown group identifier '%s'. Supported identifiers are: NAME or OBJECTID", s)
}
}
type groupModel struct {
Name string
ObjectID string
}
func (i groupModel) MarshalBinary() ([]byte, error) {
return json.Marshal(i)
}
func (i *groupModel) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, &i)
}