github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/orchestration/v1/stacktemplates/requests.go (about) 1 package stacktemplates 2 3 import ( 4 "context" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 ) 8 9 // Get retreives data for the given stack template. 10 func Get(ctx context.Context, c *gophercloud.ServiceClient, stackName, stackID string) (r GetResult) { 11 resp, err := c.Get(ctx, getURL(c, stackName, stackID), &r.Body, nil) 12 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 13 return 14 } 15 16 // ValidateOptsBuilder describes struct types that can be accepted by the Validate call. 17 // The ValidateOpts struct in this package does. 18 type ValidateOptsBuilder interface { 19 ToStackTemplateValidateMap() (map[string]any, error) 20 } 21 22 // ValidateOpts specifies the template validation parameters. 23 type ValidateOpts struct { 24 Template string `json:"template" or:"TemplateURL"` 25 TemplateURL string `json:"template_url" or:"Template"` 26 } 27 28 // ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts. 29 func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]any, error) { 30 return gophercloud.BuildRequestBody(opts, "") 31 } 32 33 // Validate validates the given stack template. 34 func Validate(ctx context.Context, c *gophercloud.ServiceClient, opts ValidateOptsBuilder) (r ValidateResult) { 35 b, err := opts.ToStackTemplateValidateMap() 36 if err != nil { 37 r.Err = err 38 return 39 } 40 resp, err := c.Post(ctx, validateURL(c), b, &r.Body, &gophercloud.RequestOpts{ 41 OkCodes: []int{200}, 42 }) 43 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 44 return 45 }