fix: CNAME support (#1735)

This commit is contained in:
Ludovic Fernandez 2022-11-25 18:12:21 +01:00 committed by GitHub
parent 1b56aa0d2f
commit 6cc21f2753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 132 additions and 102 deletions

View file

@ -107,6 +107,7 @@ func (d *DNSProvider) Present(domain, _, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// Check if credentials were previously saved for this domain.
// TODO(ldez) replace domain by FQDN to follow CNAME.
account, err := d.storage.Fetch(domain)
// Errors other than goacmeDNS.ErrDomainNotFound are unexpected.
if err != nil && !errors.Is(err, goacmedns.ErrDomainNotFound) {

View file

@ -132,7 +132,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneName, err := d.getHostedZone(domain)
zoneName, err := d.getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("alicloud: %w", err)
}
@ -153,12 +153,12 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
records, err := d.findTxtRecords(domain, fqdn)
records, err := d.findTxtRecords(fqdn)
if err != nil {
return fmt.Errorf("alicloud: %w", err)
}
_, err = d.getHostedZone(domain)
_, err = d.getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("alicloud: %w", err)
}
@ -197,7 +197,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, error) {
startPage++
}
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return "", err
}
@ -233,8 +233,8 @@ func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) (*alidns.AddDomainR
return request, nil
}
func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]alidns.Record, error) {
zoneName, err := d.getHostedZone(domain)
func (d *DNSProvider) findTxtRecords(fqdn string) ([]alidns.Record, error) {
zoneName, err := d.getHostedZone(fqdn)
if err != nil {
return nil, err
}

View file

@ -106,7 +106,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("aurora: could not determine zone for domain %q: %w", domain, err)
}
@ -158,7 +158,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return fmt.Errorf("unknown recordID for %q", fqdn)
}
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(fqdn))
if err != nil {
return fmt.Errorf("could not determine zone for domain %q: %w", domain, err)
}

View file

@ -114,6 +114,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
Value: value,
}}
// TODO(ldez) replace domain by FQDN to follow CNAME.
_, err := d.addTxtRecord(domain, records)
if err != nil {
return fmt.Errorf("autodns: %w", err)
@ -133,6 +134,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
Value: value,
}}
// TODO(ldez) replace domain by FQDN to follow CNAME.
if err := d.removeTXTRecord(domain, records); err != nil {
return fmt.Errorf("autodns: %w", err)
}

View file

