Skip to content

Commit

Permalink
Merge pull request #173 from Charliekenney23/feat/obj-level-key
Browse files Browse the repository at this point in the history
add object-acl get and update methods
  • Loading branch information
0xch4z authored Dec 8, 2020
2 parents 1dd66c8 + ea2620e commit 897602d
Show file tree
Hide file tree
Showing 8 changed files with 656 additions and 7 deletions.
83 changes: 83 additions & 0 deletions object_storage_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
14 changes: 7 additions & 7 deletions test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module test
go 1.15

require (
github.com/dnaeon/go-vcr v1.0.1
github.com/google/go-cmp v0.5.2
github.com/linode/linodego v0.20.1
github.com/linode/linodego/k8s v0.0.0-00010101000000-000000000000
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
gopkg.in/yaml.v2 v2.3.0 // indirect
k8s.io/client-go v0.18.3
github.com/dnaeon/go-vcr v1.1.0
github.com/google/go-cmp v0.5.2
github.com/linode/linodego v0.20.1
github.com/linode/linodego/k8s v0.0.0-00010101000000-000000000000
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
gopkg.in/yaml.v2 v2.3.0 // indirect
k8s.io/client-go v0.18.3
)

replace github.com/linode/linodego => ../
Expand Down
4 changes: 4 additions & 0 deletions test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
Expand Down Expand Up @@ -84,6 +86,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
Loading

0 comments on commit 897602d

Please sign in to comment.