github.com/go-chef/chef@v0.30.1/group.go (about) 1 package chef 2 3 import "fmt" 4 5 type GroupService struct { 6 client *Client 7 } 8 9 // Group represents the native Go version of the deserialized Group type 10 type Group struct { 11 Name string `json:"name"` 12 GroupName string `json:"groupname"` 13 OrgName string `json:"orgname"` 14 Actors []string `json:"actors"` 15 Clients []string `json:"clients"` 16 Groups []string `json:"groups"` 17 Users []string `json:"users"` 18 } 19 20 // GroupUpdate represents the payload needed to update a group 21 type GroupUpdate struct { 22 Name string `json:"name"` 23 GroupName string `json:"groupname"` 24 Actors struct { 25 Clients []string `json:"clients"` 26 Groups []string `json:"groups"` 27 Users []string `json:"users"` 28 } `json:"actors"` 29 } 30 31 type GroupResult struct { 32 Uri string `json:"uri"` 33 } 34 35 // List lists the groups in the Chef server. 36 // 37 // Chef API docs: https://docs.chef.io/api_chef_server.html#groups 38 func (e *GroupService) List() (grouplist map[string]string, err error) { 39 err = e.client.magicRequestDecoder("GET", "groups", nil, &grouplist) 40 return 41 } 42 43 // Get gets a group from the Chef server. 44 // 45 // Chef API docs: http://docs.opscode.com/api_chef_server.html#id28 46 func (e *GroupService) Get(name string) (group Group, err error) { 47 url := fmt.Sprintf("groups/%s", name) 48 err = e.client.magicRequestDecoder("GET", url, nil, &group) 49 return 50 } 51 52 // Creates a Group on the chef server 53 // 54 // Chef API docs: https://docs.chef.io/api_chef_server.html#groups 55 func (e *GroupService) Create(group Group) (data *GroupResult, err error) { 56 body, err := JSONReader(group) 57 if err != nil { 58 return 59 } 60 61 err = e.client.magicRequestDecoder("POST", "groups", body, &data) 62 return 63 } 64 65 // Update a group on the Chef server. 66 // 67 // Chef API docs: https://docs.chef.io/api_chef_server.html#groups 68 func (e *GroupService) Update(g GroupUpdate) (group GroupUpdate, err error) { 69 url := fmt.Sprintf("groups/%s", g.Name) 70 body, err := JSONReader(g) 71 if err != nil { 72 return 73 } 74 75 err = e.client.magicRequestDecoder("PUT", url, body, &group) 76 return 77 } 78 79 // Delete removes a group on the Chef server 80 // 81 // Chef API docs: https://docs.chef.io/api_chef_server.html#groups 82 func (e *GroupService) Delete(name string) (err error) { 83 err = e.client.magicRequestDecoder("DELETE", "groups/"+name, nil, nil) 84 return 85 }