-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathusers.go
More file actions
48 lines (38 loc) · 1.08 KB
/
users.go
File metadata and controls
48 lines (38 loc) · 1.08 KB
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
// Package users provides methods for viewing users.
package users
import (
"encoding/json"
"fmt"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/controller-sdk-go/api"
)
// List lists users registered with the controller.
func List(c *drycc.Client, results int) (api.Users, int, error) {
body, count, reqErr := c.LimitedRequest("/v2/users/", results)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return []api.User{}, -1, reqErr
}
var users []api.User
if err := json.Unmarshal([]byte(body), &users); err != nil {
return []api.User{}, -1, err
}
return users, count, reqErr
}
// Enable user with the controller.
func Enable(c *drycc.Client, username string) error {
u := fmt.Sprintf("/v2/users/%s/enable/", username)
res, err := c.Request("PATCH", u, nil)
if err == nil {
return res.Body.Close()
}
return err
}
// Disable user with the controller.
func Disable(c *drycc.Client, username string) error {
u := fmt.Sprintf("/v2/users/%s/disable/", username)
res, err := c.Request("PATCH", u, nil)
if err == nil {
return res.Body.Close()
}
return err
}