|
| 1 | +package linodego |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "fmt" |
| 7 | +) |
| 8 | + |
| 9 | +type ObjectStorageObjectURLCreateOptions struct { |
| 10 | + Name string `json:"name"` |
| 11 | + Method string `json:"method"` |
| 12 | + ContentType string `json:"content_type,omit_empty"` |
| 13 | + ContentDisposition string `json:"content_disposition,omit_empty"` |
| 14 | + ExpiresIn *int `json:"expires_in,omit_empty"` |
| 15 | +} |
| 16 | + |
| 17 | +type ObjectStorageObjectURL struct { |
| 18 | + URL string `json:"url"` |
| 19 | + Exists bool `json:"exists"` |
| 20 | +} |
| 21 | + |
| 22 | +type ObjectStorageObjectACLConfig struct { |
| 23 | + ACL string `json:"acl"` |
| 24 | + ACLXML string `json:"acl_xml"` |
| 25 | +} |
| 26 | + |
| 27 | +type ObjectStorageObjectACLConfigUpdateOptions struct { |
| 28 | + Name string `json:"name"` |
| 29 | + ACL string `json:"acl"` |
| 30 | +} |
| 31 | + |
| 32 | +func (c *Client) CreateObjectStorageObjectURL(ctx context.Context, clusterID, label string, options ObjectStorageObjectURLCreateOptions) (*ObjectStorageObjectURL, error) { |
| 33 | + var body string |
| 34 | + e, err := c.ObjectStorageBuckets.Endpoint() |
| 35 | + if err != nil { |
| 36 | + return nil, err |
| 37 | + } |
| 38 | + |
| 39 | + req := c.R(ctx).SetResult(&ObjectStorageObjectURL{}) |
| 40 | + e = fmt.Sprintf("%s/%s/%s/object-url", e, clusterID, label) |
| 41 | + |
| 42 | + if bodyData, err := json.Marshal(options); err == nil { |
| 43 | + body = string(bodyData) |
| 44 | + } else { |
| 45 | + return nil, NewError(err) |
| 46 | + } |
| 47 | + |
| 48 | + r, err := coupleAPIErrors(req.SetBody(body).Post(e)) |
| 49 | + return r.Result().(*ObjectStorageObjectURL), err |
| 50 | +} |
| 51 | + |
| 52 | +func (c *Client) GetObjectStorageObjectACLConfig(ctx context.Context, clusterID, label, object string) (*ObjectStorageObjectACLConfig, error) { |
| 53 | + e, err := c.ObjectStorageBuckets.Endpoint() |
| 54 | + if err != nil { |
| 55 | + return nil, err |
| 56 | + } |
| 57 | + |
| 58 | + req := c.R(ctx).SetResult(&ObjectStorageObjectACLConfig{}) |
| 59 | + e = fmt.Sprintf("%s/%s/%s/object-acl?name=%s", e, clusterID, label, object) |
| 60 | + |
| 61 | + r, err := coupleAPIErrors(req.Get(e)) |
| 62 | + return r.Result().(*ObjectStorageObjectACLConfig), err |
| 63 | +} |
| 64 | + |
| 65 | +func (c *Client) UpdateObjectStorageObjectACLConfig(ctx context.Context, clusterID, label string, options ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfig, error) { |
| 66 | + var body string |
| 67 | + e, err := c.ObjectStorageBuckets.Endpoint() |
| 68 | + if err != nil { |
| 69 | + return nil, err |
| 70 | + } |
| 71 | + |
| 72 | + req := c.R(ctx).SetResult(&ObjectStorageObjectACLConfig{}) |
| 73 | + e = fmt.Sprintf("%s/%s/%s/object-acl", e, clusterID, label) |
| 74 | + |
| 75 | + if bodyData, err := json.Marshal(options); err == nil { |
| 76 | + body = string(bodyData) |
| 77 | + } else { |
| 78 | + return nil, NewError(err) |
| 79 | + } |
| 80 | + |
| 81 | + r, err := coupleAPIErrors(req.SetBody(body).Put(e)) |
| 82 | + return r.Result().(*ObjectStorageObjectACLConfig), err |
| 83 | +} |
0 commit comments