Created
December 9, 2014 18:47
-
-
Save bigkraig/f0baee2993ac2717492c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
var DefaultACLs = [5]string{ | |
"create", | |
"read", | |
"update", | |
"delete", | |
"grant", | |
} | |
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment