Skip to content

Commit

Permalink
secondary_dns_primary: add support for deleting primaries
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Mar 14, 2021
1 parent 42752d4 commit c8acbf1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions secondary_dns_primaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ func (api *API) UpdateSecondaryDNSPrimary(ctx context.Context, accountID string,
return r.Result, nil
}

// DeleteSecondaryDNSPrimary deletes a secondary DNS primary.
//
// API reference: https://api.cloudflare.com/#secondary-dns-primary--delete-primary
func (api *API) DeleteSecondaryDNSPrimary(ctx context.Context, accountID, primaryID string) error {
uri := fmt.Sprintf("/zones/%s/secondary_dns/primaries/%s", accountID, primaryID)
_, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)

if err != nil {
return err
}

return nil
}

func validateRequiredSecondaryDNSPrimaries(p SecondaryDNSPrimary) error {
if p.IP == "" {
Expand Down
23 changes: 23 additions & 0 deletions secondary_dns_primaries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ func TestUpdateSecondaryDNSPrimary(t *testing.T) {
}
}

func TestDeleteSecondaryDNSPrimary(t *testing.T) {
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, r.Method, http.MethodDelete, "Expected method 'DELETE', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprint(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "23ff594956f20c2a721606e94745a8aa"
}
}
`)
}

mux.HandleFunc("/zones/01a7362d577a6c3019a474fd6f485823/secondary_dns/primaries/23ff594956f20c2a721606e94745a8aa", handler)

err := client.DeleteSecondaryDNSPrimary(context.Background(), "01a7362d577a6c3019a474fd6f485823", "23ff594956f20c2a721606e94745a8aa")
assert.NoError(t, err)
}

func TestValidateRequiredSecondaryDNSPrimaries(t *testing.T) {
p1 := SecondaryDNSPrimary{}
Expand Down

0 comments on commit c8acbf1

Please sign in to comment.