forked from ZPascal/acme-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
challengeprovider.go
46 lines (38 loc) · 1.27 KB
/
challengeprovider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"context"
"strings"
"github.com/libdns/libdns"
log "github.com/sirupsen/logrus"
)
// ChallengeProvider implements go-acme/lego Provider interface which is used for ACME DNS challenge handling
type ChallengeProvider struct {
servers []*DNSServer
}
// NewChallengeProvider creates a new instance of ChallengeProvider
func NewChallengeProvider(servers []*DNSServer) ChallengeProvider {
return ChallengeProvider{servers: servers}
}
func (c *ChallengeProvider) AppendRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error) {
var token string
for _, item := range recs {
log.WithFields(log.Fields{"name": item.Name, "value": item.Value, "type": item.Type}).Info("Attempting to set dns record")
if strings.Contains(item.Name, "acme-challenge") {
token = item.Value
break
}
}
for _, s := range c.servers {
s.PersonalKeyAuth = token
}
return recs, nil
}
func (c *ChallengeProvider) DeleteRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error) {
for _, item := range recs {
log.WithFields(log.Fields{"name": item.Name, "value": item.Value, "type": item.Type}).Info("Attempting to unset dns record")
}
for _, s := range c.servers {
s.PersonalKeyAuth = ""
}
return recs, nil
}