Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
Expand Down
75 changes: 12 additions & 63 deletions object_storage_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package linodego

import (
"context"
"encoding/json"
"fmt"

"github.com/go-resty/resty/v2"
)

type ObjectStorageKeyRegion struct {
Expand Down Expand Up @@ -49,83 +45,36 @@ type ObjectStorageKeyUpdateOptions struct {
Regions []string `json:"regions,omitempty"`
}

// ObjectStorageKeysPagedResponse represents a linode API response for listing
type ObjectStorageKeysPagedResponse struct {
*PageOptions
Data []ObjectStorageKey `json:"data"`
}

// endpoint gets the endpoint URL for Object Storage keys
func (ObjectStorageKeysPagedResponse) endpoint(_ ...any) string {
return "object-storage/keys"
}

func (resp *ObjectStorageKeysPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(ObjectStorageKeysPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*ObjectStorageKeysPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}

// ListObjectStorageKeys lists ObjectStorageKeys
func (c *Client) ListObjectStorageKeys(ctx context.Context, opts *ListOptions) ([]ObjectStorageKey, error) {
response := ObjectStorageKeysPagedResponse{}
err := c.listHelper(ctx, &response, opts)
if err != nil {
return nil, err
}
return response.Data, nil
response, err := getPaginatedResults[ObjectStorageKey](ctx, c, "object-storage/keys", opts)
return response, err
}

// CreateObjectStorageKey creates a ObjectStorageKey
func (c *Client) CreateObjectStorageKey(ctx context.Context, opts ObjectStorageKeyCreateOptions) (*ObjectStorageKey, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, NewError(err)
}

e := "object-storage/keys"
req := c.R(ctx).SetResult(&ObjectStorageKey{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Post(e))
if err != nil {
return nil, err
}
return r.Result().(*ObjectStorageKey), nil
response, err := doPOSTRequest[ObjectStorageKey](ctx, c, e, opts)
return response, err
}

// GetObjectStorageKey gets the object storage key with the provided ID
func (c *Client) GetObjectStorageKey(ctx context.Context, keyID int) (*ObjectStorageKey, error) {
e := fmt.Sprintf("object-storage/keys/%d", keyID)
req := c.R(ctx).SetResult(&ObjectStorageKey{})
r, err := coupleAPIErrors(req.Get(e))
if err != nil {
return nil, err
}
return r.Result().(*ObjectStorageKey), nil
e := formatAPIPath("object-storage/keys/%d", keyID)
response, err := doGETRequest[ObjectStorageKey](ctx, c, e)
return response, err
}

// UpdateObjectStorageKey updates the object storage key with the specified id
func (c *Client) UpdateObjectStorageKey(ctx context.Context, keyID int, opts ObjectStorageKeyUpdateOptions) (*ObjectStorageKey, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}

e := fmt.Sprintf("object-storage/keys/%d", keyID)
req := c.R(ctx).SetResult(&ObjectStorageKey{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Put(e))
if err != nil {
return nil, err
}
return r.Result().(*ObjectStorageKey), nil
e := formatAPIPath("object-storage/keys/%d", keyID)
response, err := doPUTRequest[ObjectStorageKey](ctx, c, e, opts)
return response, err
}

// DeleteObjectStorageKey deletes the ObjectStorageKey with the specified id
func (c *Client) DeleteObjectStorageKey(ctx context.Context, keyID int) error {
e := fmt.Sprintf("object-storage/keys/%d", keyID)
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
e := formatAPIPath("object-storage/keys/%d", keyID)
err := doDELETERequest(ctx, c, e)
return err
}
43 changes: 9 additions & 34 deletions object_storage_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package linodego

import (
"context"
"encoding/json"
"fmt"
"net/url"
)

type ObjectStorageObjectURLCreateOptions struct {
Expand All @@ -31,41 +28,19 @@ type ObjectStorageObjectACLConfigUpdateOptions struct {
}

func (c *Client) CreateObjectStorageObjectURL(ctx context.Context, objectID, label string, opts ObjectStorageObjectURLCreateOptions) (*ObjectStorageObjectURL, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}

label = url.PathEscape(label)
objectID = url.PathEscape(objectID)
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
e := formatAPIPath("object-storage/buckets/%s/%s/object-url", objectID, label)
response, err := doPOSTRequest[ObjectStorageObjectURL](ctx, c, e, opts)
return response, err
}

func (c *Client) GetObjectStorageObjectACLConfig(ctx context.Context, objectID, label, object string) (*ObjectStorageObjectACLConfig, error) {
label = url.PathEscape(label)
object = url.QueryEscape(object)
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))
return r.Result().(*ObjectStorageObjectACLConfig), err
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl?name=%s", objectID, label, object)
response, err := doGETRequest[ObjectStorageObjectACLConfig](ctx, c, e)
return response, err
}

func (c *Client) UpdateObjectStorageObjectACLConfig(ctx context.Context, objectID, label string, opts ObjectStorageObjectACLConfigUpdateOptions) (*ObjectStorageObjectACLConfig, error) {
body, err := json.Marshal(opts)
if err != nil {
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))
if err != nil {
return nil, err
}

return r.Result().(*ObjectStorageObjectACLConfig), err
e := formatAPIPath("object-storage/buckets/%s/%s/object-acl", objectID, label)
response, err := doPUTRequest[ObjectStorageObjectACLConfig](ctx, c, e, opts)
return response, err
}
12 changes: 12 additions & 0 deletions paged_response_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type NotificationsPagedResponse legacyPagedResponse[Notification]
// Deprecated: OAuthClientsPagedResponse exists for historical compatibility and should not be used.
type OAuthClientsPagedResponse legacyPagedResponse[OAuthClient]

// Deprecated: ObjectStorageKeysPagedResponse exists for historical compatibility and should not be used.
type ObjectStorageKeysPagedResponse legacyPagedResponse[ObjectStorageKey]

// Deprecated: ObjectStorageBucketsPagedResponse exists for historical compatibility and should not be used.
type ObjectStorageBucketsPagedResponse legacyPagedResponse[ObjectStorageBucket]

Expand All @@ -127,6 +130,15 @@ type ObjectStorageClustersPagedResponse legacyPagedResponse[ObjectStorageCluster
// Deprecated: PaymentsPagedResponse exists for historical compatibility and should not be used.
type PaymentsPagedResponse legacyPagedResponse[Payment]

// Deprecated: PostgresDatabasesPagedResponse exists for historical compatibility and should not be used.
type PostgresDatabasesPagedResponse legacyPagedResponse[PostgresDatabase]

// Deprecated: PostgresDatabaseBackupsPagedResponse exists for historical compatibility and should not be used.
type PostgresDatabaseBackupsPagedResponse legacyPagedResponse[PostgresDatabaseBackup]

// Deprecated: ProfileLoginsPagedResponse exists for historical compatibility and should not be used.
type ProfileLoginsPagedResponse legacyPagedResponse[ProfileLogin]

// Deprecated: UsersPagedResponse exists for historical compatibility and should not be used.
type UsersPagedResponse legacyPagedResponse[User]

Expand Down
Loading