mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
* OVH: Fixed DKIM when having longer keys (#487) * Shorter error message, typo fix
This commit is contained in:
committed by
Tom Limoncelli
parent
df163c0042
commit
9052e7a1a7
@ -2,6 +2,7 @@ package ovh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/models"
|
"github.com/StackExchange/dnscontrol/models"
|
||||||
"github.com/miekg/dns/dnsutil"
|
"github.com/miekg/dns/dnsutil"
|
||||||
@ -77,7 +78,7 @@ func (c *ovhProvider) fetchRecords(fqdn string) ([]*Record, error) {
|
|||||||
|
|
||||||
records := make([]*Record, len(recordIds))
|
records := make([]*Record, len(recordIds))
|
||||||
for i, id := range recordIds {
|
for i, id := range recordIds {
|
||||||
r, err := c.fecthRecord(fqdn, id)
|
r, err := c.fetchRecord(fqdn, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -87,7 +88,7 @@ func (c *ovhProvider) fetchRecords(fqdn string) ([]*Record, error) {
|
|||||||
return records, nil
|
return records, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ovhProvider) fecthRecord(fqdn string, id int) (*Record, error) {
|
func (c *ovhProvider) fetchRecord(fqdn string, id int) (*Record, error) {
|
||||||
var response Record
|
var response Record
|
||||||
|
|
||||||
err := c.client.CallAPI("GET", fmt.Sprintf("/domain/zone/%s/record/%d", fqdn, id), nil, &response, true)
|
err := c.client.CallAPI("GET", fmt.Sprintf("/domain/zone/%s/record/%d", fqdn, id), nil, &response, true)
|
||||||
@ -111,6 +112,9 @@ func (c *ovhProvider) deleteRecordFunc(id int64, fqdn string) func() error {
|
|||||||
// Returns a function that can be invoked to create a record in a zone.
|
// Returns a function that can be invoked to create a record in a zone.
|
||||||
func (c *ovhProvider) createRecordFunc(rc *models.RecordConfig, fqdn string) func() error {
|
func (c *ovhProvider) createRecordFunc(rc *models.RecordConfig, fqdn string) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
|
if c.isDKIMRecord(rc) {
|
||||||
|
rc.Type = "DKIM"
|
||||||
|
}
|
||||||
record := Record{
|
record := Record{
|
||||||
SubDomain: dnsutil.TrimDomainName(rc.GetLabelFQDN(), fqdn),
|
SubDomain: dnsutil.TrimDomainName(rc.GetLabelFQDN(), fqdn),
|
||||||
FieldType: rc.Type,
|
FieldType: rc.Type,
|
||||||
@ -129,6 +133,9 @@ func (c *ovhProvider) createRecordFunc(rc *models.RecordConfig, fqdn string) fun
|
|||||||
// Returns a function that can be invoked to update a record in a zone.
|
// Returns a function that can be invoked to update a record in a zone.
|
||||||
func (c *ovhProvider) updateRecordFunc(old *Record, rc *models.RecordConfig, fqdn string) func() error {
|
func (c *ovhProvider) updateRecordFunc(old *Record, rc *models.RecordConfig, fqdn string) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
|
if c.isDKIMRecord(rc) {
|
||||||
|
rc.Type = "DKIM"
|
||||||
|
}
|
||||||
record := Record{
|
record := Record{
|
||||||
SubDomain: rc.GetLabel(),
|
SubDomain: rc.GetLabel(),
|
||||||
FieldType: rc.Type,
|
FieldType: rc.Type,
|
||||||
@ -141,10 +148,20 @@ func (c *ovhProvider) updateRecordFunc(old *Record, rc *models.RecordConfig, fqd
|
|||||||
record.SubDomain = ""
|
record.SubDomain = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.client.CallAPI("PUT", fmt.Sprintf("/domain/zone/%s/record/%d", fqdn, old.ID), &record, &Void{}, true)
|
err := c.client.CallAPI("PUT", fmt.Sprintf("/domain/zone/%s/record/%d", fqdn, old.ID), &record, &Void{}, true)
|
||||||
|
if err != nil && rc.Type == "DKIM" && strings.Contains(err.Error(), "alter read-only properties: fieldType") {
|
||||||
|
err = fmt.Errorf("This usually occurs when DKIM value is longer than the TXT record limit what OVH allows. Delete the TXT record to get past this limitation. [Original error: %s]", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if provided record is DKIM
|
||||||
|
func (c *ovhProvider) isDKIMRecord(rc *models.RecordConfig) bool {
|
||||||
|
return (rc != nil && rc.Type == "TXT" && strings.Contains(rc.GetLabel(), "._domainkey"))
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ovhProvider) refreshZone(fqdn string) error {
|
func (c *ovhProvider) refreshZone(fqdn string) error {
|
||||||
return c.client.CallAPI("POST", fmt.Sprintf("/domain/zone/%s/refresh", fqdn), nil, &Void{}, true)
|
return c.client.CallAPI("POST", fmt.Sprintf("/domain/zone/%s/refresh", fqdn), nil, &Void{}, true)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user