Skip to content

Commit

Permalink
Merge pull request #207 from Praveen005/fix206
Browse files Browse the repository at this point in the history
enhance: add `page` and `perPage` parameters to `ListObjectStoreCredentials` request URL
  • Loading branch information
uzaxirr authored Sep 23, 2024
2 parents d986a7a + 173ab6e commit f5f607f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions objectstore_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ type UpdateObjectStoreCredentialRequest struct {
}

// ListObjectStoreCredentials returns all object store credentials in that specific region
func (c *Client) ListObjectStoreCredentials() (*PaginatedObjectStoreCredentials, error) {
resp, err := c.SendGetRequest("/v2/objectstore/credentials")
func (c *Client) ListObjectStoreCredentials(page, perPage int) (*PaginatedObjectStoreCredentials, error) {
url := "/v2/objectstore/credentials"
if page != 0 && perPage != 0 {
url = url + fmt.Sprintf("?page=%d&per_page=%d", page, perPage)
}

resp, err := c.SendGetRequest(url)
if err != nil {
return nil, decodeError(err)
}
Expand Down Expand Up @@ -75,7 +80,7 @@ func (c *Client) GetObjectStoreCredential(id string) (*ObjectStoreCredential, er

// FindObjectStoreCredential finds an objectstore credential by name or by accesskeyID
func (c *Client) FindObjectStoreCredential(search string) (*ObjectStoreCredential, error) {
creds, err := c.ListObjectStoreCredentials()
creds, err := c.ListObjectStoreCredentials(1, 10000)
if err != nil {
return nil, decodeError(err)
}
Expand Down
10 changes: 5 additions & 5 deletions objectstore_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (

func TestListObjectStoreCredentials(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/objectstore/credentials": `{"page": 1, "per_page": 20, "pages": 2, "items":[{"id": "12345", "name": "test-objectstore-cred"}]}`,
"/v2/objectstore/credentials?page=2&per_page=40": `{"page": 2, "per_page": 40, "pages": 3, "items":[{"id": "12345", "name": "test-objectstore-cred"}]}`,
})
defer server.Close()

got, err := client.ListObjectStoreCredentials()
got, err := client.ListObjectStoreCredentials(2, 40)
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}

expected := &PaginatedObjectStoreCredentials{
Page: 1,
PerPage: 20,
Pages: 2,
Page: 2,
PerPage: 40,
Pages: 3,
Items: []ObjectStoreCredential{
{
ID: "12345",
Expand Down

0 comments on commit f5f607f

Please sign in to comment.