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.
38 lines
739 B
38 lines
739 B
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 |
|
libdns.RecordSetter |
|
libdns.RecordAppender |
|
} |
|
|
|
// 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 |
|
}
|
|
|