-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathperms.go
More file actions
71 lines (58 loc) · 1.72 KB
/
perms.go
File metadata and controls
71 lines (58 loc) · 1.72 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Package perms provides methods for managing user app and administrative permissions.
package perms
import (
"encoding/json"
"fmt"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/controller-sdk-go/api"
)
// List UserPerm
func List(c *drycc.Client, appID string, results int) ([]api.UserPermResponse, int, error) {
u := fmt.Sprintf("/v2/apps/%s/perms/", appID)
body, count, reqErr := c.LimitedRequest(u, results)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return []api.UserPermResponse{}, count, reqErr
}
var userPerm []api.UserPermResponse
if err := json.Unmarshal([]byte(body), &userPerm); err != nil {
return []api.UserPermResponse{}, count, err
}
return userPerm, count, reqErr
}
// Create a App user'Perms
func Create(c *drycc.Client, appID, username, permissions string) error {
req := api.UserPermRequest{Username: username, Permissions: permissions}
reqBody, err := json.Marshal(req)
if err != nil {
return err
}
u := fmt.Sprintf("/v2/apps/%s/perms/", appID)
res, err := c.Request("POST", u, reqBody)
if err == nil {
res.Body.Close()
}
return err
}
// Update a App user'Perms
func Update(c *drycc.Client, appID, username, permissions string) error {
req := api.UserPermRequest{Username: username, Permissions: permissions}
reqBody, err := json.Marshal(req)
if err != nil {
return err
}
u := fmt.Sprintf("/v2/apps/%s/perms/%s/", appID, username)
res, err := c.Request("PUT", u, reqBody)
if err == nil {
res.Body.Close()
}
return err
}
// Delete a App user'Perms.
func Delete(c *drycc.Client, appID, username string) error {
u := fmt.Sprintf("/v2/apps/%s/perms/%s/", appID, username)
res, err := c.Request("DELETE", u, nil)
if err == nil {
res.Body.Close()
}
return err
}