Skip to content

Commit

Permalink
Escape labels in urls (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
yec-akamai authored Mar 30, 2023
1 parent a56296b commit cdc1e36
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 79 deletions.
5 changes: 5 additions & 0 deletions object_storage_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
"time"

"github.com/go-resty/resty/v2"
Expand Down Expand Up @@ -120,6 +121,7 @@ func (c *Client) ListObjectStorageBucketsInCluster(ctx context.Context, opts *Li

// GetObjectStorageBucket gets the ObjectStorageBucket with the provided label
func (c *Client) GetObjectStorageBucket(ctx context.Context, clusterID, label string) (*ObjectStorageBucket, error) {
label = url.PathEscape(label)
e := fmt.Sprintf("object-storage/buckets/%s/%s", clusterID, label)
req := c.R(ctx).SetResult(&ObjectStorageBucket{})
r, err := coupleAPIErrors(req.Get(e))
Expand Down Expand Up @@ -147,6 +149,7 @@ func (c *Client) CreateObjectStorageBucket(ctx context.Context, opts ObjectStora

// GetObjectStorageBucketAccess gets the current access config for a bucket
func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterID, label string) (*ObjectStorageBucketAccess, error) {
label = url.PathEscape(label)
e := fmt.Sprintf("object-storage/buckets/%s/%s/access", clusterID, label)
req := c.R(ctx).SetResult(&ObjectStorageBucketAccess{})
r, err := coupleAPIErrors(req.Get(e))
Expand All @@ -164,6 +167,7 @@ func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterID,
return err
}

label = url.PathEscape(label)
e := fmt.Sprintf("object-storage/buckets/%s/%s/access", clusterID, label)
_, err = coupleAPIErrors(c.R(ctx).SetBody(string(body)).Post(e))
if err != nil {
Expand All @@ -175,6 +179,7 @@ func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterID,

// DeleteObjectStorageBucket deletes the ObjectStorageBucket with the specified label
func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterID, label string) error {
label = url.PathEscape(label)
e := fmt.Sprintf("object-storage/buckets/%s/%s", clusterID, label)
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
return err
Expand Down
4 changes: 4 additions & 0 deletions object_storage_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
)

type ObjectStorageObjectURLCreateOptions struct {
Expand Down Expand Up @@ -35,13 +36,15 @@ func (c *Client) CreateObjectStorageObjectURL(ctx context.Context, objectID, lab
return nil, err
}

label = url.PathEscape(label)
e := fmt.Sprintf("object-storage/buckets/%s/%s/object-url", objectID, label)
req := c.R(ctx).SetResult(&ObjectStorageObjectURL{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Post(e))
return r.Result().(*ObjectStorageObjectURL), err
}

func (c *Client) GetObjectStorageObjectACLConfig(ctx context.Context, objectID, label, object string) (*ObjectStorageObjectACLConfig, error) {
label = url.PathEscape(label)
e := fmt.Sprintf("object-storage/buckets/%s/%s/object-acl?name=%s", objectID, label, object)
req := c.R(ctx).SetResult(&ObjectStorageObjectACLConfig{})
r, err := coupleAPIErrors(req.Get(e))
Expand All @@ -54,6 +57,7 @@ func (c *Client) UpdateObjectStorageObjectACLConfig(ctx context.Context, objectI
return nil, err
}

label = url.PathEscape(label)
e := fmt.Sprintf("object-storage/buckets/%s/%s/object-acl", objectID, label)
req := c.R(ctx).SetResult(&ObjectStorageObjectACLConfig{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Put(e))
Expand Down
3 changes: 3 additions & 0 deletions tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"

"github.com/go-resty/resty/v2"
)
Expand Down Expand Up @@ -147,6 +148,7 @@ func (i *TaggedObject) fixData() (*TaggedObject, error) {
// ListTaggedObjects lists Tagged Objects
func (c *Client) ListTaggedObjects(ctx context.Context, label string, opts *ListOptions) (TaggedObjectList, error) {
response := TaggedObjectsPagedResponse{}
label = url.PathEscape(label)
err := c.listHelper(ctx, &response, opts, label)
if err != nil {
return nil, err
Expand Down Expand Up @@ -219,6 +221,7 @@ func (c *Client) CreateTag(ctx context.Context, opts TagCreateOptions) (*Tag, er

// DeleteTag deletes the Tag with the specified id
func (c *Client) DeleteTag(ctx context.Context, label string) error {
label = url.PathEscape(label)
e := fmt.Sprintf("tags/%s", label)
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/access
method: GET
response:
body: '{"acl": "authenticated-read", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Owner><AccessControlList><Grant><Grantee
body: '{"acl": "authenticated-read", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Owner><AccessControlList><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"Group\"><URI>http://acs.amazonaws.com/groups/global/AuthenticatedUsers</URI></Grantee><Permission>READ</Permission></Grant><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>",
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>",
"cors_enabled": false, "cors_xml": null}'
headers:
Access-Control-Allow-Credentials:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/access
method: GET
response:
body: '{"acl": "private", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Owner><AccessControlList><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>",
body: '{"acl": "private", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Owner><AccessControlList><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>",
"cors_enabled": false, "cors_xml": null}'
headers:
Access-Control-Allow-Credentials:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ interactions:
body: ""
form: {}
headers: {}
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=L41EAtaiqaDrjNdOcA7ubkWG03k%3D&Expires=1665425931&AWSAccessKeyID=SANITIZED
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=IdxQQkAugjpkQaXy6oLtekSeJGU%3D&Expires=1679683246&AWSAccessKeyID=SANITIZED
method: DELETE
response:
body: ""
headers:
Connection:
- keep-alive
X-Amz-Request-Id:
- tx00000b5bf50aeef99a733-00634460a3-3e40a753-default
- tx000000ec506611737cbd6-00641ded47-40fa2286-default
status: 204 No Content
code: 204
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
headers:
Content-Type:
- text/plain
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=3geZra6WVkB26O%2FV8W4ukrJabqM%3D&Expires=1665425929&AWSAccessKeyID=SANITIZED
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=M4GM6gGRUcDpffPBEO27YY1G6DA%3D&Expires=1679683243&AWSAccessKeyID=SANITIZED
method: PUT
response:
body: ""
Expand All @@ -21,7 +21,7 @@ interactions:
Etag:
- '"7f2ababa423061c509f4923dd04b6cf1"'
X-Amz-Request-Id:
- tx00000c10a60d11c8e45e9-00634460a1-3e40d5c2-default
- tx0000019f3abcb31592798-00641ded44-40f62f66-default
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"name":"test","method":"PUT","content_type":"text/plain","content_disposition":"","expires_in":360}'
body: '{"name":"test","method":"PUT","content_type":"text/plain","expires_in":360}'
form: {}
headers:
Accept:
Expand All @@ -71,7 +71,7 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/object-url
method: POST
response:
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=3geZra6WVkB26O%2FV8W4ukrJabqM%3D&Expires=1665425929&AWSAccessKeyID=SANITIZED",
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=M4GM6gGRUcDpffPBEO27YY1G6DA%3D&Expires=1679683243&AWSAccessKeyID=SANITIZED",
"exists": false}'
headers:
Access-Control-Allow-Credentials:
Expand All @@ -87,7 +87,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "189"
- "187"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand Down Expand Up @@ -127,8 +127,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/object-acl?name=test
method: GET
response:
body: '{"acl": "private", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Owner><AccessControlList><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"}'
body: '{"acl": "private", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Owner><AccessControlList><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down Expand Up @@ -240,9 +240,9 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/object-acl?name=test
method: GET
response:
body: '{"acl": "public-read", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Owner><AccessControlList><Grant><Grantee
body: '{"acl": "public-read", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Owner><AccessControlList><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"Group\"><URI>http://acs.amazonaws.com/groups/global/AllUsers</URI></Grantee><Permission>READ</Permission></Grant><Grant><Grantee
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>247335f1-a59c-4323-8805-d64c5770d936</ID><DisplayName>247335f1-a59c-4323-8805-d64c5770d936</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"}'
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>fa25bc43-2cb0-43c7-b8bd-994243d8a697</ID><DisplayName>fa25bc43-2cb0-43c7-b8bd-994243d8a697</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down Expand Up @@ -287,7 +287,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"name":"test","method":"DELETE","content_type":"","content_disposition":"","expires_in":360}'
body: '{"name":"test","method":"DELETE","expires_in":360}'
form: {}
headers:
Accept:
Expand All @@ -299,7 +299,7 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/object-url
method: POST
response:
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=L41EAtaiqaDrjNdOcA7ubkWG03k%3D&Expires=1665425931&AWSAccessKeyID=SANITIZED",
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=IdxQQkAugjpkQaXy6oLtekSeJGU%3D&Expires=1679683246&AWSAccessKeyID=SANITIZED",
"exists": true}'
headers:
Access-Control-Allow-Credentials:
Expand Down
Loading

0 comments on commit cdc1e36

Please sign in to comment.