civo / civogo

Golang client to interact with Civo's API
https://www.civo.com/
MIT License
37 stars 23 forks source link

Update `ListObjectStoreCredentials` API Method to Include Page Number and `perPage` value in Request URL #206

Closed Praveen005 closed 3 weeks ago

Praveen005 commented 1 month ago

Description

Currently, the ListObjectStoreCredentials method in civogo retrieves only the first page of bucket credentials due to the request URL not including a configurable page number. This restricts users to only the first 20 credentials (default perPage value) without an option to access additional pages.

Praveen005 commented 1 month ago

Hi @uzaxirr

Following changes are needed to solve the issue civo/cli-#451

I have updated the url like below:

Screenshot 2024-09-10 081219



I have a question, in FindObjectStoreCredential, when querying paginated responses, is it better to retrieve all pages in a loop like this:

var creds []ObjectStoreCredential
page := 1
perPage := 100

for {
    paginatedCreds, err := c.ListObjectStoreCredentials(page, perPage)
    if err != nil {
        return nil, decodeError(err)
    }
    creds = append(creds, paginatedCreds.Items...)
    if page >= paginatedCreds.Pages {
        break
    }
    page++
}

Or should I simply use a large perPage value to fetch the complete result in one request, like this:

ListObjectStoreCredentials(1, 1000)

I noticed a similar case being handled like this:

instances, err := c.ListInstances(1, 99999999)

I am inclined toward the first approach, I feel having a large perPage value can potentially hog the server.

uzaxirr commented 1 month ago

hii @Praveen005 i would prefer you to use the second approach which is ListObjectStoreCredentials(1, 1000) looping is not which i ideally want here.

Or a much much better option would be if we can allow sending page number and page size in the SDK function call itself. and the same can be sent via CLI as well.