Skip to content

Commit 3f8f9e7

Browse files
authoredFeb 18, 2025··
refactor(RecordConfig): Use ChangeType() instead of assignment (#3441)
1 parent e0e32ca commit 3f8f9e7

File tree

9 files changed

+28
-9
lines changed

9 files changed

+28
-9
lines changed
 

‎models/recordtype.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package models
2+
3+
// ChangeType converts rc to an rc of type newType. This is only needed when
4+
// converting from one type to another. Do not use this when initializing a new
5+
// record.
6+
//
7+
// Typically this is used to convert an ALIAS to a CNAME, or SPF to TXT. Using
8+
// this function future-proofs the code since eventually such changes will
9+
// require extra steps.
10+
func (rc *RecordConfig) ChangeType(newType string, _ string) {
11+
12+
rc.Type = newType
13+
14+
}

‎providers/bunnydns/records.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (b *bunnydnsProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, ex
6464
}
6565

6666
if rc.Type == "ALIAS" {
67-
rc.Type = "CNAME"
67+
rc.ChangeType("CNAME", dc.Name)
6868
}
6969
}
7070

‎providers/cloudflare/cloudflareProvider.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (c *cloudflareProvider) getDomainID(name string) (string, error) {
180180
func (c *cloudflareProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, records models.Records) ([]*models.Correction, int, error) {
181181
for _, rec := range dc.Records {
182182
if rec.Type == "ALIAS" {
183-
rec.Type = "CNAME"
183+
rec.ChangeType("CNAME", dc.Name)
184184
}
185185
}
186186

@@ -446,7 +446,7 @@ func (c *cloudflareProvider) preprocessConfig(dc *models.DomainConfig) error {
446446

447447
for _, rec := range dc.Records {
448448
if rec.Type == "ALIAS" {
449-
rec.Type = "CNAME"
449+
rec.ChangeType("CNAME", dc.Name)
450450
}
451451
}
452452

@@ -819,6 +819,11 @@ func stringDefault(value interface{}, def string) string {
819819

820820
func (c *cloudflareProvider) nativeToRecord(domain string, cr cloudflare.DNSRecord) (*models.RecordConfig, error) {
821821

822+
// ALIAS in Cloudflare works like CNAME.
823+
if cr.Type == "ALIAS" {
824+
cr.Type = "CNAME"
825+
}
826+
822827
// workaround for https://github.com/StackExchange/dnscontrol/issues/446
823828
if cr.Type == "SPF" {
824829
cr.Type = "TXT"

‎providers/dnsmadeeasy/dnsMadeEasyProvider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (api *dnsMadeEasyProvider) GetZoneRecordsCorrections(dc *models.DomainConfi
113113
for _, rec := range dc.Records {
114114
if rec.Type == "ALIAS" {
115115
// ALIAS is called ANAME on DNS Made Easy
116-
rec.Type = "ANAME"
116+
rec.ChangeType("ANAME", dc.Name)
117117
} else if rec.Type == "NS" {
118118
// NS records have fixed TTL on DNS Made Easy and it cannot be changed
119119
rec.TTL = fixedNameServerRecordTTL

‎providers/gandiv5/gandi_v5Provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func PrepDesiredRecords(dc *models.DomainConfig) {
181181
if rec.Type == "ALIAS" && rec.Name != "@" {
182182
// GANDI only permits aliases on a naked domain.
183183
// Therefore, we change this to a CNAME.
184-
rec.Type = "CNAME"
184+
rec.ChangeType("CNAME", dc.Name)
185185
}
186186
if rec.TTL < 300 {
187187
printer.Warnf("Gandi does not support ttls < 300. Setting %s from %d to 300\n", rec.GetLabelFQDN(), rec.TTL)

‎providers/gcore/gcoreProvider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (c *gcoreProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exist
147147
// Gcore auto uses ALIAS for apex zone CNAME records, just like CloudFlare
148148
for _, rec := range dc.Records {
149149
if rec.Type == "ALIAS" {
150-
rec.Type = "CNAME"
150+
rec.ChangeType("CNAME", dc.Name)
151151
}
152152
}
153153

‎providers/hedns/hednsProvider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (c *hednsProvider) GetZoneRecords(domain string, meta map[string]string) (m
329329
err = rc.SetTargetSRVPriorityString(priority, data)
330330
case "SPF":
331331
// Convert to TXT record as SPF is deprecated
332-
rc.Type = "TXT"
332+
rc.ChangeType("TXT", domain)
333333
fallthrough
334334
default:
335335
err = rc.PopulateFromStringFunc(rc.Type, data, domain, txtutil.ParseQuoted)

‎providers/loopia/loopiaProvider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func PrepDesiredRecords(dc *models.DomainConfig) {
230230
if rec.Type == "ALIAS" {
231231
// Loopia does not support ALIAS.
232232
// Therefore, we change this to a CNAME.
233-
rec.Type = "CNAME"
233+
rec.ChangeType("CNAME", dc.Name)
234234
}
235235
if rec.TTL < 300 {
236236
/* you can submit TTL lower than 300 but the dig results are normalized to 300 */

‎providers/namedotcom/records.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (n *namedotcomProvider) GetZoneRecordsCorrections(dc *models.DomainConfig,
3434

3535
for _, rec := range dc.Records {
3636
if rec.Type == "ALIAS" {
37-
rec.Type = "ANAME"
37+
rec.ChangeType("ANAME", dc.Name)
3838
}
3939
}
4040

0 commit comments

Comments
 (0)
Please sign in to comment.