forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.go
65 lines (51 loc) · 1.7 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
package certificates
import (
"net/http"
"github.com/gophercloud/gophercloud"
)
// CreateOptsBuilder allows extensions to add additional parameters
// to the Create request.
type CreateOptsBuilder interface {
ToCertificateCreateMap() (map[string]interface{}, error)
}
// CreateOpts represents options used to create a certificate.
type CreateOpts struct {
ClusterUUID string `json:"cluster_uuid,omitempty" xor:"BayUUID"`
BayUUID string `json:"bay_uuid,omitempty" xor:"ClusterUUID"`
CSR string `json:"csr" required:"true"`
}
// ToCertificateCreateMap constructs a request body from CreateOpts.
func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
// Get makes a request against the API to get details for a certificate.
func Get(client *gophercloud.ServiceClient, clusterID string) (r GetResult) {
url := getURL(client, clusterID)
_, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}
// Create requests the creation of a new certificate.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToCertificateCreateMap()
if err != nil {
r.Err = err
return
}
var result *http.Response
result, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
if r.Err == nil {
r.Header = result.Header
}
return
}
// Update will rotate the CA certificate for a cluster
func Update(client *gophercloud.ServiceClient, clusterID string) (r UpdateResult) {
_, r.Err = client.Patch(updateURL(client, clusterID), nil, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{202},
})
return
}