Skip to content

Commit

Permalink
Merge pull request #471 from Praveen005/fix451
Browse files Browse the repository at this point in the history
fix(bucket-credentials): handle pagination to list all credentials
  • Loading branch information
uzaxirr authored Sep 24, 2024
2 parents ffeb531 + 6d4dcae commit bd54e5e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
22 changes: 17 additions & 5 deletions cmd/objectstore/objectstore_credential_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package objectstore
import (
"os"

"github.com/civo/civogo"
"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
Expand All @@ -27,14 +28,25 @@ var objectStoreCredentialListCmd = &cobra.Command{
client.Region = common.RegionSet
}

creds, err := client.ListObjectStoreCredentials()
if err != nil {
utility.Error("%s", err)
os.Exit(1)
var creds []civogo.ObjectStoreCredential
page := 1
perPage := 100

for {
paginatedCreds, err := client.ListObjectStoreCredentials(page, perPage)
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}
creds = append(creds, paginatedCreds.Items...)
if page >= paginatedCreds.Pages {
break
}
page++
}

ow := utility.NewOutputWriter()
for _, credential := range creds.Items {
for _, credential := range creds {
ow.StartLine()
ow.AppendDataWithLabel("name", credential.Name, "Name")
ow.AppendDataWithLabel("access_key", credential.AccessKeyID, "Access Key")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/briandowns/spinner v1.11.1
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c // indirect
github.com/civo/civogo v0.3.77
github.com/civo/civogo v0.3.79
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c/go.mod h1:Ie6SubJv
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/civo/civogo v0.3.77 h1:1rl5cpQruPhh+w8BBMpGQsaovjDvA44udPoDTAa45rk=
github.com/civo/civogo v0.3.77/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
github.com/civo/civogo v0.3.79 h1:Z1MbEG9CsGqSZV7UFBA0xsjk7TBGUPHjW9sM7cS5yZM=
github.com/civo/civogo v0.3.79/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down

0 comments on commit bd54e5e

Please sign in to comment.