Skip to content

Commit 4c9518a

Browse files
authored
Make object storage requests use value struct (#369)
* Make object storage requests use value struct * Fix object storage tests
1 parent 982a7b2 commit 4c9518a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

object_storage.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
// ObjectStorageService is the interface to interact with the object storage endpoints on the Vultr API.
1212
// Link : https://www.vultr.com/api/#tag/s3
1313
type ObjectStorageService interface {
14-
Create(ctx context.Context, clusterID int, label string) (*ObjectStorage, *http.Response, error)
14+
Create(ctx context.Context, objReq *ObjectStorageReq) (*ObjectStorage, *http.Response, error)
1515
Get(ctx context.Context, id string) (*ObjectStorage, *http.Response, error)
16-
Update(ctx context.Context, id, label string) error
16+
Update(ctx context.Context, id string, objReq *ObjectStorageReq) error
1717
Delete(ctx context.Context, id string) error
1818
List(ctx context.Context, options *ListOptions) ([]ObjectStorage, *Meta, *http.Response, error)
1919

@@ -41,6 +41,14 @@ type ObjectStorage struct {
4141
S3Keys
4242
}
4343

44+
// ObjectStorageReq represents the parameters for creating and updating object
45+
// storages
46+
type ObjectStorageReq struct {
47+
ClusterID int `json:"cluster_id,omitempty"`
48+
TierID int `json:"tier_id,omitempty"`
49+
Label string `json:"label"`
50+
}
51+
4452
// S3Keys define your api access to your cluster
4553
type S3Keys struct {
4654
S3Hostname string `json:"s3_hostname"`
@@ -95,11 +103,10 @@ type s3KeysBase struct {
95103
}
96104

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

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

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

138-
value := RequestBody{"label": label}
139-
req, err := o.client.NewRequest(ctx, http.MethodPut, uri, value)
145+
req, err := o.client.NewRequest(ctx, http.MethodPut, uri, objReq)
140146
if err != nil {
141147
return err
142148
}

object_storage_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestObjectStorageServiceHandler_Create(t *testing.T) {
1616
fmt.Fprint(writer, response)
1717
})
1818

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

80-
err := client.ObjectStorage.Update(ctx, "1234", "s3 label")
80+
err := client.ObjectStorage.Update(ctx, "1234", &ObjectStorageReq{Label: "s3 label"})
8181
if err != nil {
8282
t.Errorf("ObjectStorage.Create returned %+v", err)
8383
}

0 commit comments

Comments
 (0)