-
Notifications
You must be signed in to change notification settings - Fork 64
/
policy_group.go
66 lines (55 loc) · 2.45 KB
/
policy_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
package chef
import (
"fmt"
)
// PolicyGroupService is the service for interacting with chef server policies endpoint
type PolicyGroupService struct {
client *Client
}
// PolicyGroupGetResponse is returned from the chef-server for Get Requests to /policy_groups
type PolicyGroupGetResponse map[string]PolicyGroup
type PolicyGroup struct {
Uri string `json:"uri,omitempty"`
Policies map[string]Revision `json:"policies,omitempty"`
}
type Revision map[string]string
// List lists the policy groups in the Chef server.
// Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups
func (e *PolicyGroupService) List() (data PolicyGroupGetResponse, err error) {
err = e.client.magicRequestDecoder("GET", "policy_groups", nil, &data)
return
}
// Get gets the information for a specific policy group
// GET /policy_groups/GROUP
// Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups
func (e *PolicyGroupService) Get(policyGroupName string) (data PolicyGroup, err error) {
url := fmt.Sprintf("policy_groups/%s", policyGroupName)
err = e.client.magicRequestDecoder("GET", url, nil, &data)
return
}
// Delete deletes a policy group.
// DELETE /policy_groups/GROUP
// Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups
func (e *PolicyGroupService) Delete(policyGroupName string) (data PolicyGroup, err error) {
url := fmt.Sprintf("policy_groups/%s", policyGroupName)
err = e.client.magicRequestDecoder("DELETE", url, nil, &data)
return
}
// GetPolicy gets the information for a specific policy in a policy group
// GET /policy_groups/GROUP/policies/NAME
// Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups
func (e *PolicyGroupService) GetPolicy(policyGroupName string, policyName string) (data RevisionDetailsResponse, err error) {
url := fmt.Sprintf("policy_groups/%s/policies/%s", policyGroupName, policyName)
err = e.client.magicRequestDecoder("GET", url, nil, &data)
return
}
// DeletePolicy deletes a specific policy in a policy group
// DELETE /policy_groups/GROUP/policies/NAME
// Chef API docs: https://docs.chef.io/api_chef_server/#policy_groups
func (e *PolicyGroupService) DeletePolicy(policyGroupName string, policyName string) (data RevisionDetailsResponse, err error) {
url := fmt.Sprintf("policy_groups/%s/policies/%s", policyGroupName, policyName)
err = e.client.magicRequestDecoder("DELETE", url, nil, &data)
return
}
// policy_group/GN/policies/PN oc_chef_wm_named_policy_named_revision.erl
// PUT