forked from lusis/go-rundeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
acl_policy.go
52 lines (47 loc) · 1.31 KB
/
acl_policy.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
package rundeck
import (
"encoding/xml"
"fmt"
)
type AclPolicies struct {
XMLName xml.Name `xml:"resource"`
Path string `xml:"path,attr"`
Type string `xml:"type,attr"`
Href string `xml:"href,attr"`
Contents AclListContents `xml:"contents,omitempty"`
}
type AclListContents struct {
XMLName xml.Name `xml:"contents"`
Resources []struct {
XMLName xml.Name `xml:"resource"`
Path string `xml:"path,attr"`
Type string `xml:"type,attr"`
Href string `xml:"href,attr"`
Name string `xml:"name,attr"`
} `xml:"resource,omitempty"`
}
func (c *RundeckClient) GetSystemAclPolicies() (data AclPolicies, err error) {
u := make(map[string]string)
var res []byte
err = c.Get(&res, "system/acl/", u)
if err != nil {
return data, err
} else {
xml.Unmarshal(res, &data)
return data, nil
}
}
func (c *RundeckClient) CreateSystemAclPolicy(name string, contents []byte) error {
var res []byte
u := make(map[string]string)
u["content_type"] = "application/yaml"
url := fmt.Sprintf("system/acl/%s.aclpolicy", name)
payload := fmt.Sprintf("<contents><![CDATA[%s]]></contents>", string(contents))
fmt.Printf("%s\n", payload)
err := c.Post(&res, url, []byte(payload), u)
if err != nil {
fmt.Printf("%#v\n", string(res))
return err
}
return nil
}