File: acl.go

package info (click to toggle)
golang-github-go-chef-chef 0.0.1%2Bgit20161023.60.deb8c38-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 332 kB
  • ctags: 290
  • sloc: sh: 14; makefile: 7
file content (52 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (3)
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
package chef

import "fmt"

type ACLService struct {
	client *Client
}

// ACL represents the native Go version of the deserialized ACL type
type ACL map[string]ACLitems

// ACLitems
type ACLitems struct {
	Groups ACLitem `json:"groups"`
	Actors ACLitem `json:"actors"`
}

// ACLitem
type ACLitem []string

func NewACL(acltype string, actors, groups ACLitem) (acl *ACL) {
	acl = &ACL{
		acltype: ACLitems{
			Actors: actors,
			Groups: groups,
		},
	}
	return
}

// Get gets an ACL from the Chef server.
//
// Chef API docs: lol
func (a *ACLService) Get(subkind string, name string) (acl ACL, err error) {
	url := fmt.Sprintf("%s/%s/_acl", subkind, name)
	err = a.client.magicRequestDecoder("GET", url, nil, &acl)
	return
}

// Put updates an ACL on the Chef server.
//
// Chef API docs: rofl
func (a *ACLService) Put(subkind, name string, acltype string, item *ACL) (err error) {
	url := fmt.Sprintf("%s/%s/_acl/%s", subkind, name, acltype)
	body, err := JSONReader(item)
	if err != nil {
		return
	}

	err = a.client.magicRequestDecoder("PUT", url, body, nil)
	return
}