Skip to content

Commit

Permalink
fix: add missing TTL configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Aug 29, 2024
1 parent 371ca22 commit c8b0487
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion providers/dns/mittwald/mittwald.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ const (

EnvToken = envNamespace + "TOKEN"

EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
)

const minTTL = 300

// Config is used to configure the creation of the DNSProvider.
type Config struct {
Token string
TTL int
PropagationTimeout time.Duration
PollingInterval time.Duration
HTTPClient *http.Client
Expand All @@ -37,6 +41,7 @@ type Config struct {
// NewDefaultConfig returns a default configuration for the DNSProvider.
func NewDefaultConfig() *Config {
return &Config{
TTL: env.GetOrDefaultInt(EnvTTL, minTTL),
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{
Expand Down Expand Up @@ -78,6 +83,10 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
return nil, errors.New("mittwald: some credentials information are missing")
}

if config.TTL < minTTL {
return nil, fmt.Errorf("mittwald: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}

return &DNSProvider{
config: config,
client: internal.NewClient(config.Token),
Expand All @@ -103,7 +112,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {

record := internal.TXTRecord{
Settings: internal.Settings{
TTL: internal.TTL{Auto: true},
TTL: internal.TTL{Seconds: d.config.TTL},
},
Entries: []string{info.Value},
}
Expand Down
11 changes: 11 additions & 0 deletions providers/dns/mittwald/mittwald_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
testCases := []struct {
desc string
token string
ttl int
expected string
}{
{
Expand All @@ -68,13 +69,23 @@ func TestNewDNSProviderConfig(t *testing.T) {
desc: "missing credentials",
expected: "mittwald: some credentials information are missing",
},
{
desc: "invalid TTL",
token: "secret",
ttl: 10,
expected: "mittwald: invalid TTL, TTL (10) must be greater than 300",
},
}

for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
config.Token = test.token

if test.ttl > 0 {
config.TTL = test.ttl
}

p, err := NewDNSProviderConfig(config)

if test.expected == "" {
Expand Down

0 comments on commit c8b0487

Please sign in to comment.