mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-09-04 12:14:23 +08:00
Fix Gandi's MX handling.
This commit is contained in:
parent
4ae2e172eb
commit
4570e0e404
2 changed files with 33 additions and 1 deletions
|
@ -310,6 +310,23 @@ func (dc *DomainConfig) CombineMXs() {
|
|||
}
|
||||
}
|
||||
|
||||
// SplitCombinedMxValue splits a combined MX preference and target into
|
||||
// separate entities, i.e. splitting "10 aspmx2.googlemail.com."
|
||||
// into "10" and "aspmx2.googlemail.com.".
|
||||
func SplitCombinedMxValue(s string) (preference uint16, target string, err error) {
|
||||
parts := strings.Fields(s)
|
||||
|
||||
if len(parts) != 2 {
|
||||
return 0, "", fmt.Errorf("MX value %#v contains too many fields", s)
|
||||
}
|
||||
|
||||
n64, err := strconv.ParseUint(parts[0], 10, 16)
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("MX preference %#v does not fit into a uint16", parts[0])
|
||||
}
|
||||
return uint16(n64), parts[1], nil
|
||||
}
|
||||
|
||||
func copyObj(input interface{}, output interface{}) error {
|
||||
buf := &bytes.Buffer{}
|
||||
enc := gob.NewEncoder(buf)
|
||||
|
|
|
@ -173,7 +173,7 @@ func (c *GandiApi) createGandiZone(domainname string, zoneID int64, records []ga
|
|||
}
|
||||
|
||||
func convert(r *gandirecord.RecordInfo, origin string) *models.RecordConfig {
|
||||
return &models.RecordConfig{
|
||||
rc := &models.RecordConfig{
|
||||
NameFQDN: dnsutil.AddOrigin(r.Name, origin),
|
||||
Name: r.Name,
|
||||
Type: r.Type,
|
||||
|
@ -181,4 +181,19 @@ func convert(r *gandirecord.RecordInfo, origin string) *models.RecordConfig {
|
|||
Target: r.Value,
|
||||
TTL: uint32(r.Ttl),
|
||||
}
|
||||
switch r.Type {
|
||||
case "A", "AAAA", "NS", "CNAME", "TXT":
|
||||
// no-op
|
||||
case "MX":
|
||||
var err error
|
||||
rc.MxPreference, rc.Target, err = models.SplitCombinedMxValue(r.Value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("gandi.convert bad mx value format: %#v", r.Value))
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("gandi.convert unimplemented rtype %v", r.Type))
|
||||
// We panic so that we quickly find any switch statements
|
||||
// that have not been updated for a new RR type.
|
||||
}
|
||||
return rc
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue