blob: f57e226efbfaa7a12803dcf67c7af6e424edd791 [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,
14 OkCodes: []int{200},
Jon Perrittf799b942015-02-09 11:23:28 -070015 })
16 return res
17}
18
19// ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
20// The ValidateOpts struct in this package does.
21type ValidateOptsBuilder interface {
22 ToStackTemplateValidateMap() (map[string]interface{}, error)
23}
24
25// ValidateOpts specifies the template validation parameters.
26type ValidateOpts struct {
27 Template map[string]interface{}
28 TemplateURL string
29}
30
31// ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
32func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
33 vo := make(map[string]interface{})
34 if opts.Template != nil {
35 vo["template"] = opts.Template
36 return vo, nil
37 }
38 if opts.TemplateURL != "" {
39 vo["template_url"] = opts.TemplateURL
40 return vo, nil
41 }
42 return vo, fmt.Errorf("One of Template or TemplateURL is required.")
43}
44
45// Validate validates the given stack template.
46func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) ValidateResult {
47 var res ValidateResult
48
49 reqBody, err := opts.ToStackTemplateValidateMap()
50 if err != nil {
51 res.Err = err
52 return res
53 }
54
Ash Wilsondecfed72015-02-13 09:14:55 -050055 _, res.Err = c.Request("POST", validateURL(c), gophercloud.RequestOpts{
56 JSONBody: reqBody,
57 JSONResponse: &res.Body,
58 OkCodes: []int{200},
Jon Perrittf799b942015-02-09 11:23:28 -070059 })
60 return res
61}