Skip to content

Commit d077169

Browse files
committed
Use const instead of hardcoded thresholds + Trim comments of length >500
1 parent 635474f commit d077169

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

provider/cloudflare/cloudflare.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ const (
4747
cloudFlareUpdate = "UPDATE"
4848
// defaultTTL 1 = automatic
4949
defaultTTL = 1
50+
51+
// Cloudflare tier limitations https://developers.cloudflare.com/dns/manage-dns-records/reference/record-attributes/#availability
52+
// freeZoneCommentMaxLength is the maximum length of a DNS record comment on free zones
53+
freeZoneCommentMaxLength = 100
54+
// paidZoneCommentMaxLength is the maximum length of a DNS record comment on paid zones
55+
paidZoneCommentMaxLength = 500
5056
)
5157

5258
// We have to use pointers to bools now, as the upstream cloudflare-go library requires them
@@ -877,16 +883,20 @@ func (p *CloudFlareProvider) newCloudFlareChange(action string, ep *endpoint.End
877883
}
878884
}
879885

880-
// Free account checks https://developers.cloudflare.com/dns/manage-dns-records/reference/record-attributes/#availability
881-
if tags != nil || len(comment) > 100 {
886+
// Free account checks
887+
if tags != nil || len(comment) > freeZoneCommentMaxLength {
882888
freeAccount := !p.ZoneHasPaidPlan(ep.DNSName)
883889
if freeAccount && tags != nil {
884-
log.Warnf("DNS tags are only available for paid accounts, skipping for %s", ep.DNSName)
890+
log.Infof("DNS tags are only available for paid accounts, skipping for %s", ep.DNSName)
885891
tags = nil
886892
}
887-
if freeAccount && len(comment) > 100 {
888-
log.Warnf("DNS record comment is limited to 100 chars for free zones, trimming comment of %s", ep.DNSName)
889-
comment = comment[:99]
893+
if freeAccount && len(comment) > freeZoneCommentMaxLength {
894+
log.Infof("DNS record comment is limited to %d chars for free zones, trimming comment of %s", freeZoneCommentMaxLength, ep.DNSName)
895+
comment = comment[:freeZoneCommentMaxLength-1]
896+
}
897+
if len(comment) > paidZoneCommentMaxLength {
898+
log.Infof("DNS record comment is limited to %d chars, trimming comment of %s", paidZoneCommentMaxLength, ep.DNSName)
899+
comment = comment[:paidZoneCommentMaxLength-1]
890900
}
891901
}
892902

0 commit comments

Comments
 (0)