Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 1 | package stacktemplates |
| 2 | |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame^] | 3 | import "github.com/gophercloud/gophercloud" |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 4 | |
| 5 | // Get retreives data for the given stack template. |
| 6 | func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult { |
| 7 | var res GetResult |
Jon Perritt | a33da23 | 2016-03-02 04:43:08 -0600 | [diff] [blame] | 8 | _, res.Err = c.Request("GET", getURL(c, stackName, stackID), &gophercloud.RequestOpts{ |
Ash Wilson | decfed7 | 2015-02-13 09:14:55 -0500 | [diff] [blame] | 9 | JSONResponse: &res.Body, |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 10 | }) |
| 11 | return res |
| 12 | } |
| 13 | |
| 14 | // ValidateOptsBuilder describes struct types that can be accepted by the Validate call. |
| 15 | // The ValidateOpts struct in this package does. |
| 16 | type ValidateOptsBuilder interface { |
| 17 | ToStackTemplateValidateMap() (map[string]interface{}, error) |
| 18 | } |
| 19 | |
| 20 | // ValidateOpts specifies the template validation parameters. |
| 21 | type ValidateOpts struct { |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 22 | Template string |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 23 | TemplateURL string |
| 24 | } |
| 25 | |
| 26 | // ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts. |
| 27 | func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) { |
| 28 | vo := make(map[string]interface{}) |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 29 | if opts.Template != "" { |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 30 | vo["template"] = opts.Template |
| 31 | return vo, nil |
| 32 | } |
| 33 | if opts.TemplateURL != "" { |
| 34 | vo["template_url"] = opts.TemplateURL |
| 35 | return vo, nil |
| 36 | } |
Jon Perritt | 58611da | 2016-03-09 00:49:57 -0600 | [diff] [blame^] | 37 | err := gophercloud.ErrMissingInput{} |
| 38 | err.Argument = "stacktemplates.ValidateOpts.Template/stacktemplates.ValidateOpts.TemplateURL" |
| 39 | err.Info = "One of Template or TemplateURL is required." |
| 40 | return nil, err |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // Validate validates the given stack template. |
| 44 | func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) ValidateResult { |
| 45 | var res ValidateResult |
| 46 | |
| 47 | reqBody, err := opts.ToStackTemplateValidateMap() |
| 48 | if err != nil { |
| 49 | res.Err = err |
| 50 | return res |
| 51 | } |
| 52 | |
Jamie Hannaford | 1d27afa | 2015-03-24 16:20:45 +0100 | [diff] [blame] | 53 | _, res.Err = c.Post(validateURL(c), reqBody, &res.Body, &gophercloud.RequestOpts{ |
| 54 | OkCodes: []int{200}, |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 55 | }) |
| 56 | return res |
| 57 | } |