Skip to content

Commit

Permalink
chore: cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Sep 19, 2024
1 parent 4aa1c3b commit 8007292
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/content/dns/zz_gen_selfhostde.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 19 additions & 18 deletions providers/dns/selfhostde/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions providers/dns/selfhostde/selfhostde.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/selfhostde/selfhostde.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions providers/dns/selfhostde/selfhostde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 8007292

Please sign in to comment.