-
Notifications
You must be signed in to change notification settings - Fork 9
/
policy.go
48 lines (41 loc) · 1.1 KB
/
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
package cloud66
import (
"time"
)
type Policy struct {
Uid string `json:"uid"`
Name string `json:"name"`
Selector string `json:"selector"`
Sequence int `json:"sequence"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at_iso"`
UpdatedAt time.Time `json:"updated_at_iso"`
Tags []string `json:"tags"`
}
func (p Policy) String() string {
return p.Name
}
func (c *Client) AddPolicies(stackUid string, formationUid string, policies []*Policy, message string) ([]Policy, error) {
var policiesRes []Policy = make([]Policy, 0)
var singleRes *Policy
for _, policy := range policies {
params := struct {
Message string `json:"message"`
Policy *Policy `json:"policy"`
}{
Message: message,
Policy: policy,
}
singleRes = nil
req, err := c.NewRequest("POST", "/stacks/"+stackUid+"/formations/"+formationUid+"/policies.json", params, nil)
if err != nil {
return nil, err
}
err = c.DoReq(req, &singleRes, nil)
if err != nil {
return nil, err
}
policiesRes = append(policiesRes, *singleRes)
}
return policiesRes, nil
}