-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfiguration.go
87 lines (77 loc) · 2.31 KB
/
configuration.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package cloud66
import (
"strconv"
"time"
)
type Configuration struct {
Name string `json:"name"`
Type string `json:"type"`
Body string `json:"body"`
Comments string `json:"comments"`
CanApply bool `json:"can_apply"`
ChangedBy string `json:"changed_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (c *Client) ConfigurationList(stackUid string) ([]Configuration, error) {
queryStrings := make(map[string]string)
queryStrings["page"] = "1"
var p Pagination
var configurations []Configuration
var configurationRes []Configuration
for {
req, err := c.NewRequest("GET", "/stacks/"+stackUid+"/configuration.json", nil, queryStrings)
if err != nil {
return nil, err
}
configurationRes = nil
err = c.DoReq(req, &configurationRes, &p)
if err != nil {
return nil, err
}
configurations = append(configurations, configurationRes...)
if p.Current < p.Next {
queryStrings["page"] = strconv.Itoa(p.Next)
} else {
break
}
}
return configurations, nil
}
func (c *Client) ConfigurationDownload(stackUid, theType string) (*Configuration, error) {
var configurationRes Configuration
req, err := c.NewRequest("GET", "/stacks/"+stackUid+"/configuration/"+theType+"/show.json", nil, nil)
if err != nil {
return nil, err
}
err = c.DoReq(req, &configurationRes, nil)
if err != nil {
return nil, err
}
return &configurationRes, nil
}
func (c *Client) ConfigurationUpload(stackUid, theType, commitMessage, body string, mustApply bool) (*AsyncResult, error) {
params := struct {
CommitMessage string `json:"commit_message"`
Body string `json:"body"`
MustApply bool `json:"must_apply"`
}{
CommitMessage: commitMessage,
Body: body,
MustApply: mustApply,
}
req, err := c.NewRequest("POST", "/stacks/"+stackUid+"/configuration/"+theType+"/update.json", params, nil)
if err != nil {
return nil, err
}
var asyncResult *AsyncResult
return asyncResult, c.DoReq(req, &asyncResult, nil)
}
func (c *Client) ConfigurationApply(stackUid, theType string) (*AsyncResult, error) {
req, err := c.NewRequest("POST", "/stacks/"+stackUid+"/configuration/"+theType+"/apply.json", nil, nil)
if err != nil {
return nil, err
}
var asyncResult *AsyncResult
return asyncResult, c.DoReq(req, &asyncResult, nil)
}