@ -101,6 +101,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// TODO(ldez) replace domain by FQDN to follow CNAME.
domainID, err := d.getDomainIDByName(domain)
if err != nil {
return fmt.Errorf("checkdomain: %w", err)
@ -111,10 +112,10 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
return fmt.Errorf("checkdomain: %w", err)
}
name, value := dns01.GetRecord(domain, keyAuth)
fqdn, value := dns01.GetRecord(domain, keyAuth)
err = d.createRecord(domainID, &Record{
Name: name,
Name: fqdn,
TTL: d.config.TTL,
Type: "TXT",
Value: value,
@ -129,6 +130,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// CleanUp removes the TXT record previously created.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
// TODO(ldez) replace domain by FQDN to follow CNAME.
domainID, err := d.getDomainIDByName(domain)
if err != nil {
return fmt.Errorf("checkdomain: %w", err)
@ -139,15 +141,15 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return fmt.Errorf("checkdomain: %w", err)
}
name, value := dns01.GetRecord(domain, keyAuth)
fqdn, value := dns01.GetRecord(domain, keyAuth)
err = d.deleteTXTRecord(domainID, name, value)
err = d.deleteTXTRecord(domainID, fqdn, value)
if err != nil {
return fmt.Errorf("checkdomain: %w", err)
}
d.domainIDMu.Lock()
delete(d.domainIDMapping, name)
delete(d.domainIDMapping, fqdn)
d.domainIDMu.Unlock()
return nil

View file

@ -93,7 +93,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneName, err := d.getHostedZone(domain)
zoneName, err := d.getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("dnsimple: %w", err)
}
@ -116,7 +116,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
records, err := d.findTxtRecords(domain, fqdn)
records, err := d.findTxtRecords(fqdn)
if err != nil {
return fmt.Errorf("dnsimple: %w", err)
}
@ -144,7 +144,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
}
func (d *DNSProvider) getHostedZone(domain string) (string, error) {
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return "", err
}
@ -175,8 +175,8 @@ func (d *DNSProvider) getHostedZone(domain string) (string, error) {
return hostedZone.Name, nil
}
func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]dnsimple.ZoneRecord, error) {
zoneName, err := d.getHostedZone(domain)
func (d *DNSProvider) findTxtRecords(fqdn string) ([]dnsimple.ZoneRecord, error) {
zoneName, err := d.getHostedZone(fqdn)
if err != nil {
return nil, err
}

View file

@ -88,7 +88,8 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneID, zoneName, err := d.getHostedZone(domain)
zoneID, zoneName, err := d.getHostedZone(fqdn)
if err != nil {
return err
}
@ -106,12 +107,12 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
records, err := d.findTxtRecords(domain, fqdn)
zoneID, zoneName, err := d.getHostedZone(fqdn)
if err != nil {
return err
}
zoneID, _, err := d.getHostedZone(domain)
records, err := d.findTxtRecords(fqdn, zoneID, zoneName)
if err != nil {
return err
}
@ -137,7 +138,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
return "", "", fmt.Errorf("API call failed: %w", err)
}
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return "", "", err
}
@ -168,12 +169,7 @@ func (d *DNSProvider) newTxtRecord(zone, fqdn, value string, ttl int) *dnspod.Re
}
}
func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]dnspod.Record, error) {
zoneID, zoneName, err := d.getHostedZone(domain)
if err != nil {
return nil, err
}
func (d *DNSProvider) findTxtRecords(fqdn, zoneID, zoneName string) ([]dnspod.Record, error) {
recordName := extractRecordName(fqdn, zoneName)
var records []dnspod.Record

View file

@ -99,6 +99,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
rootDomain, err := d.client.GetRootDomain(domain)
if err != nil {
return fmt.Errorf("dynu: could not find root domain for %s: %w", domain, err)
@ -138,6 +139,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
rootDomain, err := d.client.GetRootDomain(domain)
if err != nil {
return fmt.Errorf("dynu: could not find root domain for %s: %w", domain, err)

View file

@ -109,7 +109,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zone, err := findZone(domain)
zone, err := findZone(fqdn)
if err != nil {
return fmt.Errorf("edgedns: %w", err)
}
@ -161,7 +161,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zone, err := findZone(domain)
zone, err := findZone(fqdn)
if err != nil {
return fmt.Errorf("edgedns: %w", err)
}
@ -215,7 +215,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
}
func findZone(domain string) (string, error) {
zone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
zone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return "", err
}

View file

@ -66,7 +66,7 @@ func TestLiveTTL(t *testing.T) {
}()
fqdn := "_acme-challenge." + domain + "."
zone, err := findZone(domain)
zone, err := findZone(fqdn)
require.NoError(t, err)
resourceRecordSets, err := configdns.GetRecordList(zone, fqdn, "TXT")

View file

@ -158,12 +158,12 @@ func TestDNSProvider_findZone(t *testing.T) {
}{
{
desc: "Extract root record name",
domain: "bar.com",
domain: "bar.com.",
expected: "bar.com",
},
{
desc: "Extract sub record name",
domain: "foo.bar.com",
domain: "foo.bar.com.",
expected: "bar.com",
},
}

View file

@ -113,7 +113,8 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
ctx := context.Background()
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneName, recordName, err := d.findZoneAndRecordName(fqdn, domain)
zoneName, recordName, err := d.findZoneAndRecordName(fqdn)
if err != nil {
return err
}
@ -169,7 +170,8 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
ctx := context.Background()
fqdn, _ := dns01.GetRecord(domain, keyAuth)
zoneName, recordName, err := d.findZoneAndRecordName(fqdn, domain)
zoneName, recordName, err := d.findZoneAndRecordName(fqdn)
if err != nil {
return err
}
@ -244,8 +246,8 @@ func (d *DNSProvider) findExistingRecordID(zoneID, recordName string) (string, e
}
// findZoneAndRecordName Extract DNS zone and DNS entry name.
func (d *DNSProvider) findZoneAndRecordName(fqdn, domain string) (string, string, error) {
zone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
func (d *DNSProvider) findZoneAndRecordName(fqdn string) (string, string, error) {
zone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return "", "", err
}

View file

@ -140,22 +140,19 @@ func TestDNSProvider_FindZoneAndRecordName(t *testing.T) {
testCases := []struct {
desc string
fqdn string
domain string
expected expected
}{
{
desc: "Extract root record name",
fqdn: "_acme-challenge.bar.com.",
domain: "bar.com",
desc: "Extract root record name",
fqdn: "_acme-challenge.bar.com.",
expected: expected{
zone: "bar.com",
recordName: "_acme-challenge",
},
},
{
desc: "Extract sub record name",
fqdn: "_acme-challenge.foo.bar.com.",
domain: "foo.bar.com",
desc: "Extract sub record name",
fqdn: "_acme-challenge.foo.bar.com.",
expected: expected{
zone: "bar.com",
recordName: "_acme-challenge.foo",
@ -168,7 +165,7 @@ func TestDNSProvider_FindZoneAndRecordName(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
zone, recordName, err := provider.findZoneAndRecordName(test.fqdn, test.domain)
zone, recordName, err := provider.findZoneAndRecordName(test.fqdn)
require.NoError(t, err)
assert.Equal(t, test.expected.zone, zone)
assert.Equal(t, test.expected.recordName, recordName)

View file

@ -120,6 +120,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
defer d.inProgressMu.Unlock()
// add TXT record into authZone
// TODO(ldez) replace domain by FQDN to follow CNAME.
recordID, err := d.addTXTRecord(domain, dns01.UnFqdn(authZone), name, value, d.config.TTL)
if err != nil {
return err
@ -146,6 +147,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
delete(d.activeRecords, fqdn)
// delete TXT record from authZone
// TODO(ldez) replace domain by FQDN to follow CNAME.
return d.deleteTXTRecord(domain, recordID)
}

View file

@ -108,6 +108,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
err := d.wrapper.AddTXTRecord(fqdn, domain, value, d.config.TTL)
if err != nil {
return fmt.Errorf("ibmcloud: %w", err)
@ -120,6 +121,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
err := d.wrapper.CleanupTXTRecord(fqdn, domain)
if err != nil {
return fmt.Errorf("ibmcloud: %w", err)

View file

@ -100,6 +100,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
_, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
err := d.deleteTxtRecord(domain, value)
if err != nil {
return fmt.Errorf("iij: %w", err)
@ -113,6 +114,7 @@ func (d *DNSProvider) addTxtRecord(domain, value string) error {
return err
}
// TODO(ldez) replace domain by FQDN to follow CNAME.
owner, zone, err := splitDomain(domain, zones)
if err != nil {
return err

View file

@ -100,7 +100,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneID, err := dpfapiutils.GetZoneIdFromServiceCode(context.Background(), d.client, d.config.ServiceCode)
zoneID, err := dpfapiutils.GetZoneIdFromServiceCode(ctx, d.client, d.config.ServiceCode)
if err != nil {
return fmt.Errorf("iijdpf: failed to get zone id: %w", err)
}
@ -124,7 +124,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneID, err := dpfapiutils.GetZoneIdFromServiceCode(context.Background(), d.client, d.config.ServiceCode)
zoneID, err := dpfapiutils.GetZoneIdFromServiceCode(ctx, d.client, d.config.ServiceCode)
if err != nil {
return fmt.Errorf("iijdpf: failed to get zone id: %w", err)
}

View file

@ -112,6 +112,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
ikDomain, err := d.client.GetDomainByName(domain)
if err != nil {
return fmt.Errorf("infomaniak: could not get domain %q: %w", domain, err)

View file

@ -115,6 +115,7 @@ func (d *DNSProvider) Present(domain, _, keyAuth string) error {
return fmt.Errorf("ionos: failed to get zones: %w", err)
}
// TODO(ldez) replace domain by FQDN to follow CNAME.
zone := findZone(zones, domain)
if zone == nil {
return errors.New("ionos: no matching zone found for domain")
@ -156,6 +157,7 @@ func (d *DNSProvider) CleanUp(domain, _, keyAuth string) error {
return fmt.Errorf("ionos: failed to get zones: %w", err)
}
// TODO(ldez) replace domain by FQDN to follow CNAME.
zone := findZone(zones, domain)
if zone == nil {
return errors.New("ionos: no matching zone found for domain")

View file

@ -132,6 +132,7 @@ func (d *DNSProvider) Timeout() (time.Duration, time.Duration) {
// Present creates a TXT record using the specified parameters.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zone, err := d.getHostedZoneInfo(fqdn)
if err != nil {
return err

View file

@ -87,6 +87,8 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
_, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
err := d.doRequest(domain, value, "REGIST")
if err != nil {
return fmt.Errorf("mydnsjp: %w", err)
@ -97,6 +99,8 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
_, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
err := d.doRequest(domain, value, "DELETE")
if err != nil {
return fmt.Errorf("mydnsjp: %w", err)

View file

@ -144,6 +144,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
// Present installs a TXT record for the DNS challenge.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// TODO(ldez) replace domain by FQDN to follow CNAME.
ch, err := newChallenge(domain, keyAuth)
if err != nil {
return fmt.Errorf("namecheap: %w", err)
@ -179,6 +180,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// CleanUp removes a TXT record used for a previous DNS challenge.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
// TODO(ldez) replace domain by FQDN to follow CNAME.
ch, err := newChallenge(domain, keyAuth)
if err != nil {
return fmt.Errorf("namecheap: %w", err)

View file

@ -108,11 +108,13 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
domainDetails, err := d.client.GetDomain(&namecom.GetDomainRequest{DomainName: domain})
if err != nil {
return fmt.Errorf("namedotcom API call failed: %w", err)
}
// TODO(ldez) replace domain by FQDN to follow CNAME.
request := &namecom.Record{
DomainName: domain,
Host: extractRecordName(fqdn, domainDetails.DomainName),
@ -133,6 +135,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
records, err := d.getRecords(domain)
if err != nil {
return fmt.Errorf("namedotcom: %w", err)
@ -140,6 +143,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
for _, rec := range records {
if rec.Fqdn == fqdn && rec.Type == "TXT" {
// TODO(ldez) replace domain by FQDN to follow CNAME.
request := &namecom.DeleteRecordRequest{
DomainName: domain,
ID: rec.ID,

View file

@ -89,7 +89,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneName, err := getZoneNameByDomain(domain)
zoneName, err := getZoneNameByDomain(fqdn)
if err != nil {
return fmt.Errorf("namesilo: %w", err)
}
@ -111,7 +111,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
zoneName, err := getZoneNameByDomain(domain)
zoneName, err := getZoneNameByDomain(fqdn)
if err != nil {
return fmt.Errorf("namesilo: %w", err)
}
@ -141,7 +141,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
}
func getZoneNameByDomain(domain string) (string, error) {
zone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
zone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return "", fmt.Errorf("failed to find zone for domain: %s, %w", domain, err)
}

View file

@ -110,9 +110,9 @@ func (d *DNSProvider) Sequential() time.Duration {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("nearlyfreespeech: could not determine zone for domain %q: %w", domain, err)
return fmt.Errorf("nearlyfreespeech: could not determine zone for domain %q: %w", fqdn, err)
}
record := internal.Record{
@ -134,9 +134,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("nearlyfreespeech: could not determine zone for domain %q: %w", domain, err)
return fmt.Errorf("nearlyfreespeech: could not determine zone for domain %q: %w", fqdn, err)
}
record := internal.Record{

View file

@ -91,8 +91,8 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
}
// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domainName, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domainName, keyAuth)
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
@ -138,8 +138,8 @@ func (d *DNSProvider) Present(domainName, token, keyAuth string) error {
}
// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domainName, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domainName, keyAuth)
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {

View file

@ -137,9 +137,9 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
rootDomain, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
rootDomain, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("nicmanager: could not determine zone for domain %q: %w", domain, err)
return fmt.Errorf("nicmanager: could not determine zone for domain %q: %w", fqdn, err)
}
zone, err := d.client.GetZone(dns01.UnFqdn(rootDomain))
@ -168,9 +168,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
rootDomain, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
rootDomain, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("nicmanager: could not determine zone for domain %q: %w", domain, err)
return fmt.Errorf("nicmanager: could not determine zone for domain %q: %w", fqdn, err)
}
zone, err := d.client.GetZone(dns01.UnFqdn(rootDomain))

View file

@ -15,11 +15,11 @@ import (
// see: https://github.com/go-acme/lego/pull/850
var mu sync.Mutex
func (d *DNSProvider) addTXTRecord(fqdn, domain, value string, ttl int) error {
func (d *DNSProvider) addTXTRecord(fqdn, value string, ttl int) error {
mu.Lock()
defer mu.Unlock()
zone, err := d.getHostedZone(domain)
zone, err := d.getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("%w", err)
}
@ -43,11 +43,11 @@ func (d *DNSProvider) addTXTRecord(fqdn, domain, value string, ttl int) error {
return nil
}
func (d *DNSProvider) cleanupTXTRecord(fqdn, domain, value string) error {
func (d *DNSProvider) cleanupTXTRecord(fqdn, value string) error {
mu.Lock()
defer mu.Unlock()
zone, err := d.getHostedZone(domain)
zone, err := d.getHostedZone(fqdn)
if err != nil {
return err
}
@ -74,7 +74,7 @@ func (d *DNSProvider) cleanupTXTRecord(fqdn, domain, value string) error {
}
func (d *DNSProvider) getHostedZone(domain string) (*iaas.DNS, error) {
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return nil, err
}

View file

@ -65,10 +65,10 @@ func TestDNSProvider_addAndCleanupRecords(t *testing.T) {
require.NoError(t, err)
t.Run("addTXTRecord", func(t *testing.T) {
err = p.addTXTRecord("test.example.com", "example.com", "dummyValue", 10)
err = p.addTXTRecord("test.example.com.", "dummyValue", 10)
require.NoError(t, err)
updZone, e := p.getHostedZone("example.com")
updZone, e := p.getHostedZone("test.example.com.")
require.NoError(t, e)
require.NotNil(t, updZone)
@ -76,10 +76,10 @@ func TestDNSProvider_addAndCleanupRecords(t *testing.T) {
})
t.Run("cleanupTXTRecord", func(t *testing.T) {
err = p.cleanupTXTRecord("test.example.com", "example.com", "dummyValue")
err = p.cleanupTXTRecord("test.example.com.", "dummyValue")
require.NoError(t, err)
updZone, e := p.getHostedZone("example.com")
updZone, e := p.getHostedZone("test.example.com.")
require.NoError(t, e)
require.NotNil(t, updZone)
@ -111,7 +111,7 @@ func TestDNSProvider_concurrentAddAndCleanupRecords(t *testing.T) {
for i, p := range providers {
go func(j int, client *DNSProvider) {
err := client.addTXTRecord(fmt.Sprintf("test%d.example.com", j), "example.com", "dummyValue", 10)
err := client.addTXTRecord(fmt.Sprintf("test%d.example.com.", j), "dummyValue", 10)
require.NoError(t, err)
wg.Done()
}(i, p)
@ -119,7 +119,7 @@ func TestDNSProvider_concurrentAddAndCleanupRecords(t *testing.T) {
wg.Wait()
updZone, err := providers[0].getHostedZone("example.com")
updZone, err := providers[0].getHostedZone("example.com.")
require.NoError(t, err)
require.NotNil(t, updZone)
@ -131,7 +131,7 @@ func TestDNSProvider_concurrentAddAndCleanupRecords(t *testing.T) {
for i, p := range providers {
go func(i int, client *DNSProvider) {
err := client.cleanupTXTRecord(fmt.Sprintf("test%d.example.com", i), "example.com", "dummyValue")
err := client.cleanupTXTRecord(fmt.Sprintf("test%d.example.com.", i), "dummyValue")
require.NoError(t, err)
wg.Done()
}(i, p)
@ -139,7 +139,7 @@ func TestDNSProvider_concurrentAddAndCleanupRecords(t *testing.T) {
wg.Wait()
updZone, err := providers[0].getHostedZone("example.com")
updZone, err := providers[0].getHostedZone("example.com.")
require.NoError(t, err)
require.NotNil(t, updZone)

View file

@ -109,7 +109,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
err := d.addTXTRecord(fqdn, domain, value, d.config.TTL)
err := d.addTXTRecord(fqdn, value, d.config.TTL)
if err != nil {
return fmt.Errorf("sakuracloud: %w", err)
}
@ -121,7 +121,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
err := d.cleanupTXTRecord(fqdn, domain, value)
err := d.cleanupTXTRecord(fqdn, value)
if err != nil {
return fmt.Errorf("sakuracloud: %w", err)
}

View file

@ -121,6 +121,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
Comment: scw.StringPtr("used by lego"),
}}
// TODO(ldez) replace domain by FQDN to follow CNAME.
req := &scwdomain.UpdateDNSZoneRecordsRequest{
DNSZone: domain,
Changes: []*scwdomain.RecordChange{{
@ -147,6 +148,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
Data: scw.StringPtr(fmt.Sprintf(`%q`, value)),
}
// TODO(ldez) replace domain by FQDN to follow CNAME.
req := &scwdomain.UpdateDNSZoneRecordsRequest{
DNSZone: domain,
Changes: []*scwdomain.RecordChange{{

View file

@ -103,6 +103,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
domainObj, err := d.client.GetDomainByName(domain)
if err != nil {
return fmt.Errorf("selectel: %w", err)
@ -127,6 +128,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
recordName := dns01.UnFqdn(fqdn)
// TODO(ldez) replace domain by FQDN to follow CNAME.
domainObj, err := d.client.GetDomainByName(domain)
if err != nil {
return fmt.Errorf("selectel: %w", err)

View file

@ -99,7 +99,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
authZone, err := getAuthZone(domain)
authZone, err := getAuthZone(fqdn)
if err != nil {
return fmt.Errorf("servercow: %w", err)
}
@ -152,7 +152,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
authZone, err := getAuthZone(domain)
authZone, err := getAuthZone(fqdn)
if err != nil {
return fmt.Errorf("servercow: %w", err)
}
@ -203,7 +203,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
}
func getAuthZone(domain string) (string, error) {
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return "", fmt.Errorf("could not find zone for domain %q: %w", domain, err)
}

View file

@ -91,8 +91,8 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
}
// Present creates a TXT record using the specified parameters.
func (d *DNSProvider) Present(domainName, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domainName, keyAuth)
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
err := d.client.SetRecord(dns01.UnFqdn(fqdn), value, d.config.TTL)
if err != nil {
@ -103,8 +103,8 @@ func (d *DNSProvider) Present(domainName, token, keyAuth string) error {
}
// CleanUp removes the TXT records matching the specified parameters.
func (d *DNSProvider) CleanUp(domainName, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domainName, keyAuth)
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
err := d.client.SetRecord(dns01.UnFqdn(fqdn), "_", d.config.TTL)
if err != nil {

View file

@ -50,8 +50,7 @@ func (e *ErrorResponse) Error() string {
// https://developer.stackpath.com/en/api/dns/#operation/GetZones
func (d *DNSProvider) getZones(domain string) (*Zone, error) {
domain = dns01.UnFqdn(domain)
tld, err := publicsuffix.EffectiveTLDPlusOne(domain)
tld, err := publicsuffix.EffectiveTLDPlusOne(dns01.UnFqdn(domain))
if err != nil {
return nil, err
}

View file

@ -113,13 +113,13 @@ func getOathClient(config *Config) *http.Client {
// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
zone, err := d.getZones(domain)
fqdn, value := dns01.GetRecord(domain, keyAuth)
zone, err := d.getZones(fqdn)
if err != nil {
return fmt.Errorf("stackpath: %w", err)
}
fqdn, value := dns01.GetRecord(domain, keyAuth)
record := Record{
Name: extractRecordName(fqdn, zone.Domain),
Type: "TXT",
@ -132,12 +132,13 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
zone, err := d.getZones(domain)
fqdn, _ := dns01.GetRecord(domain, keyAuth)
zone, err := d.getZones(fqdn)
if err != nil {
return fmt.Errorf("stackpath: %w", err)
}
fqdn, _ := dns01.GetRecord(domain, keyAuth)
recordName := extractRecordName(fqdn, zone.Domain)
records, err := d.getZoneRecords(recordName, zone)

View file

@ -32,7 +32,7 @@ func (d *DNSProvider) getHostedZone(domain string) (*dnspod.DomainListItem, erro
request.Offset = common.Int64Ptr(int64(len(domains)))
}
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return nil, err
}

View file

@ -114,7 +114,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zone, err := d.getHostedZone(domain)
zone, err := d.getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("tencentcloud: failed to get hosted zone: %w", err)
}
@ -145,7 +145,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
zone, err := d.getHostedZone(domain)
zone, err := d.getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("tencentcloud: failed to get hosted zone: %w", err)
}

View file

@ -105,7 +105,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("vercel: could not determine zone for domain %q: %w", domain, err)
}

View file

@ -139,6 +139,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("versio: %w", err)

View file

@ -103,6 +103,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
domainObj, err := d.client.GetDomainByName(domain)
if err != nil {
return fmt.Errorf("vscale: %w", err)
@ -127,6 +128,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
recordName := dns01.UnFqdn(fqdn)
// TODO(ldez) replace domain by FQDN to follow CNAME.
domainObj, err := d.client.GetDomainByName(domain)
if err != nil {
return fmt.Errorf("vscale: %w", err)

View file

@ -99,6 +99,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
zoneDomain, err := d.getHostedZone(ctx, domain)
if err != nil {
return fmt.Errorf("vultr: %w", err)
@ -127,6 +128,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
// TODO(ldez) replace domain by FQDN to follow CNAME.
zoneDomain, records, err := d.findTxtRecords(ctx, domain, fqdn)
if err != nil {
return fmt.Errorf("vultr: %w", err)

View file

@ -112,7 +112,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
Destination: value,
}
authZone, err := getHostedZone(domain)
authZone, err := getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("zoneee: %w", err)
}
@ -126,9 +126,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
// CleanUp removes the TXT record previously created.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
_, value := dns01.GetRecord(domain, keyAuth)
fqdn, value := dns01.GetRecord(domain, keyAuth)
authZone, err := getHostedZone(domain)
authZone, err := getHostedZone(fqdn)
if err != nil {
return fmt.Errorf("zoneee: %w", err)
}
@ -157,11 +157,10 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
}
func getHostedZone(domain string) (string, error) {
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
authZone, err := dns01.FindZoneByFqdn(domain)
if err != nil {
return "", err
}
zoneName := dns01.UnFqdn(authZone)
return zoneName, nil
return dns01.UnFqdn(authZone), nil
}