mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-25 16:13:04 +08:00
CLOUDFLARE: Stop requiring accountname (#1280)
There is no API call I've found that requires it, only the accountID. Also, we now set the cfClient.AccountID similar to b55278140f
(h/t @fdcastel) and no longer store duplicate information in the cfClient and api objects.
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
parent
413d5a15c3
commit
d08a8f6c4e
3 changed files with 8 additions and 17 deletions
|
@ -43,7 +43,6 @@ If your Cloudflare account has access to multiple Cloudflare accounts, you can s
|
||||||
"cloudflare": {
|
"cloudflare": {
|
||||||
"apitoken": "...",
|
"apitoken": "...",
|
||||||
"accountid": "your-cloudflare-account-id",
|
"accountid": "your-cloudflare-account-id",
|
||||||
"accountname": "your-cloudflare-account-name"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
|
@ -25,7 +25,6 @@ Info required in `creds.json`:
|
||||||
- apikey
|
- apikey
|
||||||
- apiuser
|
- apiuser
|
||||||
- accountid (optional)
|
- accountid (optional)
|
||||||
- accountname (optional)
|
|
||||||
|
|
||||||
Record level metadata available:
|
Record level metadata available:
|
||||||
- cloudflare_proxy ("on", "off", or "full")
|
- cloudflare_proxy ("on", "off", or "full")
|
||||||
|
@ -63,11 +62,6 @@ func init() {
|
||||||
|
|
||||||
// cloudflareProvider is the handle for API calls.
|
// cloudflareProvider is the handle for API calls.
|
||||||
type cloudflareProvider struct {
|
type cloudflareProvider struct {
|
||||||
APIKey string `json:"apikey"`
|
|
||||||
APIToken string `json:"apitoken"`
|
|
||||||
APIUser string `json:"apiuser"`
|
|
||||||
AccountID string `json:"accountid"`
|
|
||||||
AccountName string `json:"accountname"`
|
|
||||||
domainIndex map[string]string
|
domainIndex map[string]string
|
||||||
nameservers map[string][]string
|
nameservers map[string][]string
|
||||||
ipConversions []transform.IPConversion
|
ipConversions []transform.IPConversion
|
||||||
|
@ -450,20 +444,19 @@ func (c *cloudflareProvider) preprocessConfig(dc *models.DomainConfig) error {
|
||||||
|
|
||||||
func newCloudflare(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
|
func newCloudflare(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
|
||||||
api := &cloudflareProvider{}
|
api := &cloudflareProvider{}
|
||||||
api.APIUser, api.APIKey, api.APIToken = m["apiuser"], m["apikey"], m["apitoken"]
|
|
||||||
// check api keys from creds json file
|
// check api keys from creds json file
|
||||||
if api.APIToken == "" && (api.APIKey == "" || api.APIUser == "") {
|
if m["apitoken"] == "" && (m["apikey"] == "" || m["apiuser"] == "") {
|
||||||
return nil, fmt.Errorf("if cloudflare apitoken is not set, apikey and apiuser must be provided")
|
return nil, fmt.Errorf("if cloudflare apitoken is not set, apikey and apiuser must be provided")
|
||||||
}
|
}
|
||||||
if api.APIToken != "" && (api.APIKey != "" || api.APIUser != "") {
|
if m["apitoken"] != "" && (m["apikey"] != "" || m["apiuser"] != "") {
|
||||||
return nil, fmt.Errorf("if cloudflare apitoken is set, apikey and apiuser should not be provided")
|
return nil, fmt.Errorf("if cloudflare apitoken is set, apikey and apiuser should not be provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if api.APIToken != "" {
|
if m["apitoken"] != "" {
|
||||||
api.cfClient, err = cloudflare.NewWithAPIToken(api.APIToken)
|
api.cfClient, err = cloudflare.NewWithAPIToken(m["apitoken"])
|
||||||
} else {
|
} else {
|
||||||
api.cfClient, err = cloudflare.New(api.APIKey, api.APIUser)
|
api.cfClient, err = cloudflare.New(m["apikey"], m["apiuser"])
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -471,9 +464,8 @@ func newCloudflare(m map[string]string, metadata json.RawMessage) (providers.DNS
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check account data if set
|
// Check account data if set
|
||||||
api.AccountID, api.AccountName = m["accountid"], m["accountname"]
|
if m["accountid"] != "" {
|
||||||
if (api.AccountID != "" && api.AccountName == "") || (api.AccountID == "" && api.AccountName != "") {
|
api.cfClient.AccountID = m["accountid"]
|
||||||
return nil, fmt.Errorf("either both cloudflare accountid and accountname must be provided or neither")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(metadata) > 0 {
|
if len(metadata) > 0 {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (c *cloudflareProvider) deleteRec(rec cloudflare.DNSRecord, domainID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cloudflareProvider) createZone(domainName string) (string, error) {
|
func (c *cloudflareProvider) createZone(domainName string) (string, error) {
|
||||||
zone, err := c.cfClient.CreateZone(context.Background(), domainName, false, cloudflare.Account{Name: c.AccountName, ID: c.AccountID}, "full")
|
zone, err := c.cfClient.CreateZone(context.Background(), domainName, false, cloudflare.Account{ID: c.cfClient.AccountID}, "full")
|
||||||
return zone.ID, err
|
return zone.ID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue