-
Notifications
You must be signed in to change notification settings - Fork 64
/
group.go
85 lines (73 loc) · 2.23 KB
/
group.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
75
76
77
78
79
80
81
82
83
84
85
package chef
import "fmt"
type GroupService struct {
client *Client
}
// Group represents the native Go version of the deserialized Group type
type Group struct {
Name string `json:"name"`
GroupName string `json:"groupname"`
OrgName string `json:"orgname"`
Actors []string `json:"actors"`
Clients []string `json:"clients"`
Groups []string `json:"groups"`
Users []string `json:"users"`
}
// GroupUpdate represents the payload needed to update a group
type GroupUpdate struct {
Name string `json:"name"`
GroupName string `json:"groupname"`
Actors struct {
Clients []string `json:"clients"`
Groups []string `json:"groups"`
Users []string `json:"users"`
} `json:"actors"`
}
type GroupResult struct {
Uri string `json:"uri"`
}
// List lists the groups in the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#groups
func (e *GroupService) List() (grouplist map[string]string, err error) {
err = e.client.magicRequestDecoder("GET", "groups", nil, &grouplist)
return
}
// Get gets a group from the Chef server.
//
// Chef API docs: http://docs.opscode.com/api_chef_server.html#id28
func (e *GroupService) Get(name string) (group Group, err error) {
url := fmt.Sprintf("groups/%s", name)
err = e.client.magicRequestDecoder("GET", url, nil, &group)
return
}
// Creates a Group on the chef server
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#groups
func (e *GroupService) Create(group Group) (data *GroupResult, err error) {
body, err := JSONReader(group)
if err != nil {
return
}
err = e.client.magicRequestDecoder("POST", "groups", body, &data)
return
}
// Update a group on the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#groups
func (e *GroupService) Update(g GroupUpdate) (group GroupUpdate, err error) {
url := fmt.Sprintf("groups/%s", g.Name)
body, err := JSONReader(g)
if err != nil {
return
}
err = e.client.magicRequestDecoder("PUT", url, body, &group)
return
}
// Delete removes a group on the Chef server
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#groups
func (e *GroupService) Delete(name string) (err error) {
err = e.client.magicRequestDecoder("DELETE", "groups/"+name, nil, nil)
return
}