github.com/go-chef/chef@v0.30.1/policy_group.go (about) 1 package chef 2 3 import ( 4 "fmt" 5 ) 6 7 // PolicyGroupService is the service for interacting with chef server policies endpoint 8 type PolicyGroupService struct { 9 client *Client 10 } 11 12 // PolicyGroupGetResponse is returned from the chef-server for Get Requests to /policy_groups 13 type PolicyGroupGetResponse map[string]PolicyGroup 14 15 type PolicyGroup struct { 16 Uri string `json:"uri,omitempty"` 17 Policies map[string]Revision `json:"policies,omitempty"` 18 } 19 20 type Revision map[string]string 21 22 // List lists the policy groups in the Chef server. 23 // Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups 24 func (e *PolicyGroupService) List() (data PolicyGroupGetResponse, err error) { 25 err = e.client.magicRequestDecoder("GET", "policy_groups", nil, &data) 26 return 27 } 28 29 // Get gets the information for a specific policy group 30 // GET /policy_groups/GROUP 31 // Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups 32 func (e *PolicyGroupService) Get(policyGroupName string) (data PolicyGroup, err error) { 33 url := fmt.Sprintf("policy_groups/%s", policyGroupName) 34 err = e.client.magicRequestDecoder("GET", url, nil, &data) 35 return 36 } 37 38 // Delete deletes a policy group. 39 // DELETE /policy_groups/GROUP 40 // Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups 41 func (e *PolicyGroupService) Delete(policyGroupName string) (data PolicyGroup, err error) { 42 url := fmt.Sprintf("policy_groups/%s", policyGroupName) 43 err = e.client.magicRequestDecoder("DELETE", url, nil, &data) 44 return 45 } 46 47 // GetPolicy gets the information for a specific policy in a policy group 48 // GET /policy_groups/GROUP/policies/NAME 49 // Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups 50 func (e *PolicyGroupService) GetPolicy(policyGroupName string, policyName string) (data RevisionDetailsResponse, err error) { 51 url := fmt.Sprintf("policy_groups/%s/policies/%s", policyGroupName, policyName) 52 err = e.client.magicRequestDecoder("GET", url, nil, &data) 53 return 54 } 55 56 // DeletePolicy deletes a specific policy in a policy group 57 // DELETE /policy_groups/GROUP/policies/NAME 58 // Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups 59 func (e *PolicyGroupService) DeletePolicy(policyGroupName string, policyName string) (data RevisionDetailsResponse, err error) { 60 url := fmt.Sprintf("policy_groups/%s/policies/%s", policyGroupName, policyName) 61 err = e.client.magicRequestDecoder("DELETE", url, nil, &data) 62 return 63 } 64 65 // policy_group/GN/policies/PN oc_chef_wm_named_policy_named_revision.erl 66 // PUT