-
Notifications
You must be signed in to change notification settings - Fork 2
/
permission.go
56 lines (50 loc) · 1.42 KB
/
permission.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
package adafruitio
type Permission struct {
ID string `json:"id,omitempty"`
UserID string `json:"user_id,omitempty"`
Scope string `json:"scope,omitempty"`
ScopeValue string `json:"scope_value,omitempty"`
Model string `json:"model,omitempty"`
ObjectID string `json:"object_id,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
func (c *Client) ListPermissions(u, t string) ([]Permission, error) {
var permissions []Permission
resp, err := c.get("/" + u + "/type/" + t + "/acl")
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return permissions, err
}
return permissions, c.decodeJSON(resp, &permissions)
}
func (c *Client) CreatePermission(u, t string, p Permission) error {
resp, err := c.post("/"+u+"/type/"+t+"/acl", p)
if resp != nil {
defer resp.Body.Close()
}
return err
}
func (c *Client) UpdatePermission(u, t, a string, p Permission) error {
resp, err := c.patch("/"+u+"/type/"+t+"/acl/"+a, p)
if resp != nil {
defer resp.Body.Close()
}
return err
}
func (c *Client) ReplacePermission(u, t, a string, p Permission) error {
resp, err := c.put("/"+u+"/type/"+t+"/acl/"+a, p)
if resp != nil {
defer resp.Body.Close()
}
return err
}
func (c *Client) DeletePermission(u, t, a string) error {
resp, err := c.delete("/" + u + "/type/" + t + "/acl/" + a)
if resp != nil {
defer resp.Body.Close()
}
return err
}