caddy-dns01/caddyapp/stub.go

50 lines
1.2 KiB
Go
Raw Normal View History

2026-02-15 13:16:23 +01:00
package caddydns01
2023-02-25 10:30:08 +01:00
import (
"strconv"
2023-02-25 10:49:47 +01:00
2023-02-25 11:21:28 +01:00
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/libdns/libdns"
2023-02-25 10:49:47 +01:00
"github.com/miekg/dns"
2023-02-25 10:30:08 +01:00
)
// An in-process request to create or delete a DNS record
type request struct {
append bool
zone string
records []dns.RR
responder chan error
2023-02-25 10:30:08 +01:00
}
func init() {
caddy.RegisterModule(App{})
caddy.RegisterModule(Provider{})
2026-02-16 23:29:45 +01:00
httpcaddyfile.RegisterGlobalOption("dns01", parseApp)
}
func record_to_rr(zone string, record libdns.Record) (dns.RR, error) {
2026-02-15 15:21:12 +01:00
/*
maybe_priority := ""
if record.Priority != 0 {
maybe_priority += strconv.FormatInt(int64(record.Priority), 10)
maybe_priority += " "
}
*/
//TODO: consider fixing this with dns.StringToType & dns.TypeToRR
// Problem is putting the value in, since it will be a different field
// for every type.
// Also, will probably require parsing the value anyway (e.g. to net.IP)
//TODO: does the value need to be escaped?!
return dns.NewRR(
2026-02-15 15:21:12 +01:00
dns.Fqdn(record.RR().Name+"."+zone) +
" " +
2026-02-15 15:21:12 +01:00
strconv.FormatInt(int64(record.RR().TTL.Seconds()), 10) +
" IN " +
2026-02-15 15:21:12 +01:00
record.RR().Type +
" " +
2026-02-15 15:21:12 +01:00
// maybe_priority +
record.RR().Data)
2023-02-25 10:49:47 +01:00
}