From c8acbf193a1ecd675f1556ee3a5af30c0a73cdc0 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Mon, 15 Mar 2021 10:59:57 +1100 Subject: [PATCH] secondary_dns_primary: add support for deleting primaries --- secondary_dns_primaries.go | 13 +++++++++++++ secondary_dns_primaries_test.go | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/secondary_dns_primaries.go b/secondary_dns_primaries.go index 6aeba8b428a..dc0b57a49dd 100644 --- a/secondary_dns_primaries.go +++ b/secondary_dns_primaries.go @@ -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 == "" { diff --git a/secondary_dns_primaries_test.go b/secondary_dns_primaries_test.go index 9f6d5913b39..eea4c80f55e 100644 --- a/secondary_dns_primaries_test.go +++ b/secondary_dns_primaries_test.go @@ -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{}