blob: ad1e468d1996da548c458f864cb74ba1a43dcee9 [file] [log] [blame]
Jon Perrittf799b942015-02-09 11:23:28 -07001package stacktemplates
2
3import (
4 "fmt"
5
Jon Perrittf799b942015-02-09 11:23:28 -07006 "github.com/rackspace/gophercloud"
7)
8
9// Get retreives data for the given stack template.
10func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult {
11 var res GetResult
Ash Wilsondecfed72015-02-13 09:14:55 -050012 _, res.Err = c.Request("GET", getURL(c, stackName, stackID), gophercloud.RequestOpts{
13 JSONResponse: &res.Body,
Jon Perrittf799b942015-02-09 11:23:28 -070014 })
15 return res
16}
17
18// ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
19// The ValidateOpts struct in this package does.
20type ValidateOptsBuilder interface {
21 ToStackTemplateValidateMap() (map[string]interface{}, error)
22}
23
24// ValidateOpts specifies the template validation parameters.
25type ValidateOpts struct {
26 Template map[string]interface{}
27 TemplateURL string
28}
29
30// ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
31func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
32 vo := make(map[string]interface{})
33 if opts.Template != nil {
34 vo["template"] = opts.Template
35 return vo, nil
36 }
37 if opts.TemplateURL != "" {
38 vo["template_url"] = opts.TemplateURL
39 return vo, nil
40 }
41 return vo, fmt.Errorf("One of Template or TemplateURL is required.")
42}
43
44// Validate validates the given stack template.
45func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) ValidateResult {
46 var res ValidateResult
47
48 reqBody, err := opts.ToStackTemplateValidateMap()
49 if err != nil {
50 res.Err = err
51 return res
52 }
53
Jamie Hannaford1d27afa2015-03-24 16:20:45 +010054 _, res.Err = c.Post(validateURL(c), reqBody, &res.Body, &gophercloud.RequestOpts{
55 OkCodes: []int{200},
Jon Perrittf799b942015-02-09 11:23:28 -070056 })
57 return res
58}