Skip to content

Commit fae73fd

Browse files
eusouovhldez
andauthored
vinyldns: add an option to add quotes around the TXT record value (#2580)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent bfa487c commit fae73fd

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/dns/zz_gen_vinyldns.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

providers/dns/vinyldns/vinyldns.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package vinyldns
44
import (
55
"errors"
66
"fmt"
7+
"strconv"
78
"time"
89

910
"github.com/go-acme/lego/v4/challenge"
@@ -17,9 +18,10 @@ import (
1718
const (
1819
envNamespace = "VINYLDNS_"
1920

20-
EnvAccessKey = envNamespace + "ACCESS_KEY"
21-
EnvSecretKey = envNamespace + "SECRET_KEY"
22-
EnvHost = envNamespace + "HOST"
21+
EnvAccessKey = envNamespace + "ACCESS_KEY"
22+
EnvSecretKey = envNamespace + "SECRET_KEY"
23+
EnvHost = envNamespace + "HOST"
24+
EnvQuoteValue = envNamespace + "QUOTE_VALUE"
2325

2426
EnvTTL = envNamespace + "TTL"
2527
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
@@ -30,9 +32,11 @@ var _ challenge.ProviderTimeout = (*DNSProvider)(nil)
3032

3133
// Config is used to configure the creation of the DNSProvider.
3234
type Config struct {
33-
AccessKey string
34-
SecretKey string
35-
Host string
35+
AccessKey string
36+
SecretKey string
37+
Host string
38+
QuoteValue bool
39+
3640
TTL int
3741
PropagationTimeout time.Duration
3842
PollingInterval time.Duration
@@ -66,6 +70,7 @@ func NewDNSProvider() (*DNSProvider, error) {
6670
config.AccessKey = values[EnvAccessKey]
6771
config.SecretKey = values[EnvSecretKey]
6872
config.Host = values[EnvHost]
73+
config.QuoteValue = env.GetOrDefaultBool(EnvQuoteValue, false)
6974

7075
return NewDNSProviderConfig(config)
7176
}
@@ -105,7 +110,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
105110
return fmt.Errorf("vinyldns: %w", err)
106111
}
107112

108-
record := vinyldns.Record{Text: info.Value}
113+
value := d.formatValue(info.Value)
114+
115+
record := vinyldns.Record{Text: value}
109116

110117
if existingRecord == nil || existingRecord.ID == "" {
111118
err = d.createRecordSet(info.EffectiveFQDN, []vinyldns.Record{record})
@@ -117,7 +124,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
117124
}
118125

119126
for _, i := range existingRecord.Records {
120-
if i.Text == info.Value {
127+
if i.Text == value {
121128
return nil
122129
}
123130
}
@@ -146,9 +153,11 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
146153
return nil
147154
}
148155

156+
value := d.formatValue(info.Value)
157+
149158
var records []vinyldns.Record
150159
for _, i := range existingRecord.Records {
151-
if i.Text != info.Value {
160+
if i.Text != value {
152161
records = append(records, i)
153162
}
154163
}
@@ -175,3 +184,11 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
175184
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
176185
return d.config.PropagationTimeout, d.config.PollingInterval
177186
}
187+
188+
func (d *DNSProvider) formatValue(v string) string {
189+
if d.config.QuoteValue {
190+
return strconv.Quote(v)
191+
}
192+
193+
return v
194+
}

providers/dns/vinyldns/vinyldns.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Users are required to have DELETE ACL level or zone admin permissions on the Vin
2222
VINYLDNS_SECRET_KEY = "The VinylDNS API Secret key"
2323
VINYLDNS_HOST = "The VinylDNS API URL"
2424
[Configuration.Additional]
25+
VINYLDNS_QUOTE_VALUE = "Adds quotes around the TXT record value (Default: false)"
2526
VINYLDNS_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 4)"
2627
VINYLDNS_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 120)"
2728
VINYLDNS_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 30)"

0 commit comments

Comments
 (0)