/
requests.go
41 lines (35 loc) · 1.38 KB
/
requests.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
package stacktemplates
import "github.com/gophercloud/gophercloud"
// Get retreives data for the given stack template.
func Get(c *gophercloud.ServiceClient, stackName, stackID string) (r GetResult) {
resp, err := c.Get(getURL(c, stackName, stackID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
// The ValidateOpts struct in this package does.
type ValidateOptsBuilder interface {
ToStackTemplateValidateMap() (map[string]interface{}, error)
}
// ValidateOpts specifies the template validation parameters.
type ValidateOpts struct {
Template string `json:"template" or:"TemplateURL"`
TemplateURL string `json:"template_url" or:"Template"`
}
// ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
// Validate validates the given stack template.
func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) (r ValidateResult) {
b, err := opts.ToStackTemplateValidateMap()
if err != nil {
r.Err = err
return
}
resp, err := c.Post(validateURL(c), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}