forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_storage_object.go
83 lines (67 loc) · 2.38 KB
/
object_storage_object.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
package linodego
import (
"context"
"encoding/json"
"fmt"
)
type ObjectStorageObjectURLCreateOptions struct {
Name string `json:"name"`
Method string `json:"method"`
ContentType string `json:"content_type,omit_empty"`
ContentDisposition string `json:"content_disposition,omit_empty"`
ExpiresIn *int `json:"expires_in,omit_empty"`
}
type ObjectStorageObjectURL struct {
URL string `json:"url"`
Exists bool `json:"exists"`
}
type ObjectStorageObjectACLConfig struct {
ACL string `json:"acl"`
ACLXML string `json:"acl_xml"`
}
type ObjectStorageObjectACLConfigUpdateOptions struct {
Name string `json:"name"`
ACL string `json:"acl"`
}
func (c *Client) CreateObjectStorageObjectURL(ctx context.Context, clusterID, label string, options ObjectStorageObjectURLCreateOptions) (*ObjectStorageObjectURL, error) {
var body string
e, err := c.ObjectStorageBuckets.Endpoint()
if err != nil {
return nil, err
}
req := c.R(ctx).SetResult(&ObjectStorageObjectURL{})
e = fmt.Sprintf("%s/%s/%s/object-url", e, clusterID, label)
if bodyData, err := json.Marshal(options); err == nil {
body = string(bodyData)
} else {
return nil, NewError(err)
}
r, err := coupleAPIErrors(req.SetBody(body).Post(e))
return r.Result().(*ObjectStorageObjectURL), err
}
func (c *Client) GetObjectStorageObjectACLConfig(ctx context.Context, clusterID, label, object string) (*ObjectStorageObjectACLConfig, error) {
e, err := c.ObjectStorageBuckets.Endpoint()
if err != nil {
return nil, err
}
req := c.R(ctx).SetResult(&ObjectStorageObjectACLConfig{})
e = fmt.Sprintf("%s/%s/%s/object-acl?name=%s", e, clusterID, label, object)
r, err := coupleAPIErrors(req.Get(e))
return r.Result().(*ObjectStorageObjectACLConfig), err
}
func (c *Client) UpdateObjectStorageObjectACLConfig(ctx context.Context, clusterID, label string, options ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfig, error) {
var body string
e, err := c.ObjectStorageBuckets.Endpoint()
if err != nil {
return nil, err
}
req := c.R(ctx).SetResult(&ObjectStorageObjectACLConfig{})
e = fmt.Sprintf("%s/%s/%s/object-acl", e, clusterID, label)
if bodyData, err := json.Marshal(options); err == nil {
body = string(bodyData)
} else {
return nil, NewError(err)
}
r, err := coupleAPIErrors(req.SetBody(body).Put(e))
return r.Result().(*ObjectStorageObjectACLConfig), err
}