diff --git a/providers/dns/azure/azure.go b/providers/dns/azure/azure.go index 521209ab..bb5a741d 100644 --- a/providers/dns/azure/azure.go +++ b/providers/dns/azure/azure.go @@ -41,6 +41,8 @@ const ( // Config is used to configure the creation of the DNSProvider. type Config struct { + ZoneName string + // optional if using instance metadata service ClientID string ClientSecret string @@ -63,6 +65,7 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ + ZoneName: env.GetOrFile(EnvZoneName), TTL: env.GetOrDefaultInt(EnvTTL, 60), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second), diff --git a/providers/dns/azure/private.go b/providers/dns/azure/private.go index e07af4e3..d6c9fc7b 100644 --- a/providers/dns/azure/private.go +++ b/providers/dns/azure/private.go @@ -11,7 +11,6 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/to" "github.com/go-acme/lego/v4/challenge/dns01" - "github.com/go-acme/lego/v4/platform/config/env" ) // dnsProviderPrivate implements the challenge.Provider interface for Azure Private Zone DNS. @@ -112,8 +111,8 @@ func (d *dnsProviderPrivate) CleanUp(domain, token, keyAuth string) error { // Checks that azure has a zone for this domain name. func (d *dnsProviderPrivate) getHostedZoneID(ctx context.Context, fqdn string) (string, error) { - if zone := env.GetOrFile(EnvZoneName); zone != "" { - return zone, nil + if d.config.ZoneName != "" { + return d.config.ZoneName, nil } authZone, err := dns01.FindZoneByFqdn(fqdn) diff --git a/providers/dns/azure/public.go b/providers/dns/azure/public.go index 66b458be..8e6fa182 100644 --- a/providers/dns/azure/public.go +++ b/providers/dns/azure/public.go @@ -11,7 +11,6 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/to" "github.com/go-acme/lego/v4/challenge/dns01" - "github.com/go-acme/lego/v4/platform/config/env" ) // dnsProviderPublic implements the challenge.Provider interface for Azure Public Zone DNS. @@ -112,8 +111,8 @@ func (d *dnsProviderPublic) CleanUp(domain, token, keyAuth string) error { // Checks that azure has a zone for this domain name. func (d *dnsProviderPublic) getHostedZoneID(ctx context.Context, fqdn string) (string, error) { - if zone := env.GetOrFile(EnvZoneName); zone != "" { - return zone, nil + if d.config.ZoneName != "" { + return d.config.ZoneName, nil } authZone, err := dns01.FindZoneByFqdn(fqdn) diff --git a/providers/dns/azuredns/azuredns.go b/providers/dns/azuredns/azuredns.go index bd87d950..765bd073 100644 --- a/providers/dns/azuredns/azuredns.go +++ b/providers/dns/azuredns/azuredns.go @@ -53,6 +53,8 @@ const ( // Config is used to configure the creation of the DNSProvider. type Config struct { + ZoneName string + SubscriptionID string ResourceGroup string PrivateZone bool @@ -83,6 +85,7 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ + ZoneName: env.GetOrFile(EnvZoneName), TTL: env.GetOrDefaultInt(EnvTTL, 60), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second), @@ -257,15 +260,18 @@ func (w *timeoutTokenCredential) GetToken(ctx context.Context, opts policy.Token return tk, err } -func getAuthZone(fqdn string) (string, error) { - authZone := env.GetOrFile(EnvZoneName) - if authZone != "" { - return authZone, nil +func getZoneName(config *Config, fqdn string) (string, error) { + if config.ZoneName != "" { + return config.ZoneName, nil } authZone, err := dns01.FindZoneByFqdn(fqdn) if err != nil { - return "", fmt.Errorf("could not find zone: %w", err) + return "", fmt.Errorf("could not find zone for %s: %w", fqdn, err) + } + + if authZone == "" { + return "", errors.New("empty zone name") } return authZone, nil diff --git a/providers/dns/azuredns/private.go b/providers/dns/azuredns/private.go index 516879f3..d31d20b0 100644 --- a/providers/dns/azuredns/private.go +++ b/providers/dns/azuredns/private.go @@ -125,7 +125,7 @@ func (d *DNSProviderPrivate) CleanUp(domain, _, keyAuth string) error { // Checks that azure has a zone for this domain name. func (d *DNSProviderPrivate) getHostedZone(fqdn string) (ServiceDiscoveryZone, error) { - authZone, err := getAuthZone(fqdn) + authZone, err := getZoneName(d.config, fqdn) if err != nil { return ServiceDiscoveryZone{}, err } diff --git a/providers/dns/azuredns/public.go b/providers/dns/azuredns/public.go index 0d0af53a..abe26970 100644 --- a/providers/dns/azuredns/public.go +++ b/providers/dns/azuredns/public.go @@ -124,7 +124,7 @@ func (d *DNSProviderPublic) CleanUp(domain, _, keyAuth string) error { // Checks that azure has a zone for this domain name. func (d *DNSProviderPublic) getHostedZone(fqdn string) (ServiceDiscoveryZone, error) { - authZone, err := getAuthZone(fqdn) + authZone, err := getZoneName(d.config, fqdn) if err != nil { return ServiceDiscoveryZone{}, err } diff --git a/providers/dns/bunny/bunny.go b/providers/dns/bunny/bunny.go index 276db09c..2cf7ea54 100644 --- a/providers/dns/bunny/bunny.go +++ b/providers/dns/bunny/bunny.go @@ -91,7 +91,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - authZone, err := getZone(info.EffectiveFQDN) + authZone, err := getZoneName(info.EffectiveFQDN) if err != nil { return fmt.Errorf("bunny: could not find zone for domain %q: %w", domain, err) } @@ -126,7 +126,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - authZone, err := getZone(info.EffectiveFQDN) + authZone, err := getZoneName(info.EffectiveFQDN) if err != nil { return fmt.Errorf("bunny: could not find zone for domain %q: %w", domain, err) } @@ -184,15 +184,13 @@ func (d *DNSProvider) findZone(ctx context.Context, authZone string) (*bunny.DNS return zone, nil } -func getZone(fqdn string) (string, error) { +func getZoneName(fqdn string) (string, error) { authZone, err := dns01.FindZoneByFqdn(fqdn) if err != nil { return "", err } - zone := dns01.UnFqdn(authZone) - - return zone, nil + return dns01.UnFqdn(authZone), nil } func pointer[T string | int | int32 | int64](v T) *T { return &v } diff --git a/providers/dns/desec/desec.go b/providers/dns/desec/desec.go index c86e0ceb..a8aee6ac 100644 --- a/providers/dns/desec/desec.go +++ b/providers/dns/desec/desec.go @@ -102,7 +102,6 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { ctx := context.Background() info := dns01.GetChallengeInfo(domain, keyAuth) - quotedValue := fmt.Sprintf(`%q`, info.Value) authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) if err != nil { @@ -116,6 +115,8 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { domainName := dns01.UnFqdn(authZone) + quotedValue := fmt.Sprintf(`%q`, info.Value) + rrSet, err := d.client.Records.Get(ctx, domainName, recordName, "TXT") if err != nil { var nf *desec.NotFoundError diff --git a/providers/dns/designate/designate.go b/providers/dns/designate/designate.go index b935c117..8b712b5a 100644 --- a/providers/dns/designate/designate.go +++ b/providers/dns/designate/designate.go @@ -46,6 +46,7 @@ const ( // Config is used to configure the creation of the DNSProvider. type Config struct { + ZoneName string PropagationTimeout time.Duration PollingInterval time.Duration TTL int @@ -55,6 +56,7 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ + ZoneName: env.GetOrFile(EnvZoneName), TTL: env.GetOrDefaultInt(EnvTTL, 10), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 10*time.Minute), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 10*time.Second), @@ -129,7 +131,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - zone, err := getAuthZone(info.EffectiveFQDN) + zone, err := d.getZoneName(info.EffectiveFQDN) if err != nil { return fmt.Errorf("designate: %w", err) } @@ -169,7 +171,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - zone, err := getAuthZone(info.EffectiveFQDN) + zone, err := d.getZoneName(info.EffectiveFQDN) if err != nil { return fmt.Errorf("designate: %w", err) } @@ -276,15 +278,18 @@ func (d *DNSProvider) getRecord(zoneID, wanted string) (*recordsets.RecordSet, e return nil, nil } -func getAuthZone(fqdn string) (string, error) { - authZone := env.GetOrFile(EnvZoneName) - if authZone != "" { - return authZone, nil +func (d *DNSProvider) getZoneName(fqdn string) (string, error) { + if d.config.ZoneName != "" { + return d.config.ZoneName, nil } authZone, err := dns01.FindZoneByFqdn(fqdn) if err != nil { - return "", fmt.Errorf("could not find zone: %w", err) + return "", fmt.Errorf("could not find zone for %s: %w", fqdn, err) + } + + if authZone == "" { + return "", errors.New("empty zone name") } return authZone, nil diff --git a/providers/dns/digitalocean/digitalocean.go b/providers/dns/digitalocean/digitalocean.go index 792c11f3..4ef8c061 100644 --- a/providers/dns/digitalocean/digitalocean.go +++ b/providers/dns/digitalocean/digitalocean.go @@ -112,7 +112,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(info.EffectiveFQDN)) + authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) if err != nil { return fmt.Errorf("digitalocean: could not find zone for domain %q: %w", domain, err) } diff --git a/providers/dns/directadmin/directadmin.go b/providers/dns/directadmin/directadmin.go index 5aab7086..5ce07b12 100644 --- a/providers/dns/directadmin/directadmin.go +++ b/providers/dns/directadmin/directadmin.go @@ -29,9 +29,12 @@ const ( // Config is used to configure the creation of the DNSProvider. type Config struct { - BaseURL string - Username string - Password string + BaseURL string + Username string + Password string + + ZoneName string + TTL int PropagationTimeout time.Duration PollingInterval time.Duration @@ -41,6 +44,7 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ + ZoneName: env.GetOrFile(EnvZoneName), TTL: env.GetOrDefaultInt(EnvTTL, 30), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 60*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second), @@ -95,7 +99,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - authZone, err := getAuthZone(info.EffectiveFQDN) + authZone, err := d.getZoneName(info.EffectiveFQDN) if err != nil { return fmt.Errorf("directadmin: [domain: %q] %w", domain, err) } @@ -124,7 +128,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - authZone, err := getAuthZone(info.EffectiveFQDN) + authZone, err := d.getZoneName(info.EffectiveFQDN) if err != nil { return fmt.Errorf("directadmin: [domain: %q] %w", domain, err) } @@ -148,10 +152,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } -func getAuthZone(fqdn string) (string, error) { - authZone := env.GetOrFile(EnvZoneName) - if authZone != "" { - return authZone, nil +func (d *DNSProvider) getZoneName(fqdn string) (string, error) { + if d.config.ZoneName != "" { + return d.config.ZoneName, nil } authZone, err := dns01.FindZoneByFqdn(fqdn) @@ -159,5 +162,9 @@ func getAuthZone(fqdn string) (string, error) { return "", fmt.Errorf("could not find zone for %s: %w", fqdn, err) } + if authZone == "" { + return "", errors.New("empty zone name") + } + return authZone, nil } diff --git a/providers/dns/hostingde/hostingde.go b/providers/dns/hostingde/hostingde.go index db886896..3b63bbfb 100644 --- a/providers/dns/hostingde/hostingde.go +++ b/providers/dns/hostingde/hostingde.go @@ -40,6 +40,7 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ + ZoneName: env.GetOrFile(EnvZoneName), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second), @@ -69,7 +70,6 @@ func NewDNSProvider() (*DNSProvider, error) { config := NewDefaultConfig() config.APIKey = values[EnvAPIKey] - config.ZoneName = env.GetOrFile(EnvZoneName) return NewDNSProviderConfig(config) } @@ -208,7 +208,7 @@ func (d *DNSProvider) getZoneName(fqdn string) (string, error) { zoneName, err := dns01.FindZoneByFqdn(fqdn) if err != nil { - return "", fmt.Errorf("could not find zone: %w", err) + return "", fmt.Errorf("could not find zone for %s: %w", fqdn, err) } if zoneName == "" { diff --git a/providers/dns/httpnet/httpnet.go b/providers/dns/httpnet/httpnet.go index 88a13f46..69f22e4b 100644 --- a/providers/dns/httpnet/httpnet.go +++ b/providers/dns/httpnet/httpnet.go @@ -41,6 +41,7 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ + ZoneName: env.GetOrFile(EnvZoneName), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second), @@ -70,7 +71,6 @@ func NewDNSProvider() (*DNSProvider, error) { config := NewDefaultConfig() config.APIKey = values[EnvAPIKey] - config.ZoneName = env.GetOrFile(EnvZoneName) return NewDNSProviderConfig(config) } @@ -212,7 +212,7 @@ func (d *DNSProvider) getZoneName(fqdn string) (string, error) { zoneName, err := dns01.FindZoneByFqdn(fqdn) if err != nil { - return "", fmt.Errorf("could not find zone: %w", err) + return "", fmt.Errorf("could not find zone for %s: %w", fqdn, err) } if zoneName == "" { diff --git a/providers/dns/ovh/ovh.go b/providers/dns/ovh/ovh.go index 287bd8c9..5b0893a4 100644 --- a/providers/dns/ovh/ovh.go +++ b/providers/dns/ovh/ovh.go @@ -150,7 +150,6 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - // Parse domain name authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) if err != nil { return fmt.Errorf("ovh: could not find zone for domain %q: %w", domain, err) diff --git a/providers/dns/servercow/servercow.go b/providers/dns/servercow/servercow.go index 3a8ae1f2..3db4ac45 100644 --- a/providers/dns/servercow/servercow.go +++ b/providers/dns/servercow/servercow.go @@ -217,8 +217,7 @@ func getAuthZone(domain string) (string, error) { return "", fmt.Errorf("could not find zone: %w", err) } - zoneName := dns01.UnFqdn(authZone) - return zoneName, nil + return dns01.UnFqdn(authZone), nil } func findRecords(records []internal.Record, name string) *internal.Record { diff --git a/providers/dns/zoneee/zoneee.go b/providers/dns/zoneee/zoneee.go index 59dd0baf..6a412a2c 100644 --- a/providers/dns/zoneee/zoneee.go +++ b/providers/dns/zoneee/zoneee.go @@ -119,11 +119,6 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - record := internal.TXTRecord{ - Name: dns01.UnFqdn(info.EffectiveFQDN), - Destination: info.Value, - } - authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) if err != nil { return fmt.Errorf("zoneee: could not find zone for domain %q: %w", domain, err) @@ -131,6 +126,11 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { authZone = dns01.UnFqdn(authZone) + record := internal.TXTRecord{ + Name: dns01.UnFqdn(info.EffectiveFQDN), + Destination: info.Value, + } + _, err = d.client.AddTxtRecord(context.Background(), authZone, record) if err != nil { return fmt.Errorf("zoneee: %w", err)