Skip to content

Commit 4ac0410

Browse files
authored
chore(cloudflare): migrate DeleteCustomHostname() to new lib (kubernetes-sigs#5880)
1 parent 85b6a6e commit 4ac0410

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

provider/cloudflare/cloudflare.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
cloudflarev0 "github.com/cloudflare/cloudflare-go"
3232
"github.com/cloudflare/cloudflare-go/v5"
3333
"github.com/cloudflare/cloudflare-go/v5/addressing"
34+
"github.com/cloudflare/cloudflare-go/v5/custom_hostnames"
3435
"github.com/cloudflare/cloudflare-go/v5/dns"
3536
"github.com/cloudflare/cloudflare-go/v5/option"
3637
"github.com/cloudflare/cloudflare-go/v5/zones"
@@ -124,7 +125,7 @@ type cloudFlareDNS interface {
124125
UpdateDataLocalizationRegionalHostname(ctx context.Context, hostname string, params addressing.RegionalHostnameEditParams) error
125126
DeleteDataLocalizationRegionalHostname(ctx context.Context, hostname string, params addressing.RegionalHostnameDeleteParams) error
126127
CustomHostnames(ctx context.Context, zoneID string, page int, filter cloudflarev0.CustomHostname) ([]cloudflarev0.CustomHostname, cloudflarev0.ResultInfo, error)
127-
DeleteCustomHostname(ctx context.Context, zoneID string, customHostnameID string) error
128+
DeleteCustomHostname(ctx context.Context, customHostnameID string, params custom_hostnames.CustomHostnameDeleteParams) error
128129
CreateCustomHostname(ctx context.Context, zoneID string, ch cloudflarev0.CustomHostname) (*cloudflarev0.CustomHostnameResponse, error)
129130
}
130131

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

185-
func (z zoneService) DeleteCustomHostname(ctx context.Context, zoneID string, customHostnameID string) error {
186-
return z.serviceV0.DeleteCustomHostname(ctx, zoneID, customHostnameID)
186+
func (z zoneService) DeleteCustomHostname(ctx context.Context, customHostnameID string, params custom_hostnames.CustomHostnameDeleteParams) error {
187+
_, err := z.service.CustomHostnames.Delete(ctx, customHostnameID, params)
188+
return err
187189
}
188190

189191
func (z zoneService) CreateCustomHostname(ctx context.Context, zoneID string, ch cloudflarev0.CustomHostname) (*cloudflarev0.CustomHostnameResponse, error) {
@@ -552,7 +554,8 @@ func (p *CloudFlareProvider) submitCustomHostnameChanges(ctx context.Context, zo
552554
prevChID := prevCh.ID
553555
if prevChID != "" {
554556
log.WithFields(logFields).Infof("Removing previous custom hostname %q/%q", prevChID, changeCH)
555-
chErr := p.Client.DeleteCustomHostname(ctx, zoneID, prevChID)
557+
params := custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F(zoneID)}
558+
chErr := p.Client.DeleteCustomHostname(ctx, prevChID, params)
556559
if chErr != nil {
557560
failedChange = true
558561
log.WithFields(logFields).Errorf("failed to remove previous custom hostname %q/%q: %v", prevChID, changeCH, chErr)
@@ -575,7 +578,8 @@ func (p *CloudFlareProvider) submitCustomHostnameChanges(ctx context.Context, zo
575578
log.WithFields(logFields).Infof("Deleting custom hostname %q", changeCH.Hostname)
576579
if ch, err := getCustomHostname(chs, changeCH.Hostname); err == nil {
577580
chID := ch.ID
578-
chErr := p.Client.DeleteCustomHostname(ctx, zoneID, chID)
581+
params := custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F(zoneID)}
582+
chErr := p.Client.DeleteCustomHostname(ctx, chID, params)
579583
if chErr != nil {
580584
failedChange = true
581585
log.WithFields(logFields).Errorf("failed to delete custom hostname %q/%q: %v", chID, changeCH.Hostname, chErr)

provider/cloudflare/cloudflare_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
cloudflarev0 "github.com/cloudflare/cloudflare-go"
3030
"github.com/cloudflare/cloudflare-go/v5"
31+
"github.com/cloudflare/cloudflare-go/v5/custom_hostnames"
3132
"github.com/cloudflare/cloudflare-go/v5/dns"
3233
"github.com/cloudflare/cloudflare-go/v5/zones"
3334
"github.com/maxatome/go-testdeep/td"
@@ -351,7 +352,8 @@ func (m *mockCloudFlareClient) CustomHostnames(ctx context.Context, zoneID strin
351352
for idx := (page - 1) * perPage; idx < min(len(chs), page*perPage); idx++ {
352353
ch := m.customHostnames[zoneID][idx]
353354
if strings.HasPrefix(ch.Hostname, "newerror-list-") {
354-
m.DeleteCustomHostname(ctx, zoneID, ch.ID)
355+
params := custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F(zoneID)}
356+
m.DeleteCustomHostname(ctx, ch.ID, params)
355357
return nil, cloudflarev0.ResultInfo{}, errors.New("failed to list erroring custom hostname")
356358
}
357359
result = append(result, ch)
@@ -389,7 +391,8 @@ func (m *mockCloudFlareClient) CreateCustomHostname(ctx context.Context, zoneID
389391
return &cloudflarev0.CustomHostnameResponse{}, nil
390392
}
391393

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

36063609
t.Run("DeleteCustomHostname", func(t *testing.T) {
36073610
t.Parallel()
3608-
err := client.DeleteCustomHostname(ctx, zoneID, "foo")
3611+
err := client.DeleteCustomHostname(ctx, "1234", custom_hostnames.CustomHostnameDeleteParams{ZoneID: cloudflare.F("foo")})
36093612
assert.ErrorIs(t, err, context.Canceled)
36103613
})
36113614

0 commit comments

Comments
 (0)