-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusers.go
74 lines (57 loc) · 1.54 KB
/
users.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
package main
import (
"fmt"
admin "google.golang.org/api/admin/directory/v1"
plugin "github.com/defensestation/pluginutils"
)
func (g *Gsuite) getUsersList(customerId string) ([]*admin.User, error){
r, err := g.client.Users.List().Customer(customerId).OrderBy("email").Do()
if err != nil {
return nil, fmt.Errorf("Unable to retrieve users in domain: %v", err)
}
if len(r.Users) > 0 {
return r.Users, nil
} else {
fmt.Print("No users found.\n")
}
return nil, nil
}
func (g *Gsuite) getUsers(customerId string) (error) {
users, err := g.getUsersList(customerId)
if err != nil {
return err
}
if users == nil || len(users) == 0 {
return nil
}
graph, ok := g.plugin.GetGraph(employeeType)
if !ok {
return fmt.Errorf("unable to find %s graph", employeeType)
}
graph.SetReverseRelation(true)
for _, user := range users {
var aliasArr []map[string]interface{}
if user.Aliases != nil {
for _, alias := range user.Aliases {
newAlias := map[string]interface{}{}
newAlias["email"] = alias
newAlias["alais"] = "alais"
newAlias["supervisor_type"] = "is_alais_of"
err := graph.AddNode(newAlias)
if err != nil {
return err
}
aliasArr = append(aliasArr, newAlias)
}
}
userMapInterface := plugin.StructToMap(user)
userMapInterface["relations"] = aliasArr
userMapInterface["personnel"] = "personnel"
userMapInterface["personnel_id"] = fmt.Sprintf("%s_%s", g.plugin.Name, user.PrimaryEmail)
err := graph.AddNode(userMapInterface)
if err != nil {
return err
}
}
return nil
}