Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make object storage requests use value struct #369

Merged
merged 2 commits into from
Mar 10, 2025
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
22 changes: 14 additions & 8 deletions object_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
// ObjectStorageService is the interface to interact with the object storage endpoints on the Vultr API.
// Link : https://www.vultr.com/api/#tag/s3
type ObjectStorageService interface {
Create(ctx context.Context, clusterID int, label string) (*ObjectStorage, *http.Response, error)
Create(ctx context.Context, objReq *ObjectStorageReq) (*ObjectStorage, *http.Response, error)
Get(ctx context.Context, id string) (*ObjectStorage, *http.Response, error)
Update(ctx context.Context, id, label string) error
Update(ctx context.Context, id string, objReq *ObjectStorageReq) error
Delete(ctx context.Context, id string) error
List(ctx context.Context, options *ListOptions) ([]ObjectStorage, *Meta, *http.Response, error)

Expand Down Expand Up @@ -41,6 +41,14 @@ type ObjectStorage struct {
S3Keys
}

// ObjectStorageReq represents the parameters for creating and updating object
// storages
type ObjectStorageReq struct {
ClusterID int `json:"cluster_id,omitempty"`
TierID int `json:"tier_id,omitempty"`
Label string `json:"label"`
}

// S3Keys define your api access to your cluster
type S3Keys struct {
S3Hostname string `json:"s3_hostname"`
Expand Down Expand Up @@ -95,11 +103,10 @@ type s3KeysBase struct {
}

// Create an object storage subscription
func (o *ObjectStorageServiceHandler) Create(ctx context.Context, clusterID int, label string) (*ObjectStorage, *http.Response, error) {
func (o *ObjectStorageServiceHandler) Create(ctx context.Context, objReq *ObjectStorageReq) (*ObjectStorage, *http.Response, error) {
uri := "/v2/object-storage"

values := RequestBody{"cluster_id": clusterID, "label": label}
req, err := o.client.NewRequest(ctx, http.MethodPost, uri, values)
req, err := o.client.NewRequest(ctx, http.MethodPost, uri, objReq)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -132,11 +139,10 @@ func (o *ObjectStorageServiceHandler) Get(ctx context.Context, id string) (*Obje
}

// Update a Object Storage Subscription.
func (o *ObjectStorageServiceHandler) Update(ctx context.Context, id, label string) error {
func (o *ObjectStorageServiceHandler) Update(ctx context.Context, id string, objReq *ObjectStorageReq) error {
uri := fmt.Sprintf("/v2/object-storage/%s", id)

value := RequestBody{"label": label}
req, err := o.client.NewRequest(ctx, http.MethodPut, uri, value)
req, err := o.client.NewRequest(ctx, http.MethodPut, uri, objReq)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions object_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestObjectStorageServiceHandler_Create(t *testing.T) {
fmt.Fprint(writer, response)
})

objectStorage, _, err := client.ObjectStorage.Create(ctx, 2, "api-obj-storage2")
objectStorage, _, err := client.ObjectStorage.Create(ctx, &ObjectStorageReq{ClusterID: 2, Label: "api-obj-storage2"})
if err != nil {
t.Errorf("ObjectStorage.Create returned %+v", err)
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestObjectStorageServiceHandler_Update(t *testing.T) {
fmt.Fprint(writer)
})

err := client.ObjectStorage.Update(ctx, "1234", "s3 label")
err := client.ObjectStorage.Update(ctx, "1234", &ObjectStorageReq{Label: "s3 label"})
if err != nil {
t.Errorf("ObjectStorage.Create returned %+v", err)
}
Expand Down
Loading