forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_storage_bucket_certs.go
57 lines (50 loc) · 1.83 KB
/
object_storage_bucket_certs.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
package linodego
import (
"context"
"encoding/json"
"fmt"
"net/url"
)
type ObjectStorageBucketCert struct {
SSL bool `json:"ssl"`
}
type ObjectStorageBucketCertUploadOptions struct {
Certificate string `json:"certificate"`
PrivateKey string `json:"private_key"`
}
// UploadObjectStorageBucketCert uploads a TLS/SSL Cert to be used with an Object Storage Bucket.
func (c *Client) UploadObjectStorageBucketCert(ctx context.Context, clusterID, bucket string, opts ObjectStorageBucketCertUploadOptions) (*ObjectStorageBucketCert, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}
clusterID = url.PathEscape(clusterID)
bucket = url.PathEscape(bucket)
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterID, bucket)
req := c.R(ctx).SetResult(&ObjectStorageBucketCert{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Post(e))
if err != nil {
return nil, err
}
return r.Result().(*ObjectStorageBucketCert), nil
}
// GetObjectStorageBucketCert gets an ObjectStorageBucketCert
func (c *Client) GetObjectStorageBucketCert(ctx context.Context, clusterID, bucket string) (*ObjectStorageBucketCert, error) {
clusterID = url.PathEscape(clusterID)
bucket = url.PathEscape(bucket)
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterID, bucket)
req := c.R(ctx).SetResult(&ObjectStorageBucketCert{})
r, err := coupleAPIErrors(req.Get(e))
if err != nil {
return nil, err
}
return r.Result().(*ObjectStorageBucketCert), nil
}
// DeleteObjectStorageBucketCert deletes an ObjectStorageBucketCert
func (c *Client) DeleteObjectStorageBucketCert(ctx context.Context, clusterID, bucket string) error {
clusterID = url.PathEscape(clusterID)
bucket = url.PathEscape(bucket)
e := fmt.Sprintf("object-storage/buckets/%s/%s/ssl", clusterID, bucket)
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
return err
}