Merge pull request #90 from weppos/dnsimple-subdomain

Fix bugs with subdomains
This commit is contained in:
xenolf 2016-01-30 23:57:27 +01:00
commit 1ab8907f82

View file

@ -5,7 +5,7 @@ import (
"os"
"strings"
"github.com/weppos/go-dnsimple/dnsimple"
"github.com/weppos/dnsimple-go/dnsimple"
)
// DNSProviderDNSimple is an implementation of the DNSProvider interface.
@ -35,12 +35,12 @@ func NewDNSProviderDNSimple(dnsimpleEmail, dnsimpleApiKey string) (*DNSProviderD
func (c *DNSProviderDNSimple) Present(domain, token, keyAuth string) error {
fqdn, value, ttl := DNS01Record(domain, keyAuth)
zoneID, err := c.getHostedZoneID(domain)
zoneID, zoneName, err := c.getHostedZone(domain)
if err != nil {
return err
}
recordAttributes := c.newTxtRecord(domain, fqdn, value, ttl)
recordAttributes := c.newTxtRecord(zoneName, fqdn, value, ttl)
_, _, err = c.client.Domains.CreateRecord(zoneID, *recordAttributes)
if err != nil {
return fmt.Errorf("DNSimple API call failed: %v", err)
@ -67,10 +67,10 @@ func (c *DNSProviderDNSimple) CleanUp(domain, token, keyAuth string) error {
return nil
}
func (c *DNSProviderDNSimple) getHostedZoneID(domain string) (string, error) {
func (c *DNSProviderDNSimple) getHostedZone(domain string) (string, string, error) {
domains, _, err := c.client.Domains.List()
if err != nil {
return "", fmt.Errorf("DNSimple API call failed: %v", err)
return "", "", fmt.Errorf("DNSimple API call failed: %v", err)
}
var hostedDomain dnsimple.Domain
@ -82,36 +82,36 @@ func (c *DNSProviderDNSimple) getHostedZoneID(domain string) (string, error) {
}
}
if hostedDomain.Id == 0 {
return "", fmt.Errorf("No matching DNSimple domain found for domain %s", domain)
return "", "", fmt.Errorf("No matching DNSimple domain found for domain %s", domain)
}
return fmt.Sprintf("%v", hostedDomain.Id), nil
return fmt.Sprintf("%v", hostedDomain.Id), hostedDomain.Name, nil
}
func (c *DNSProviderDNSimple) findTxtRecords(domain, fqdn string) ([]*dnsimple.Record, error) {
zoneID, err := c.getHostedZoneID(domain)
func (c *DNSProviderDNSimple) findTxtRecords(domain, fqdn string) ([]dnsimple.Record, error) {
zoneID, zoneName, err := c.getHostedZone(domain)
if err != nil {
return nil, err
}
var records []*dnsimple.Record
var records []dnsimple.Record
result, _, err := c.client.Domains.ListRecords(zoneID, "", "TXT")
if err != nil {
return records, fmt.Errorf("DNSimple API call has failed: %v", err)
}
recordName := c.extractRecordName(fqdn, domain)
recordName := c.extractRecordName(fqdn, zoneName)
for _, record := range result {
if record.Name == recordName {
records = append(records, &record)
records = append(records, record)
}
}
return records, nil
}
func (c *DNSProviderDNSimple) newTxtRecord(domain, fqdn, value string, ttl int) *dnsimple.Record {
name := c.extractRecordName(fqdn, domain)
func (c *DNSProviderDNSimple) newTxtRecord(zone, fqdn, value string, ttl int) *dnsimple.Record {
name := c.extractRecordName(fqdn, zone)
return &dnsimple.Record{
Type: "TXT",