Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accounts: allow filtering by name for Accounts #899

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions accounts.go
Expand Up @@ -48,13 +48,20 @@ type AccountDetailResponse struct {
Result Account `json:"result"`
}

// AccountsListParams holds the filterable options for Accounts.
type AccountsListParams struct {
Name string `url:"name"`

PaginationOptions
}

// Accounts returns all accounts the logged in user has access to.
//
// API reference: https://api.cloudflare.com/#accounts-list-accounts
func (api *API) Accounts(ctx context.Context, pageOpts PaginationOptions) ([]Account, ResultInfo, error) {
func (api *API) Accounts(ctx context.Context, params AccountsListParams) ([]Account, ResultInfo, error) {
uri := "/accounts"

v, _ := query.Values(pageOpts)
v, _ := query.Values(params)
queryParams := v.Encode()
if queryParams != "" {
queryParams = "?" + queryParams
Expand Down
2 changes: 1 addition & 1 deletion accounts_test.go
Expand Up @@ -57,7 +57,7 @@ func TestAccounts(t *testing.T) {
mux.HandleFunc("/accounts", handler)
want := []Account{expectedAccountStruct}

actual, _, err := client.Accounts(context.Background(), PaginationOptions{})
actual, _, err := client.Accounts(context.Background(), AccountsListParams{})

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down
4 changes: 2 additions & 2 deletions cmd/flarectl/firewall.go
Expand Up @@ -316,8 +316,8 @@ func getScope(c *cli.Context) (string, string, error) {
var account, accountID string
if c.String("account") != "" {
account = c.String("account")
pageOpts := cloudflare.PaginationOptions{}
accounts, _, err := api.Accounts(context.Background(), pageOpts)
params := cloudflare.AccountsListParams{}
accounts, _, err := api.Accounts(context.Background(), params)
if err != nil {
fmt.Println(err)
return "", "", err
Expand Down