mirror of
https://github.com/go-acme/lego
synced 2026-03-14 22:45:48 +01:00
fix: TTL
This commit is contained in:
parent
e0dc04c421
commit
6a26d09c55
5 changed files with 26 additions and 9 deletions
|
|
@ -41,7 +41,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, internal.DefaultTTL),
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
HTTPClient: &http.Client{
|
||||
|
|
@ -118,7 +118,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||
zone.Records = append(zone.Records, internal.Record{
|
||||
Type: "TXT",
|
||||
Host: subDomain,
|
||||
TTL: d.config.TTL,
|
||||
TTL: internal.TTLRounder(d.config.TTL),
|
||||
RData: info.Value,
|
||||
Updated: true,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ lego --dns eurodns -d '*.example.com' -d example.com run
|
|||
EURODNS_APP_ID = "Application ID"
|
||||
EURODNS_API_KEY = "API key"
|
||||
[Configuration.Additional]
|
||||
EURODNS_POLLING_INTERVAL = "Time between DNS propagation check"
|
||||
EURODNS_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
|
||||
EURODNS_TTL = "The TTL of the TXT record used for the DNS challenge"
|
||||
EURODNS_HTTP_TIMEOUT = "API request timeout"
|
||||
EURODNS_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
|
||||
EURODNS_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)"
|
||||
EURODNS_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 600)"
|
||||
EURODNS_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)"
|
||||
|
||||
[Links]
|
||||
API = "https://docapi.eurodns.com/"
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ func NewClient(appID, apiKey string) (*Client, error) {
|
|||
}
|
||||
|
||||
// GetZone gets a DNS Zone.
|
||||
// https://docapi.eurodns.com/#/dnsprovider/getdnszone
|
||||
func (c *Client) GetZone(ctx context.Context, domain string) (*Zone, error) {
|
||||
endpoint := c.BaseURL.JoinPath(domain)
|
||||
|
||||
|
|
@ -66,6 +67,7 @@ func (c *Client) GetZone(ctx context.Context, domain string) (*Zone, error) {
|
|||
}
|
||||
|
||||
// SaveZone saves a DNS Zone.
|
||||
// https://docapi.eurodns.com/#/dnsprovider/savednszone
|
||||
func (c *Client) SaveZone(ctx context.Context, domain string, zone *Zone) error {
|
||||
endpoint := c.BaseURL.JoinPath(domain)
|
||||
|
||||
|
|
@ -78,6 +80,7 @@ func (c *Client) SaveZone(ctx context.Context, domain string, zone *Zone) error
|
|||
}
|
||||
|
||||
// ValidateZone validates DNS Zone.
|
||||
// https://docapi.eurodns.com/#/dnsprovider/checkdnszone
|
||||
func (c *Client) ValidateZone(ctx context.Context, domain string, zone *Zone) (*Zone, error) {
|
||||
endpoint := c.BaseURL.JoinPath(domain, "check")
|
||||
|
||||
|
|
@ -164,3 +167,17 @@ func parseError(req *http.Request, resp *http.Response) error {
|
|||
|
||||
return fmt.Errorf("%d: %w", resp.StatusCode, &errAPI)
|
||||
}
|
||||
|
||||
const DefaultTTL = 600
|
||||
|
||||
// TTLRounder rounds the given TTL in seconds to the next accepted value.
|
||||
// Accepted TTL values are: 600, 900, 1800,3600, 7200, 14400, 21600, 43200, 86400, 172800, 432000, 604800.
|
||||
func TTLRounder(ttl int) int {
|
||||
for _, validTTL := range []int{DefaultTTL, 900, 1800, 3600, 7200, 14400, 21600, 43200, 86400, 172800, 432000, 604800} {
|
||||
if ttl <= validTTL {
|
||||
return validTTL
|
||||
}
|
||||
}
|
||||
|
||||
return DefaultTTL
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func TestClient_SaveZone(t *testing.T) {
|
|||
Type: "TXT",
|
||||
Host: "_acme-challenge",
|
||||
RData: "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
|
||||
TTL: 120,
|
||||
TTL: 600,
|
||||
Updated: true,
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ func TestClient_ValidateZone(t *testing.T) {
|
|||
Type: "TXT",
|
||||
Host: "_acme-challenge",
|
||||
RData: "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
|
||||
TTL: 120,
|
||||
TTL: 600,
|
||||
Updated: true,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
{
|
||||
"type": "TXT",
|
||||
"host": "_acme-challenge",
|
||||
"ttl": 120,
|
||||
"ttl": 600,
|
||||
"rdata": "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
|
||||
"updated": true,
|
||||
"locked": false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue