Browse Source

dns: DefaultDNSProvider() using CLOUDFLARE_DNS_API_TOKEN

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/24/head
Alejandro Mery 1 year ago
parent
commit
00aec477a4
  1. 1
      go.mod
  2. 3
      go.sum
  3. 36
      pkg/dns/provider.go

1
go.mod

@ -11,6 +11,7 @@ require (
darvaza.org/slog/handlers/discard v0.4.5
github.com/gofrs/uuid/v5 v5.0.0
github.com/hack-pad/hackpadfs v0.2.1
github.com/libdns/cloudflare v0.1.0
github.com/libdns/libdns v0.2.1
github.com/mgechev/revive v1.3.3
github.com/spf13/cobra v1.7.0

3
go.sum

@ -36,6 +36,9 @@ github.com/hack-pad/hackpadfs v0.2.1 h1:FelFhIhv26gyjujoA/yeFO+6YGlqzmc9la/6iKMI
github.com/hack-pad/hackpadfs v0.2.1/go.mod h1:khQBuCEwGXWakkmq8ZiFUvUZz84ZkJ2KNwKvChs4OrU=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/libdns/cloudflare v0.1.0 h1:93WkJaGaiXCe353LHEP36kAWCUw0YjFqwhkBkU2/iic=
github.com/libdns/cloudflare v0.1.0/go.mod h1:a44IP6J1YH6nvcNl1PverfJviADgXUnsozR3a7vBKN8=
github.com/libdns/libdns v0.2.0/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis=
github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=

36
pkg/dns/provider.go

@ -0,0 +1,36 @@
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
}
Loading…
Cancel
Save