Skip to content

Commit 1c19355

Browse files
thriqonfrittentheke
authored andcommitted
provider: Add support for MX records
1 parent 602ca53 commit 1c19355

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

internal/designate/provider/provider.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ func canonicalizeDomainNames(domains []string) []string {
7676
return cDomains
7777
}
7878

79+
func canonicalizeDomainNamesForMX(domains []string) []string {
80+
var cDomains []string
81+
82+
for _, d := range domains {
83+
parts := strings.Split(d, " ")
84+
if len(parts) == 2 {
85+
// If the format does not conform to the expected one, play it safe and just pass the value on.
86+
// Otherwise, canonicalize the hostname.
87+
d = fmt.Sprintf("%s %s", parts[0], canonicalizeDomainName(parts[1]))
88+
}
89+
90+
cDomains = append(cDomains, canonicalizeDomainName(d))
91+
}
92+
return cDomains
93+
}
94+
7995
// converts domain name to FQDN
8096
func canonicalizeDomainName(d string) string {
8197
if !strings.HasSuffix(d, ".") {
@@ -158,7 +174,7 @@ func (p designateProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, e
158174

159175
func (p designateProvider) supportedRecordType(recordType string) bool {
160176
switch recordType {
161-
case endpoint.RecordTypeA, endpoint.RecordTypeTXT, endpoint.RecordTypeCNAME, endpoint.RecordTypeNS:
177+
case endpoint.RecordTypeA, endpoint.RecordTypeTXT, endpoint.RecordTypeCNAME, endpoint.RecordTypeNS, endpoint.RecordTypeMX:
162178
return true
163179
default:
164180
return false
@@ -205,6 +221,9 @@ func addEndpoint(ep *endpoint.Endpoint, recordSets map[string]*recordSet, oldEnd
205221
if ep.RecordType == endpoint.RecordTypeCNAME || ep.RecordType == endpoint.RecordTypeNS {
206222
targets = canonicalizeDomainNames(targets)
207223
}
224+
if ep.RecordType == endpoint.RecordTypeMX {
225+
targets = canonicalizeDomainNamesForMX(targets)
226+
}
208227
for _, t := range targets {
209228
rs.names[t] = !delete
210229
}

internal/designate/provider/provider_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
457457
Targets: endpoint.Targets{"ns1.test.net", "ns2.test.net", "ns3.test.net"},
458458
Labels: map[string]string{},
459459
},
460+
{
461+
DNSName: "mx.test.net",
462+
RecordType: endpoint.RecordTypeMX,
463+
Targets: endpoint.Targets{"10 mx1.test.net", "100 mx2.test.net"},
464+
Labels: map[string]string{},
465+
},
460466
}
461467
expected := []*recordsets.RecordSet{
462468
{
@@ -496,6 +502,12 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
496502
Records: []string{"ns1.test.net.", "ns2.test.net.", "ns3.test.net."},
497503
ZoneID: "zone-2",
498504
},
505+
{
506+
Name: "mx.test.net.",
507+
Type: endpoint.RecordTypeMX,
508+
Records: []string{"10 mx1.test.net.", "100 mx2.test.net."},
509+
ZoneID: "zone-2",
510+
},
499511
}
500512
expectedCopy := make([]*recordsets.RecordSet, len(expected))
501513
copy(expectedCopy, expected)

0 commit comments

Comments
 (0)