Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions provider/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
cloudflarev0 "github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/cloudflare-go/v5"
"github.com/cloudflare/cloudflare-go/v5/addressing"
"github.com/cloudflare/cloudflare-go/v5/custom_hostnames"
"github.com/cloudflare/cloudflare-go/v5/dns"
"github.com/cloudflare/cloudflare-go/v5/option"
"github.com/cloudflare/cloudflare-go/v5/zones"
Expand Down Expand Up @@ -124,7 +125,7 @@ type cloudFlareDNS interface {
UpdateDataLocalizationRegionalHostname(ctx context.Context, hostname string, params addressing.RegionalHostnameEditParams) error
DeleteDataLocalizationRegionalHostname(ctx context.Context, hostname string, params addressing.RegionalHostnameDeleteParams) error
CustomHostnames(ctx context.Context, zoneID string, page int, filter cloudflarev0.CustomHostname) ([]cloudflarev0.CustomHostname, cloudflarev0.ResultInfo, error)
DeleteCustomHostname(ctx context.Context, zoneID string, customHostnameID string) error
DeleteCustomHostname(ctx context.Context, customHostnameID string, params custom_hostnames.CustomHostnameDeleteParams) error
CreateCustomHostname(ctx context.Context, zoneID string, ch cloudflarev0.CustomHostname) (*cloudflarev0.CustomHostnameResponse, error)
}

Expand Down Expand Up @@ -182,8 +183,9 @@ func (z zoneService) CustomHostnames(ctx context.Context, zoneID string, page in
return z.serviceV0.CustomHostnames(ctx, zoneID, page, filter)
}

func (z zoneService) DeleteCustomHostname(ctx context.Context, zoneID string, customHostnameID string) error {
return z.serviceV0.DeleteCustomHostname(ctx, zoneID, customHostnameID)
func (z zoneService) DeleteCustomHostname(ctx context.Context, customHostnameID string, params custom_hostnames.CustomHostnameDeleteParams) error {
_, err := z.service.CustomHostnames.Delete(ctx, customHostnameID, params)
return err
}

func (z zoneService) CreateCustomHostname(ctx context.Context, zoneID string, ch cloudflarev0.CustomHostname) (*cloudflarev0.CustomHostnameResponse, error) {
Expand Down Expand Up @@ -552,7 +554,8 @@ func (p *CloudFlareProvider) submitCustomHostnameChanges(ctx context.Context, zo
prevChID := prevCh.ID
if prevChID != "" {
log.WithFields(logFields).Infof("Removing previous custom hostname %q/%q", prevChID, changeCH)
chErr := p.Client.DeleteCustomHostname(ctx, zoneID, prevChID)
params := custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F(zoneID)}
chErr := p.Client.DeleteCustomHostname(ctx, prevChID, params)
if chErr != nil {
failedChange = true
log.WithFields(logFields).Errorf("failed to remove previous custom hostname %q/%q: %v", prevChID, changeCH, chErr)
Expand All @@ -575,7 +578,8 @@ func (p *CloudFlareProvider) submitCustomHostnameChanges(ctx context.Context, zo
log.WithFields(logFields).Infof("Deleting custom hostname %q", changeCH.Hostname)
if ch, err := getCustomHostname(chs, changeCH.Hostname); err == nil {
chID := ch.ID
chErr := p.Client.DeleteCustomHostname(ctx, zoneID, chID)
params := custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F(zoneID)}
chErr := p.Client.DeleteCustomHostname(ctx, chID, params)
if chErr != nil {
failedChange = true
log.WithFields(logFields).Errorf("failed to delete custom hostname %q/%q: %v", chID, changeCH.Hostname, chErr)
Expand Down
9 changes: 6 additions & 3 deletions provider/cloudflare/cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

cloudflarev0 "github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/cloudflare-go/v5"
"github.com/cloudflare/cloudflare-go/v5/custom_hostnames"
"github.com/cloudflare/cloudflare-go/v5/dns"
"github.com/cloudflare/cloudflare-go/v5/zones"
"github.com/maxatome/go-testdeep/td"
Expand Down Expand Up @@ -351,7 +352,8 @@ func (m *mockCloudFlareClient) CustomHostnames(ctx context.Context, zoneID strin
for idx := (page - 1) * perPage; idx < min(len(chs), page*perPage); idx++ {
ch := m.customHostnames[zoneID][idx]
if strings.HasPrefix(ch.Hostname, "newerror-list-") {
m.DeleteCustomHostname(ctx, zoneID, ch.ID)
params := custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F(zoneID)}
m.DeleteCustomHostname(ctx, ch.ID, params)
return nil, cloudflarev0.ResultInfo{}, errors.New("failed to list erroring custom hostname")
}
result = append(result, ch)
Expand Down Expand Up @@ -389,7 +391,8 @@ func (m *mockCloudFlareClient) CreateCustomHostname(ctx context.Context, zoneID
return &cloudflarev0.CustomHostnameResponse{}, nil
}

func (m *mockCloudFlareClient) DeleteCustomHostname(ctx context.Context, zoneID string, customHostnameID string) error {
func (m *mockCloudFlareClient) DeleteCustomHostname(ctx context.Context, customHostnameID string, params custom_hostnames.CustomHostnameDeleteParams) error {
zoneID := params.ZoneID.String()
idx := 0
if idx = getCustomHostnameIdxByID(m.customHostnames[zoneID], customHostnameID); idx < 0 {
return fmt.Errorf("Invalid custom hostname ID to delete")
Expand Down Expand Up @@ -3605,7 +3608,7 @@ func TestZoneService(t *testing.T) {

t.Run("DeleteCustomHostname", func(t *testing.T) {
t.Parallel()
err := client.DeleteCustomHostname(ctx, zoneID, "foo")
err := client.DeleteCustomHostname(ctx, "1234", custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F("foo")})
assert.ErrorIs(t, err, context.Canceled)
})

Expand Down
Loading