Skip to content

Commit 897602d

Browse files
authored
Merge pull request #173 from Charliekenney23/feat/obj-level-key
add object-acl get and update methods
2 parents 1dd66c8 + ea2620e commit 897602d

8 files changed

+656
-7
lines changed

object_storage_object.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

test/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module test
33
go 1.15
44

55
require (
6-
github.com/dnaeon/go-vcr v1.0.1
7-
github.com/google/go-cmp v0.5.2
8-
github.com/linode/linodego v0.20.1
9-
github.com/linode/linodego/k8s v0.0.0-00010101000000-000000000000
10-
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
11-
gopkg.in/yaml.v2 v2.3.0 // indirect
12-
k8s.io/client-go v0.18.3
6+
github.com/dnaeon/go-vcr v1.1.0
7+
github.com/google/go-cmp v0.5.2
8+
github.com/linode/linodego v0.20.1
9+
github.com/linode/linodego/k8s v0.0.0-00010101000000-000000000000
10+
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
11+
gopkg.in/yaml.v2 v2.3.0 // indirect
12+
k8s.io/client-go v0.18.3
1313
)
1414

1515
replace github.com/linode/linodego => ../

test/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
1919
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
2020
github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY=
2121
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
22+
github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c=
23+
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
2224
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
2325
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
2426
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
@@ -84,6 +86,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
8486
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
8587
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
8688
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
89+
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA=
90+
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
8791
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
8892
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
8993
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=

0 commit comments

Comments
 (0)