MCPcopy Create free account
hub / github.com/TalkingData/owl / SyncUsers

Function SyncUsers

api/users.go:47–92  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

45}
46
47func SyncUsers(c *gin.Context) {
48 client := http.Client{}
49 req, err := http.NewRequest("GET", fmt.Sprintf("%s/sync_users", config.IamURL), nil)
50 if err != nil {
51 panic(err)
52 }
53 req.Header.Add("App-ID", config.AppID)
54 req.Header.Add("Api-Key", config.AppKey)
55 resp, err := client.Do(req)
56 if err != nil {
57 panic(err)
58 }
59 buf, err := ioutil.ReadAll(resp.Body)
60 if err != nil {
61 panic(err)
62 }
63 s := struct {
64 Code int `json:"code"`
65 Message []User `json:"message"`
66 }{}
67 if err := json.Unmarshal(buf, &s); err != nil {
68 c.AbortWithError(http.StatusInternalServerError, err)
69 return
70 }
71 _, users := mydb.getAllUsers(false, "", "", 0, 0)
72 userMap := map[string]struct{}{}
73 for _, user := range s.Message {
74 userMap[user.Username] = struct{}{}
75 if user.Username == "" {
76 continue
77 }
78 user.Type = IAMUser
79 user, _ := mydb.createUser(&user)
80 log.Println("create user:", user)
81 }
82 for _, user := range users {
83 if _, ok := userMap[user.Username]; ok {
84 continue
85 }
86 if user.Type == IAMUser {
87 mydb.deleteUser(user.ID)
88 log.Printf("delete iam user %v", user)
89 }
90 }
91 c.JSON(http.StatusOK, gin.H{"users": s})
92}
93
94func listAllUsers(c *gin.Context) {
95 response := gin.H{"code": http.StatusOK}

Callers

nothing calls this directly

Calls 5

DoMethod · 0.80
getAllUsersMethod · 0.80
createUserMethod · 0.80
deleteUserMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected