Skip to content

Commit

Permalink
feat: Refactor ListSecrets method in GCP provider to handle paginatio…
Browse files Browse the repository at this point in the history
…n and limit the number of secrets
  • Loading branch information
h0n9 committed May 2, 2024
1 parent 59a4870 commit b5a2a9c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions provider/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (provider *GCP) Close() error {
func (provider *GCP) ListSecrets(limit int) ([]string, error) {
req := &secretmanagerpb.ListSecretsRequest{}
var secrets []string

secretsIterator := provider.client.ListSecrets(provider.ctx, req)
for {
// get next secret
Expand All @@ -39,15 +40,16 @@ func (provider *GCP) ListSecrets(limit int) ([]string, error) {
break
}

// append secret name
secrets = append(secrets, resp.GetName())

// break if reached the limit
if len(secrets) >= limit {
break
}

// append secret name
secrets = append(secrets, resp.GetName())
}
return secrets, nil

return secrets[:limit], nil
}

// The secretID in the format `projects/*/secrets/*/versions/*`.
Expand Down

0 comments on commit b5a2a9c

Please sign in to comment.