diff --git a/docs/content/dns/zz_gen_selfhostde.md b/docs/content/dns/zz_gen_selfhostde.md index ad18cd92dc9..62c5838db7e 100644 --- a/docs/content/dns/zz_gen_selfhostde.md +++ b/docs/content/dns/zz_gen_selfhostde.md @@ -61,7 +61,7 @@ More information [here]({{% ref "dns#configuration-and-credentials" %}}). SelfHost.de doesn't have an API to create or delete TXT records, there is only an "unofficial" and undocumented endpoint to update an existing TXT record. -So,bBefore using lego to request a certificate for a given domain or wildcard (such as `my.example.org` or `*.my.example.org`), +So, before using lego to request a certificate for a given domain or wildcard (such as `my.example.org` or `*.my.example.org`), you should create: - one TXT record named `_acme-challenge.my.example.org` if you are **not** using wildcard for this domain. - two TXT records named `_acme-challenge.my.example.org` if you are using wildcard for this domain. diff --git a/providers/dns/selfhostde/mapping.go b/providers/dns/selfhostde/mapping.go index 10964cd325e..0984419ef9f 100644 --- a/providers/dns/selfhostde/mapping.go +++ b/providers/dns/selfhostde/mapping.go @@ -36,35 +36,36 @@ func (s *Seq) Next() string { return v } -func parseRecordsMapping(v string) (map[string]*Seq, error) { - v = strings.ReplaceAll(v, " ", "") +func parseRecordsMapping(raw string) (map[string]*Seq, error) { + raw = strings.ReplaceAll(raw, " ", "") - if v == "" { + if raw == "" { return nil, errors.New("empty mapping") } acc := map[string]*Seq{} for { - index, err := safeIndex(v, lineSep) + index, err := safeIndex(raw, lineSep) if err != nil { return nil, err } if index != -1 { - name, seq, err := parseLine(v[:index]) + name, seq, err := parseLine(raw[:index]) if err != nil { return nil, err } acc[name] = seq - v = v[index+1:] + // Data for the next iteration. + raw = raw[index+1:] continue } - name, seq, errP := parseLine(v) + name, seq, errP := parseLine(raw) if errP != nil { return nil, errP } @@ -85,8 +86,7 @@ func parseLine(line string) (string, *Seq, error) { return "", nil, fmt.Errorf("missing %q: %s", recordSep, line) } - name := line[:idx] - rawIDs := line[idx+1:] + name, rawIDs := line[:idx], line[idx+1:] var ids []string var count int @@ -101,19 +101,20 @@ func parseLine(line string) (string, *Seq, error) { return "", nil, fmt.Errorf("too many record IDs for one domain: %s", line) } - if idx == -1 { - ids = append(ids, rawIDs) - break + if idx != -1 { + ids = append(ids, rawIDs[:idx]) + count++ + + // Data for the next iteration. + rawIDs = rawIDs[idx+1:] + + continue } - ids = append(ids, rawIDs[:idx]) - count++ + ids = append(ids, rawIDs) - // Data for the next iteration. - rawIDs = rawIDs[idx+1:] + return name, NewSeq(ids...), nil } - - return name, NewSeq(ids...), nil } func safeIndex(v, sep string) (int, error) { diff --git a/providers/dns/selfhostde/selfhostde.go b/providers/dns/selfhostde/selfhostde.go index a46e50e2017..32428766534 100644 --- a/providers/dns/selfhostde/selfhostde.go +++ b/providers/dns/selfhostde/selfhostde.go @@ -66,7 +66,7 @@ func (c *Config) getSeqNext(domain string) (string, error) { // fallback seq, ok = c.RecordsMapping[domain] if !ok { - return "", fmt.Errorf("record mapping not found for %s", effectiveDomain) + return "", fmt.Errorf("record mapping not found for %q", effectiveDomain) } } @@ -119,7 +119,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { for domain, seq := range config.RecordsMapping { if seq == nil || len(seq.ids) == 0 { - return nil, fmt.Errorf("selfhostde: missing record ID for %s", domain) + return nil, fmt.Errorf("selfhostde: missing record ID for %q", domain) } } @@ -167,13 +167,11 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { info := dns01.GetChallengeInfo(domain, keyAuth) - effectiveDomain := strings.TrimPrefix(info.EffectiveFQDN, "_acme-challenge.") - d.recordIDsMu.Lock() recordID, ok := d.recordIDs[token] d.recordIDsMu.Unlock() if !ok { - return fmt.Errorf("selfhostde: unknown record ID for '%s'", effectiveDomain) + return fmt.Errorf("selfhostde: unknown record ID for %q", dns01.UnFqdn(info.EffectiveFQDN)) } err := d.client.UpdateTXTRecord(context.Background(), recordID, "empty") diff --git a/providers/dns/selfhostde/selfhostde.toml b/providers/dns/selfhostde/selfhostde.toml index 51066e517c3..b9567dc2066 100644 --- a/providers/dns/selfhostde/selfhostde.toml +++ b/providers/dns/selfhostde/selfhostde.toml @@ -14,7 +14,7 @@ lego --email you@example.com --dns selfhostde --domains my.example.org run Additional = """ SelfHost.de doesn't have an API to create or delete TXT records, there is only an "unofficial" and undocumented endpoint to update an existing TXT record. -So,bBefore using lego to request a certificate for a given domain or wildcard (such as `my.example.org` or `*.my.example.org`), +So, before using lego to request a certificate for a given domain or wildcard (such as `my.example.org` or `*.my.example.org`), you should create: - one TXT record named `_acme-challenge.my.example.org` if you are **not** using wildcard for this domain. - two TXT records named `_acme-challenge.my.example.org` if you are using wildcard for this domain. diff --git a/providers/dns/selfhostde/selfhostde_test.go b/providers/dns/selfhostde/selfhostde_test.go index 4e0be50f64e..1161049b072 100644 --- a/providers/dns/selfhostde/selfhostde_test.go +++ b/providers/dns/selfhostde/selfhostde_test.go @@ -128,7 +128,7 @@ func TestNewDNSProviderConfig(t *testing.T) { recordMapping: map[string]*Seq{ "example.com": nil, }, - expected: "selfhostde: missing record ID for example.com", + expected: `selfhostde: missing record ID for "example.com"`, }, { desc: "empty sequence", @@ -137,7 +137,7 @@ func TestNewDNSProviderConfig(t *testing.T) { recordMapping: map[string]*Seq{ "example.com": NewSeq(), }, - expected: "selfhostde: missing record ID for example.com", + expected: `selfhostde: missing record ID for "example.com"`, }, { desc: "missing records mapping",