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

cloudflare: remove all references to api.AccountID #1315

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
7 changes: 7 additions & 0 deletions .changelog/1315.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:breaking-change
cloudflare: remove `api.AccountID` from client struct
```

```release-note:breaking-change
cloudflare: remove `UsingAccount` in favour of resource specific attributes
```
16 changes: 1 addition & 15 deletions cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type API struct {
APIUserServiceKey string
APIToken string
BaseURL string
AccountID string
UserAgent string
headers http.Header
httpClient *http.Client
Expand Down Expand Up @@ -147,7 +146,7 @@ func (api *API) SetAuthType(authType int) {
// ZoneIDByName retrieves a zone's ID from the name.
func (api *API) ZoneIDByName(zoneName string) (string, error) {
zoneName = normalizeZoneName(zoneName)
res, err := api.ListZonesContext(context.Background(), WithZoneFilters(zoneName, api.AccountID, ""))
res, err := api.ListZonesContext(context.Background(), WithZoneFilters(zoneName, "", ""))
if err != nil {
return "", fmt.Errorf("ListZonesContext command failed: %w", err)
}
Expand Down Expand Up @@ -416,19 +415,6 @@ func (api *API) request(ctx context.Context, method, uri string, reqBody io.Read
return resp, nil
}

// Returns the base URL to use for API endpoints that exist for accounts.
// If an account option was used when creating the API instance, returns
// the account URL.
//
// accountBase is the base URL for endpoints referring to the current user.
// It exists as a parameter because it is not consistent across APIs.
func (api *API) userBaseURL(accountBase string) string {
if api.AccountID != "" {
return "/accounts/" + api.AccountID
}
return accountBase
}

// copyHeader copies all headers for `source` and sets them on `target`.
// based on https://godoc.org/github.com/golang/gddo/httputil/header#Copy
func copyHeader(target, source http.Header) {
Expand Down
2 changes: 1 addition & 1 deletion cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func TestZoneIDByNameWithNonUniqueZonesWithoutOrgID(t *testing.T) {
}

func TestZoneIDByNameWithIDN(t *testing.T) {
setup(UsingAccount("01a7362d577a6c3019a474fd6f485823"))
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 0 additions & 4 deletions cmd/flarectl/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ func initializeAPI(c *cli.Context) error {
return err
}

if c.IsSet("account-id") {
cloudflare.UsingAccount(c.String("account-id"))(api) // nolint
}

return nil
}

Expand Down
11 changes: 0 additions & 11 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ func Headers(headers http.Header) Option {
}
}

// UsingAccount allows you to apply account-level changes (Load Balancing,
// Railguns) to an account instead.
//
// Deprecated: Resources should define the `AccountID` parameter explicitly.
func UsingAccount(accountID string) Option {
return func(api *API) error {
api.AccountID = accountID
return nil
}
}

// UsingRateLimit applies a non-default rate limit to client API requests
// If not specified the default of 4rps will be applied.
func UsingRateLimit(rps float64) Option {
Expand Down