diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index 2859afd9b..24a2470bb 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -472,7 +472,7 @@ func displayDNSHelp(w io.Writer, name string) error { ew.writeln(`Additional Configuration:`) ew.writeln(` - "BAIDUCLOUD_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 2)`) ew.writeln(` - "BAIDUCLOUD_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 60)`) - ew.writeln(` - "BAIDUCLOUD_TTL": The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)`) + ew.writeln(` - "BAIDUCLOUD_TTL": The TTL of the TXT record used for the DNS challenge in seconds (Default: 300)`) ew.writeln() ew.writeln(`More information: https://go-acme.github.io/lego/dns/baiducloud`) diff --git a/docs/content/dns/zz_gen_baiducloud.md b/docs/content/dns/zz_gen_baiducloud.md index 11a71c1ab..9f59aa156 100644 --- a/docs/content/dns/zz_gen_baiducloud.md +++ b/docs/content/dns/zz_gen_baiducloud.md @@ -51,7 +51,7 @@ More information [here]({{% ref "dns#configuration-and-credentials" %}}). |--------------------------------|-------------| | `BAIDUCLOUD_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 2) | | `BAIDUCLOUD_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 60) | -| `BAIDUCLOUD_TTL` | The TTL of the TXT record used for the DNS challenge in seconds (Default: 120) | +| `BAIDUCLOUD_TTL` | The TTL of the TXT record used for the DNS challenge in seconds (Default: 300) | The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. More information [here]({{% ref "dns#configuration-and-credentials" %}}). diff --git a/providers/dns/baiducloud/baiducloud.go b/providers/dns/baiducloud/baiducloud.go index fc317904a..1dc8d90ed 100644 --- a/providers/dns/baiducloud/baiducloud.go +++ b/providers/dns/baiducloud/baiducloud.go @@ -24,6 +24,9 @@ const ( EnvPollingInterval = envNamespace + "POLLING_INTERVAL" ) +// 300 is the minimum TTL for free users. +const defaultTTL = 300 + // Config is used to configure the creation of the DNSProvider. type Config struct { AccessKeyID string @@ -37,7 +40,7 @@ type Config struct { // NewDefaultConfig returns a default configuration for the DNSProvider. func NewDefaultConfig() *Config { return &Config{ - TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL), + TTL: env.GetOrDefaultInt(EnvTTL, defaultTTL), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval), } @@ -103,6 +106,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { Rr: subDomain, Type: "TXT", Value: info.Value, + Ttl: ptr.Pointer(int32(d.config.TTL)), } err = d.client.CreateRecord(dns01.UnFqdn(authZone), crr, "") @@ -122,14 +126,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return fmt.Errorf("baiducloud: could not find zone for domain %q: %w", domain, err) } - lrr := &baidudns.ListRecordRequest{} - - recordResponse, err := d.client.ListRecord(dns01.UnFqdn(authZone), lrr) - if err != nil { - return fmt.Errorf("baiducloud: list record: %w", err) - } - - recordID, err := findRecordID(recordResponse, info) + recordID, err := d.findRecordID(dns01.UnFqdn(authZone), info.Value) if err != nil { return fmt.Errorf("baiducloud: find record: %w", err) } @@ -142,11 +139,26 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } -func findRecordID(recordResponse *baidudns.ListRecordResponse, info dns01.ChallengeInfo) (string, error) { - for _, record := range recordResponse.Records { - if record.Type == "TXT" && record.Value == info.Value { - return record.Id, nil +func (d *DNSProvider) findRecordID(zoneName, tokenValue string) (string, error) { + lrr := &baidudns.ListRecordRequest{} + + for { + recordResponse, err := d.client.ListRecord(zoneName, lrr) + if err != nil { + return "", fmt.Errorf("baiducloud: list record: %w", err) } + + for _, record := range recordResponse.Records { + if record.Type == "TXT" && record.Value == tokenValue { + return record.Id, nil + } + } + + if !recordResponse.IsTruncated { + break + } + + lrr.Marker = recordResponse.NextMarker } return "", errors.New("record not found") diff --git a/providers/dns/baiducloud/baiducloud.toml b/providers/dns/baiducloud/baiducloud.toml index 941d90b2c..8422eafd5 100644 --- a/providers/dns/baiducloud/baiducloud.toml +++ b/providers/dns/baiducloud/baiducloud.toml @@ -17,7 +17,7 @@ lego --email you@example.com --dns baiducloud -d '*.example.com' -d example.com [Configuration.Additional] BAIDUCLOUD_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)" BAIDUCLOUD_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)" - BAIDUCLOUD_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)" + BAIDUCLOUD_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 300)" [Links] API = "https://cloud.baidu.com/doc/DNS/s/El4s7lssr"