forked from go-chef/chef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganization.go
76 lines (65 loc) · 2.24 KB
/
organization.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
package chef
import "fmt"
type OrganizationService struct {
client *Client
}
// Organization represents the native Go version of the deserialized Organization type
type Organization struct {
Name string `json:"name"`
FullName string `json:"full_name"`
Guid string `json:"guid"`
}
type OrganizationResult struct {
ClientName string `json:"clientname"`
PrivateKey string `json:"private_key"`
Uri string `json:"uri"`
}
// List lists the organizations in the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#organizations
func (e *OrganizationService) List() (organizationlist map[string]string, err error) {
err = e.client.magicRequestDecoder("GET", "organizations", nil, &organizationlist)
return
}
// Get gets an organization from the Chef server.
//
// Chef API docs: http://docs.opscode.com/api_chef_server.html#id28
func (e *OrganizationService) Get(name string) (organization Organization, err error) {
url := fmt.Sprintf("organizations/%s", name)
err = e.client.magicRequestDecoder("GET", url, nil, &organization)
return
}
// Creates an Organization on the chef server
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#organizations
func (e *OrganizationService) Create(organization Organization) (data OrganizationResult, err error) {
body, err := JSONReader(organization)
if err != nil {
return
}
var orglist map[string]string
err = e.client.magicRequestDecoder("POST", "organizations", body, &orglist)
data.ClientName = orglist["clientname"]
data.PrivateKey = orglist["private_key"]
data.Uri = orglist["uri"]
return
}
// Update an organization on the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#organizations
func (e *OrganizationService) Update(g Organization) (organization Organization, err error) {
url := fmt.Sprintf("organizations/%s", g.Name)
body, err := JSONReader(g)
if err != nil {
return
}
err = e.client.magicRequestDecoder("PUT", url, body, &organization)
return
}
// Delete removes an organization on the Chef server
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#organizations
func (e *OrganizationService) Delete(name string) (err error) {
err = e.client.magicRequestDecoder("DELETE", "organizations/"+name, nil, nil)
return
}