Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 1 | package stacktemplates |
| 2 | |
| 3 | import ( |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 4 | "encoding/json" |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 5 | "github.com/mitchellh/mapstructure" |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | ) |
| 8 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame] | 9 | // GetResult represents the result of a Get operation. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 10 | type GetResult struct { |
| 11 | gophercloud.Result |
| 12 | } |
| 13 | |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 14 | // Extract returns the JSON template and is called after a Get operation. |
| 15 | func (r GetResult) Extract() ([]byte, error) { |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 16 | if r.Err != nil { |
| 17 | return nil, r.Err |
| 18 | } |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 19 | template, err := json.MarshalIndent(r.Body, "", " ") |
| 20 | if err != nil { |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 21 | return nil, err |
| 22 | } |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 23 | return template, nil |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame] | 26 | // ValidatedTemplate represents the parsed object returned from a Validate request. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 27 | type ValidatedTemplate struct { |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 28 | Description string `mapstructure:"Description"` |
| 29 | Parameters map[string]interface{} `mapstructure:"Parameters"` |
| 30 | ParameterGroups map[string]interface{} `mapstructure:"ParameterGroups"` |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame] | 33 | // ValidateResult represents the result of a Validate operation. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 34 | type ValidateResult struct { |
| 35 | gophercloud.Result |
| 36 | } |
| 37 | |
Jon Perritt | 8ade432 | 2015-02-09 11:34:59 -0700 | [diff] [blame] | 38 | // Extract returns a pointer to a ValidatedTemplate object and is called after a |
| 39 | // Validate operation. |
Jon Perritt | f799b94 | 2015-02-09 11:23:28 -0700 | [diff] [blame] | 40 | func (r ValidateResult) Extract() (*ValidatedTemplate, error) { |
| 41 | if r.Err != nil { |
| 42 | return nil, r.Err |
| 43 | } |
| 44 | |
| 45 | var res ValidatedTemplate |
| 46 | if err := mapstructure.Decode(r.Body, &res); err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | |
| 50 | return &res, nil |
| 51 | } |