You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
695 B
37 lines
695 B
1 year ago
|
package dns
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
|
||
|
"github.com/libdns/cloudflare"
|
||
|
"github.com/libdns/libdns"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
// CloudflareAPIToken is the environment variable
|
||
|
// containing the API Token
|
||
|
CloudflareAPIToken = "CLOUDFLARE_DNS_API_TOKEN"
|
||
|
)
|
||
|
|
||
|
// Provider manages DNS entries
|
||
|
type Provider interface {
|
||
|
libdns.RecordGetter
|
||
|
libdns.RecordDeleter
|
||
|
}
|
||
|
|
||
|
// DefaultDNSProvider returns a cloudflare DNS provider
|
||
|
// using an API Token from env [CloudflareAPIToken]
|
||
|
func DefaultDNSProvider() (*cloudflare.Provider, error) {
|
||
|
s := os.Getenv(CloudflareAPIToken)
|
||
|
if s == "" {
|
||
|
return nil, fmt.Errorf("%q: %s", CloudflareAPIToken, "not found")
|
||
|
}
|
||
|
|
||
|
p := &cloudflare.Provider{
|
||
|
APIToken: s,
|
||
|
}
|
||
|
|
||
|
return p, nil
|
||
|
}
|