-
Notifications
You must be signed in to change notification settings - Fork 510
/
requests.go
121 lines (105 loc) · 3.94 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package resourcetypes
import (
"github.com/gophercloud/gophercloud"
)
// SupportStatus is a type for specifying by which support status to filter the
// list of resource types.
type SupportStatus string
const (
// SupportStatusUnknown is returned when the resource type does not have a
// support status.
SupportStatusUnknown SupportStatus = "UNKNOWN"
// SupportStatusSupported indicates a resource type that is expected to
// work.
SupportStatusSupported SupportStatus = "SUPPORTED"
// SupportStatusDeprecated indicates a resource type that is in the process
// being removed, and may or may not be replaced by something else.
SupportStatusDeprecated SupportStatus = "DEPRECATED"
// SupportStatusHidden indicates a resource type that has been removed.
// Existing stacks that contain resources of this type can still be
// deleted or updated to remove the resources, but they may not actually
// do anything any more.
SupportStatusHidden SupportStatus = "HIDDEN"
// SupportStatusUnsupported indicates a resource type that is provided for
// preview or other purposes and should not be relied upon.
SupportStatusUnsupported SupportStatus = "UNSUPPORTED"
)
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToResourceTypeListQuery() (string, error)
}
// ListOpts allows the filtering of collections through the API.
type ListOpts struct {
// Filters the resource type list by a regex on the name.
NameRegex string `q:"name"`
// Filters the resource list by the specified SupportStatus.
SupportStatus SupportStatus `q:"support_status"`
// Return descriptions as well as names of resource types
WithDescription bool `q:"with_description"`
}
// ToResourceTypeListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToResourceTypeListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// List makes a request against the API to list available resource types.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) (r ListResult) {
url := listURL(client)
if opts == nil {
opts = ListOpts{}
}
query, err := opts.ToResourceTypeListQuery()
if err != nil {
r.Err = err
return
}
url += query
resp, err := client.Get(url, &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// GetSchema retreives the schema for a given resource type.
func GetSchema(client *gophercloud.ServiceClient, resourceType string) (r GetSchemaResult) {
resp, err := client.Get(getSchemaURL(client, resourceType), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// GenerateTemplateOptsBuilder allows extensions to add additional parameters
// to the GenerateTemplate request.
type GenerateTemplateOptsBuilder interface {
ToGenerateTemplateQuery() (string, error)
}
type GeneratedTemplateType string
const (
TemplateTypeHOT GeneratedTemplateType = "hot"
TemplateTypeCFn GeneratedTemplateType = "cfn"
)
// GenerateTemplateOpts allows the filtering of collections through the API.
type GenerateTemplateOpts struct {
TemplateType GeneratedTemplateType `q:"template_type"`
}
// ToGenerateTemplateQuery formats a GenerateTemplateOpts into a query string.
func (opts GenerateTemplateOpts) ToGenerateTemplateQuery() (string, error) {
if opts.TemplateType == "" {
opts.TemplateType = TemplateTypeHOT
}
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// GenerateTemplate retreives an example template for a given resource type.
func GenerateTemplate(client *gophercloud.ServiceClient, resourceType string, opts GenerateTemplateOptsBuilder) (r TemplateResult) {
url := generateTemplateURL(client, resourceType)
if opts == nil {
opts = GenerateTemplateOpts{}
}
query, err := opts.ToGenerateTemplateQuery()
if err != nil {
r.Err = err
return
}
url += query
resp, err := client.Get(url, &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}