Skip to content

Commit

Permalink
cloudflare: support reading API token from file
Browse files Browse the repository at this point in the history
  • Loading branch information
cxuu committed Apr 18, 2023
1 parent eaabf71 commit 91cd518
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion provider/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package cloudflare
import (
"context"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"

cloudflare "github.com/cloudflare/cloudflare-go"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -155,7 +157,15 @@ func NewCloudFlareProvider(domainFilter endpoint.DomainFilter, zoneIDFilter prov
err error
)
if os.Getenv("CF_API_TOKEN") != "" {
config, err = cloudflare.NewWithAPIToken(os.Getenv("CF_API_TOKEN"))
token := os.Getenv("CF_API_TOKEN")
if strings.HasPrefix(token, "file:") {
tokenBytes, err := ioutil.ReadFile(strings.TrimPrefix(token, "file:"))
if err != nil {
return nil, fmt.Errorf("failed to read CF_API_TOKEN from file: %v", err)
}
token = string(tokenBytes)
}
config, err = cloudflare.NewWithAPIToken(token)
} else {
config, err = cloudflare.New(os.Getenv("CF_API_KEY"), os.Getenv("CF_API_EMAIL"))
}
Expand Down

0 comments on commit 91cd518

Please sign in to comment.