blob: 4e9ba5a4c613fae699f177796d7b3a3acdf9be52 [file] [log] [blame]
Jon Perrittf799b942015-02-09 11:23:28 -07001package stacktemplates
2
3import (
Pratik Mallya827c03e2015-09-17 00:10:47 -05004 "encoding/json"
Jon Perrittf799b942015-02-09 11:23:28 -07005 "github.com/mitchellh/mapstructure"
6 "github.com/rackspace/gophercloud"
7)
8
Jon Perritt8ade4322015-02-09 11:34:59 -07009// GetResult represents the result of a Get operation.
Jon Perrittf799b942015-02-09 11:23:28 -070010type GetResult struct {
11 gophercloud.Result
12}
13
Pratik Mallya827c03e2015-09-17 00:10:47 -050014// Extract returns the JSON template and is called after a Get operation.
15func (r GetResult) Extract() ([]byte, error) {
Jon Perrittf799b942015-02-09 11:23:28 -070016 if r.Err != nil {
17 return nil, r.Err
18 }
Pratik Mallya827c03e2015-09-17 00:10:47 -050019 template, err := json.MarshalIndent(r.Body, "", " ")
20 if err != nil {
Jon Perrittf799b942015-02-09 11:23:28 -070021 return nil, err
22 }
Pratik Mallya827c03e2015-09-17 00:10:47 -050023 return template, nil
Jon Perrittf799b942015-02-09 11:23:28 -070024}
25
Jon Perritt8ade4322015-02-09 11:34:59 -070026// ValidatedTemplate represents the parsed object returned from a Validate request.
Jon Perrittf799b942015-02-09 11:23:28 -070027type ValidatedTemplate struct {
Pratik Mallya827c03e2015-09-17 00:10:47 -050028 Description string `mapstructure:"Description"`
29 Parameters map[string]interface{} `mapstructure:"Parameters"`
30 ParameterGroups map[string]interface{} `mapstructure:"ParameterGroups"`
Jon Perrittf799b942015-02-09 11:23:28 -070031}
32
Jon Perritt8ade4322015-02-09 11:34:59 -070033// ValidateResult represents the result of a Validate operation.
Jon Perrittf799b942015-02-09 11:23:28 -070034type ValidateResult struct {
35 gophercloud.Result
36}
37
Jon Perritt8ade4322015-02-09 11:34:59 -070038// Extract returns a pointer to a ValidatedTemplate object and is called after a
39// Validate operation.
Jon Perrittf799b942015-02-09 11:23:28 -070040func (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}