mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
baiducloud: pagination and TTL (#2712)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
877738cef3
commit
b338263c96
4 changed files with 28 additions and 16 deletions
2
cmd/zz_gen_cmd_dnshelp.go
generated
2
cmd/zz_gen_cmd_dnshelp.go
generated
|
|
@ -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`)
|
||||
|
|
|
|||
2
docs/content/dns/zz_gen_baiducloud.md
generated
2
docs/content/dns/zz_gen_baiducloud.md
generated
|
|
@ -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" %}}).
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue