-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuser.go
55 lines (52 loc) · 1.56 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package netskope
import (
"fmt"
)
// User is a user with its attributes.
type User struct {
ID string `json:"_id,omitempty"`
DeviceClassificationStatus string `json:"device_classification_status,omitempty"`
LastEvent *Event
OrganizationUnit string `json:"organization_unit,omitempty"`
AddedTimestamp float64 `json:"user_added_time,omitempty"`
Groups []string `json:"user_groups,omitempty"`
Source string `json:"user_source,omitempty"`
Key string `json:"userkey,omitempty"`
Username string `json:"username,omitempty"`
}
func (u *User) load(m map[string]interface{}) error {
if m == nil {
return nil
}
for k, v := range m {
switch k {
case "_id":
u.ID = v.(string)
case "device_classification_status":
u.DeviceClassificationStatus = v.(string)
case "last_event":
e := &Event{}
if err := e.load(v.(map[string]interface{})); err != nil {
return fmt.Errorf("failed to unpack ClientEndpoint, %s attribute error: %s", k, err)
}
u.LastEvent = e
case "organization_unit":
u.OrganizationUnit = v.(string)
case "user_added_time":
u.AddedTimestamp = v.(float64)
case "user_groups":
for _, g := range v.([]interface{}) {
u.Groups = append(u.Groups, g.(string))
}
case "user_source":
u.Source = v.(string)
case "userkey":
u.Key = v.(string)
case "username":
u.Username = v.(string)
default:
return fmt.Errorf("unsupported attribute: %s, %v", k, v)
}
}
return nil
}