Skip to content

Commit

Permalink
adding object-storage/transfer and /cancel endpoints (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
jriddle-linode authored May 20, 2022
1 parent 13da5e5 commit f8402b0
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 84 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type Client struct {
ObjectStorageBucketCerts *Resource
ObjectStorageClusters *Resource
ObjectStorageKeys *Resource
ObjectStorage *Resource
Payments *Resource
Profile *Resource
Regions *Resource
Expand Down Expand Up @@ -373,6 +374,7 @@ func addResources(client *Client) {
objectStorageBucketCertsName: NewResource(client, objectStorageBucketCertsName, objectStorageBucketCertsEndpoint, true, ObjectStorageBucketCert{}, nil),
objectStorageClustersName: NewResource(client, objectStorageClustersName, objectStorageClustersEndpoint, false, ObjectStorageCluster{}, ObjectStorageClustersPagedResponse{}),
objectStorageKeysName: NewResource(client, objectStorageKeysName, objectStorageKeysEndpoint, false, ObjectStorageKey{}, ObjectStorageKeysPagedResponse{}),
objectStorageName: NewResource(client, objectStorageName, objectStorageEndpoint, false, nil, nil),
paymentsName: NewResource(client, paymentsName, paymentsEndpoint, false, Payment{}, PaymentsPagedResponse{}),
profileName: NewResource(client, profileName, profileEndpoint, false, nil, nil), // really?
regionsName: NewResource(client, regionsName, regionsEndpoint, false, Region{}, RegionsPagedResponse{}),
Expand Down Expand Up @@ -430,6 +432,7 @@ func addResources(client *Client) {
client.ObjectStorageBucketCerts = resources[objectStorageBucketCertsName]
client.ObjectStorageClusters = resources[objectStorageClustersName]
client.ObjectStorageKeys = resources[objectStorageKeysName]
client.ObjectStorage = resources[objectStorageName]
client.Payments = resources[paymentsName]
client.Profile = resources[profileName]
client.Regions = resources[regionsName]
Expand Down
47 changes: 47 additions & 0 deletions object_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package linodego

import (
"context"
"fmt"
)

// ObjectStorageTransfer is an object matching the response of object-storage/transfer
type ObjectStorageTransfer struct {
AmmountUsed int `json:"used"`
}

// CancelObjectStorage cancels and removes all object storage from the Account
func (c *Client) CancelObjectStorage(ctx context.Context) error {
e, err := c.ObjectStorage.Endpoint()
if err != nil {
return err
}

req := c.R(ctx)

e = fmt.Sprintf("%s/cancel", e)
_, err = coupleAPIErrors(req.Post(e))
if err != nil {
return err
}

return nil
}

// GetObjectStorageTransfer returns the amount of outbound data transferred used by the Account
func (c *Client) GetObjectStorageTransfer(ctx context.Context) (*ObjectStorageTransfer, error) {
e, err := c.ObjectStorage.Endpoint()
if err != nil {
return nil, err
}

req := c.R(ctx)

e = fmt.Sprintf("%s/transfer", e)
r, err := coupleAPIErrors(req.SetResult(&ObjectStorageTransfer{}).Get(e))
if err != nil {
return nil, err
}

return r.Result().(*ObjectStorageTransfer), nil
}
2 changes: 2 additions & 0 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
objectStorageBucketCertsName = "objectstoragebucketcerts"
objectStorageClustersName = "objectstorageclusters"
objectStorageKeysName = "objectstoragekeys"
objectStorageName = "objectstorage"
paymentsName = "payments"
profileName = "profile"
regionsName = "regions"
Expand Down Expand Up @@ -114,6 +115,7 @@ const (
objectStorageBucketCertsEndpoint = "object-storage/buckets/{{ .ID }}/{{ .SecondID }}/ssl"
objectStorageClustersEndpoint = "object-storage/clusters"
objectStorageKeysEndpoint = "object-storage/keys"
objectStorageEndpoint = "object-storage"
paymentsEndpoint = "account/payments"
profileEndpoint = "profile"
regionsEndpoint = "regions"
Expand Down
26 changes: 13 additions & 13 deletions test/integration/fixtures/TestAccountEvents_List.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ interactions:
url: https://api.linode.com/v4beta/linode/instances
method: POST
response:
body: '{"id": 36182209, "label": "linodego-test-instance", "group": "", "status":
body: '{"id": 36362372, "label": "linodego-test-instance", "group": "", "status":
"provisioning", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05",
"type": "g6-nanode-1", "ipv4": ["170.187.205.38"], "ipv6": "1234::5678/128",
"type": "g6-nanode-1", "ipv4": ["170.187.203.112"], "ipv6": "1234::5678/128",
"image": "linode/debian9", "region": "us-southeast", "specs": {"disk": 25600,
"memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000}, "alerts": {"cpu":
90, "network_in": 10, "network_out": 10, "transfer_quota": 80, "io": 10000},
Expand All @@ -36,7 +36,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "644"
- "645"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand Down Expand Up @@ -64,7 +64,7 @@ interactions:
code: 200
duration: ""
- request:
body: '{"label":"linodego-test-config-12","devices":{},"interfaces":null}'
body: '{"label":"linodego-test-config-30","devices":{},"interfaces":null}'
form: {}
headers:
Accept:
Expand All @@ -73,10 +73,10 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/36182209/configs
url: https://api.linode.com/v4beta/linode/instances/36362372/configs
method: POST
response:
body: '{"id": 38517743, "label": "linodego-test-config-12", "helpers": {"updatedb_disabled":
body: '{"id": 38712880, "label": "linodego-test-config-30", "helpers": {"updatedb_disabled":
true, "distro": true, "modules_dep": true, "network": true, "devtmpfs_automount":
true}, "kernel": "linode/latest-64bit", "comments": "", "memory_limit": 0, "created":
"2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "root_device": "/dev/sda",
Expand Down Expand Up @@ -135,17 +135,17 @@ interactions:
User-Agent:
- linodego/dev https://github.com/linode/linodego
X-Filter:
- '{"action":"linode_config_create","entity.id":36182209,"entity.type":"linode"}'
- '{"action":"linode_config_create","entity.id":36362372,"entity.type":"linode"}'
url: https://api.linode.com/v4beta/account/events
method: GET
response:
body: '{"data": [{"id": 305731382, "created": "2018-01-02T03:04:05", "seen": false,
body: '{"data": [{"id": 310881385, "created": "2018-01-02T03:04:05", "seen": false,
"read": false, "percent_complete": null, "time_remaining": null, "rate": null,
"duration": null, "action": "linode_config_create", "username": "jriddle-dev",
"entity": {"label": "linodego-test-instance", "id": 36182209, "type": "linode",
"url": "/v4/linode/instances/36182209"}, "status": "notification", "secondary_entity":
{"id": 38517743, "type": "linode_config", "label": "linodego-test-config-12",
"url": "/v4/linode/instances/36182209/configs/38517743"}, "message": ""}], "page":
"entity": {"label": "linodego-test-instance", "id": 36362372, "type": "linode",
"url": "/v4/linode/instances/36362372"}, "status": "notification", "secondary_entity":
{"id": 38712880, "type": "linode_config", "label": "linodego-test-config-30",
"url": "/v4/linode/instances/36362372/configs/38712880"}, "message": ""}], "page":
1, "pages": 1, "results": 1}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -200,7 +200,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/36182209
url: https://api.linode.com/v4beta/linode/instances/36362372
method: DELETE
response:
body: '{}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1651626250325124704","acl":"authenticated-read","cors_enabled":false}'
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1652723978403166804","acl":"authenticated-read","cors_enabled":false}'
form: {}
headers:
Accept:
Expand All @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets
method: POST
response:
body: '{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,7 +68,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704/access
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804/access
method: GET
response:
body: '{"acl": "authenticated-read", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>ee86d510-a82a-4fad-8850-ac239eb1bec2</ID><DisplayName>ee86d510-a82a-4fad-8850-ac239eb1bec2</DisplayName></Owner><AccessControlList><Grant><Grantee
Expand Down Expand Up @@ -128,7 +128,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804
method: DELETE
response:
body: '{}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1651626250325124704"}'
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1652723978403166804"}'
form: {}
headers:
Accept:
Expand All @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets
method: POST
response:
body: '{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,7 +68,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704/access
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804/access
method: POST
response:
body: '{}'
Expand Down Expand Up @@ -123,7 +123,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704/access
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804/access
method: GET
response:
body: '{"acl": "private", "acl_xml": "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>ee86d510-a82a-4fad-8850-ac239eb1bec2</ID><DisplayName>ee86d510-a82a-4fad-8850-ac239eb1bec2</DisplayName></Owner><AccessControlList><Grant><Grantee
Expand Down Expand Up @@ -182,7 +182,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804
method: DELETE
response:
body: '{}'
Expand Down
8 changes: 4 additions & 4 deletions test/integration/fixtures/TestObjectStorageBucket_Create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1651626250325124704"}'
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1652723978403166804"}'
form: {}
headers:
Accept:
Expand All @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets
method: POST
response:
body: '{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,7 +68,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804
method: DELETE
response:
body: '{}'
Expand Down
14 changes: 7 additions & 7 deletions test/integration/fixtures/TestObjectStorageBucket_GetFound.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1651626250325124704"}'
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1652723978403166804"}'
form: {}
headers:
Accept:
Expand All @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets
method: POST
response:
body: '{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,11 +68,11 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804
method: GET
response:
body: '{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -127,7 +127,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804
method: DELETE
response:
body: '{}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1651626250325124704"}'
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1652723978403166804"}'
form: {}
headers:
Accept:
Expand All @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets
method: POST
response:
body: '{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,7 +68,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-west-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-west-1/linodego-test-bucket-1652723978403166804
method: GET
response:
body: '{"errors": [{"reason": "Not found"}]}'
Expand Down Expand Up @@ -110,7 +110,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804
method: DELETE
response:
body: '{}'
Expand Down
12 changes: 6 additions & 6 deletions test/integration/fixtures/TestObjectStorageBuckets_List.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1651626250325124704"}'
body: '{"cluster":"us-east-1","label":"linodego-test-bucket-1652723978403166804"}'
form: {}
headers:
Accept:
Expand All @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets
method: POST
response:
body: '{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -71,8 +71,8 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets
method: GET
response:
body: '{"page": 1, "pages": 1, "results": 1, "data": [{"hostname": "linodego-test-bucket-1651626250325124704.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1651626250325124704", "created": "2018-01-02T03:04:05",
body: '{"page": 1, "pages": 1, "results": 1, "data": [{"hostname": "linodego-test-bucket-1652723978403166804.us-east-1.linodeobjects.com",
"label": "linodego-test-bucket-1652723978403166804", "created": "2018-01-02T03:04:05",
"cluster": "us-east-1", "size": 0, "objects": 0}]}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -127,7 +127,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1651626250325124704
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/linodego-test-bucket-1652723978403166804
method: DELETE
response:
body: '{}'
Expand Down
Loading

0 comments on commit f8402b0

Please sign in to comment.