github.com/go-chef/chef@v0.30.1/organization.go (about) 1 package chef 2 3 import "fmt" 4 5 type OrganizationService struct { 6 client *Client 7 } 8 9 // Organization represents the native Go version of the deserialized Organization type 10 type Organization struct { 11 Name string `json:"name"` 12 FullName string `json:"full_name"` 13 Guid string `json:"guid"` 14 } 15 16 type OrganizationResult struct { 17 ClientName string `json:"clientname"` 18 PrivateKey string `json:"private_key"` 19 Uri string `json:"uri"` 20 } 21 22 // List lists the organizations in the Chef server. 23 // 24 // Chef API docs: https://docs.chef.io/api_chef_server.html#organizations 25 func (e *OrganizationService) List() (organizationlist map[string]string, err error) { 26 err = e.client.magicRequestDecoder("GET", "organizations", nil, &organizationlist) 27 return 28 } 29 30 // Get gets an organization from the Chef server. 31 // 32 // Chef API docs: http://docs.opscode.com/api_chef_server.html#id28 33 func (e *OrganizationService) Get(name string) (organization Organization, err error) { 34 url := fmt.Sprintf("organizations/%s", name) 35 err = e.client.magicRequestDecoder("GET", url, nil, &organization) 36 return 37 } 38 39 // Creates an Organization on the chef server 40 // 41 // Chef API docs: https://docs.chef.io/api_chef_server.html#organizations 42 func (e *OrganizationService) Create(organization Organization) (data OrganizationResult, err error) { 43 body, err := JSONReader(organization) 44 if err != nil { 45 return 46 } 47 48 var orglist map[string]string 49 err = e.client.magicRequestDecoder("POST", "organizations", body, &orglist) 50 data.ClientName = orglist["clientname"] 51 data.PrivateKey = orglist["private_key"] 52 data.Uri = orglist["uri"] 53 return 54 } 55 56 // Update an organization on the Chef server. 57 // 58 // Chef API docs: https://docs.chef.io/api_chef_server.html#organizations 59 func (e *OrganizationService) Update(g Organization) (organization Organization, err error) { 60 url := fmt.Sprintf("organizations/%s", g.Name) 61 body, err := JSONReader(g) 62 if err != nil { 63 return 64 } 65 66 err = e.client.magicRequestDecoder("PUT", url, body, &organization) 67 return 68 } 69 70 // Delete removes an organization on the Chef server 71 // 72 // Chef API docs: https://docs.chef.io/api_chef_server.html#organizations 73 func (e *OrganizationService) Delete(name string) (err error) { 74 err = e.client.magicRequestDecoder("DELETE", "organizations/"+name, nil, nil) 75 return 76 }