adding functionality to allow Gandi to use SRV record types (#192)

* adding CombineSRVs and SplitCombinedSrvValues

adding support for Gandi SRV record types

* adding dc.CombineSRVs()

adding dc.CombineSRVs() to allow Gandi SRV record types.

* adding providers.CanUseSRV

adding providers.CanUseSRV for allowing Gandi to use SRV record types.

* adding case "SRV"

adding case SRV to allow Gandi to use SRV record types.
This commit is contained in:
chewrocca 2017-08-29 09:10:50 -05:00 committed by Craig Peterson
parent 2b23a21d84
commit 4244d5f638
3 changed files with 48 additions and 1 deletions

View file

@ -327,6 +327,46 @@ func SplitCombinedMxValue(s string) (preference uint16, target string, err error
return uint16(n64), parts[1], nil
}
// CombineSRVs will merge the priority, weight, and port into the target field for all srv records.
// Useful for providers that desire them as one field.
func (dc *DomainConfig) CombineSRVs() {
for _, rec := range dc.Records {
if rec.Type == "SRV" {
if rec.CombinedTarget {
pm := strings.Join([]string{"CombineSRVs: Already collapsed: ", rec.Name, rec.Target}, " ")
panic(pm)
}
rec.Target = fmt.Sprintf("%d %d %d %s", rec.SrvPriority, rec.SrvWeight, rec.SrvPort, rec.Target)
rec.CombinedTarget = true
}
}
}
//SplitCombinedSrvValue splits a combined SRV priority, weight, port and target into
//separate entities, some DNS providers want "5" "10" 15" and "foo.com.",
//while other providers want "5 10 15 foo.com.".
func SplitCombinedSrvValue(s string) (priority, weight, port uint16, target string, err error) {
parts := strings.Fields(s)
if len(parts) != 4 {
return 0, 0, 0, "", fmt.Errorf("SRV value %#v contains too many fields", s)
}
priorityconv, err := strconv.ParseInt(parts[0], 10, 16)
if err != nil {
return 0, 0, 0, "", fmt.Errorf("Priority %#v does not fit into a uint16", parts[0])
}
weightconv, err := strconv.ParseInt(parts[1], 10, 16)
if err != nil {
return 0, 0, 0, "", fmt.Errorf("Weight %#v does not fit into a uint16", parts[0])
}
portconv, err := strconv.ParseInt(parts[2], 10, 16)
if err != nil {
return 0, 0, 0, "", fmt.Errorf("Port %#v does not fit into a uint16", parts[0])
}
return uint16(priorityconv), uint16(weightconv), uint16(portconv), parts[3], nil
}
func copyObj(input interface{}, output interface{}) error {
buf := &bytes.Buffer{}
enc := gob.NewEncoder(buf)

View file

@ -61,6 +61,7 @@ func (c *GandiApi) GetNameservers(domain string) ([]*models.Nameserver, error) {
func (c *GandiApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
dc.Punycode()
dc.CombineSRVs()
dc.CombineMXs()
domaininfo, err := c.getDomainInfo(dc.Name)
if err != nil {
@ -146,5 +147,5 @@ func newGandi(m map[string]string, metadata json.RawMessage) (providers.DNSServi
}
func init() {
providers.RegisterDomainServiceProviderType("GANDI", newGandi, providers.CanUsePTR)
providers.RegisterDomainServiceProviderType("GANDI", newGandi, providers.CanUsePTR, providers.CanUseSRV)
}

View file

@ -184,6 +184,12 @@ func convert(r *gandirecord.RecordInfo, origin string) *models.RecordConfig {
}
switch r.Type {
case "A", "AAAA", "NS", "CNAME", "PTR", "TXT":
case "SRV":
var err error
rc.SrvPriority, rc.SrvWeight, rc.SrvPort, rc.Target, err = models.SplitCombinedSrvValue(r.Value)
if err != nil {
panic(fmt.Sprintf("gandi.convert bad srv value format: %#v (%s)", r.Value, err))
}
// no-op
case "MX":
var err error