Skip to content

Commit

Permalink
- fixed issues with auth when making calls to cloudflare api
Browse files Browse the repository at this point in the history
  • Loading branch information
maZahaca committed Apr 15, 2021
1 parent 2ecf44f commit f8e9983
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func (c CloudflareProvider) AddRecord(record string, ip string) error {
return err
}

rec := cloudflare.DNSRecord{Name: record, Content: ip}
proxied := true
rec := cloudflare.DNSRecord{Type: "A", Name: record, Content: ip, Proxied: &proxied, ZoneID: c.ZoneId}
_, err = c.API.CreateDNSRecord(context.Background(), c.ZoneId, rec)

return err
Expand All @@ -49,7 +50,7 @@ func (c CloudflareProvider) RemoveRecord(record string, ip string) error {
}

func (c CloudflareProvider) getRecord(record string) (r *cloudflare.DNSRecord, err error) {
filter := cloudflare.DNSRecord{Name: record}
filter := cloudflare.DNSRecord{Name: record, ZoneID: c.ZoneId}
recs, err := c.API.DNSRecords(context.Background(), c.ZoneId, filter)
if len(recs) == 0 || err != nil {
return nil, err
Expand All @@ -60,10 +61,9 @@ func (c CloudflareProvider) getRecord(record string) (r *cloudflare.DNSRecord, e

func NewDnsProvider() (IDnsProvider, error) {
cloudflareToken := os.Getenv("CF_TOKEN")
cloudflareAccount := os.Getenv("CF_ACCOUNT_EMAIL")
cloudflareZone := os.Getenv("CF_ZONE_ID")
if cloudflareToken != "" && cloudflareAccount != "" && cloudflareZone != "" {
api, err := cloudflare.New(cloudflareToken, cloudflareAccount)
if cloudflareToken != "" && cloudflareZone != "" {
api, err := cloudflare.NewWithAPIToken(cloudflareToken)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit f8e9983

Please sign in to comment.