mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
@@ -29,14 +29,15 @@ func TestConversion(t *testing.T) {
|
||||
Type: "SRV",
|
||||
Name: "_ssh_.tcp",
|
||||
Data: "5 22 ssh.example.com",
|
||||
Priority: 5,
|
||||
Priority: intPtr(5),
|
||||
TTL: 300,
|
||||
},
|
||||
{
|
||||
Type: "MX",
|
||||
Name: "",
|
||||
Data: "mail.example.com",
|
||||
TTL: 300,
|
||||
Type: "MX",
|
||||
Name: "",
|
||||
Data: "mail.example.com",
|
||||
Priority: intPtr(0),
|
||||
TTL: 300,
|
||||
},
|
||||
{
|
||||
Type: "NS",
|
||||
@@ -66,8 +67,12 @@ func TestConversion(t *testing.T) {
|
||||
|
||||
converted := toVultrRecord(dc, rc, 0)
|
||||
|
||||
if converted.Type != record.Type || converted.Name != record.Name || converted.Data != record.Data || converted.Priority != record.Priority || converted.TTL != record.TTL {
|
||||
if converted.Type != record.Type || converted.Name != record.Name || converted.Data != record.Data || ((converted.Priority == nil) != (record.Priority == nil) || (converted.Priority != nil && *converted.Priority != *record.Priority)) || converted.TTL != record.TTL {
|
||||
t.Error("Vultr record conversion mismatch", record, rc, converted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func intPtr(v int) *int {
|
||||
return &v
|
||||
}
|
||||
|
@@ -119,7 +119,7 @@ func (api *Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Co
|
||||
corrections = append(corrections, &models.Correction{
|
||||
Msg: mod.String(),
|
||||
F: func() error {
|
||||
return api.client.DNSRecord.Create(context.Background(), dc.Name, r.Type, r.Name, r.Data, r.TTL, r.Priority)
|
||||
return api.client.DNSRecord.Create(context.Background(), dc.Name, r.Type, r.Name, r.Data, r.TTL, vultrPriority(r))
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -191,10 +191,10 @@ func toRecordConfig(domain string, r *govultr.DNSRecord) (*models.RecordConfig,
|
||||
if !strings.HasSuffix(data, ".") {
|
||||
data = data + "."
|
||||
}
|
||||
return rc, rc.SetTargetMX(uint16(r.Priority), data)
|
||||
return rc, rc.SetTargetMX(uint16(vultrPriority(r)), data)
|
||||
case "SRV":
|
||||
// Vultr returns SRV records in the format "[weight] [port] [target]".
|
||||
return rc, rc.SetTargetSRVPriorityString(uint16(r.Priority), data)
|
||||
return rc, rc.SetTargetSRVPriorityString(uint16(vultrPriority(r)), data)
|
||||
case "TXT":
|
||||
// Remove quotes if it is a TXT record.
|
||||
if !strings.HasPrefix(data, `"`) || !strings.HasSuffix(data, `"`) {
|
||||
@@ -225,13 +225,15 @@ func toVultrRecord(dc *models.DomainConfig, rc *models.RecordConfig, vultrID int
|
||||
data = fmt.Sprintf(`"%s"`, data)
|
||||
}
|
||||
|
||||
priority := 0
|
||||
var priority *int
|
||||
|
||||
if rc.Type == "MX" {
|
||||
priority = int(rc.MxPreference)
|
||||
tmp := int(rc.MxPreference)
|
||||
priority = &tmp
|
||||
}
|
||||
if rc.Type == "SRV" {
|
||||
priority = int(rc.SrvPriority)
|
||||
tmp := int(rc.SrvPriority)
|
||||
priority = &tmp
|
||||
}
|
||||
|
||||
r := &govultr.DNSRecord{
|
||||
@@ -254,3 +256,10 @@ func toVultrRecord(dc *models.DomainConfig, rc *models.RecordConfig, vultrID int
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func vultrPriority(r *govultr.DNSRecord) int {
|
||||
if r.Priority == nil {
|
||||
return 0
|
||||
}
|
||||
return *r.Priority
|
||||
}
|
||||
|
Reference in New Issue
Block a user