/
requests.go
56 lines (49 loc) · 1.78 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
package certificates
import (
"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)
resp, err := client.Get(url, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
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
}
resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Update will rotate the CA certificate for a cluster
func Update(client *gophercloud.ServiceClient, clusterID string) (r UpdateResult) {
resp, err := client.Patch(updateURL(client, clusterID), nil, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{202},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}