mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-09-05 04:34:32 +08:00
CLOUDFLARE: Added options to set the target account for new domains (#430)
This commit is contained in:
parent
133b7e6414
commit
5594904f3d
3 changed files with 34 additions and 0 deletions
|
@ -18,6 +18,19 @@ In the credentials file you must provide your Cloudflare API username and access
|
|||
}
|
||||
{% endhighlight %}
|
||||
|
||||
If your Cloudflare account has access to multiple Cloudflare accounts, you can specify which Cloudflare account should be used when adding new domains:
|
||||
|
||||
{% highlight json %}
|
||||
{
|
||||
"cloudflare": {
|
||||
"apikey": "...",
|
||||
"apiuser": "...",
|
||||
"accountid": "your-cloudflare-account-id",
|
||||
"accountname": "your-cloudflare-account-name"
|
||||
}
|
||||
}
|
||||
{% endhighlight %}
|
||||
|
||||
## Metadata
|
||||
Record level metadata availible:
|
||||
* `cloudflare_proxy` ("on", "off", or "full")
|
||||
|
|
|
@ -24,6 +24,8 @@ Cloudflare API DNS provider:
|
|||
Info required in `creds.json`:
|
||||
- apikey
|
||||
- apiuser
|
||||
- accountid (optional)
|
||||
- accountname (optional)
|
||||
|
||||
Record level metadata available:
|
||||
- cloudflare_proxy ("on", "off", or "full")
|
||||
|
@ -54,6 +56,8 @@ func init() {
|
|||
type CloudflareApi struct {
|
||||
ApiKey string `json:"apikey"`
|
||||
ApiUser string `json:"apiuser"`
|
||||
AccountID string `json:"accountid"`
|
||||
AccountName string `json:"accountname"`
|
||||
domainIndex map[string]string
|
||||
nameservers map[string][]string
|
||||
ipConversions []transform.IpConversion
|
||||
|
@ -307,6 +311,12 @@ func newCloudflare(m map[string]string, metadata json.RawMessage) (providers.DNS
|
|||
return nil, errors.Errorf("cloudflare apikey and apiuser must be provided")
|
||||
}
|
||||
|
||||
// Check account data if set
|
||||
api.AccountID, api.AccountName = m["accountid"], m["accountname"]
|
||||
if (api.AccountID != "" && api.AccountName == "") || (api.AccountID == "" && api.AccountName != "") {
|
||||
return nil, errors.Errorf("either both cloudflare accountid and accountname must be provided or neither")
|
||||
}
|
||||
|
||||
err := api.fetchDomainList()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -99,10 +99,21 @@ func (c *CloudflareApi) deleteRec(rec *cfRecord, domainID string) *models.Correc
|
|||
func (c *CloudflareApi) createZone(domainName string) (string, error) {
|
||||
type createZone struct {
|
||||
Name string `json:"name"`
|
||||
|
||||
Account struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"account"`
|
||||
}
|
||||
var id string
|
||||
cz := &createZone{
|
||||
Name: domainName}
|
||||
|
||||
if c.AccountID != "" || c.AccountName != "" {
|
||||
cz.Account.ID = c.AccountID
|
||||
cz.Account.Name = c.AccountName
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
encoder := json.NewEncoder(buf)
|
||||
if err := encoder.Encode(cz); err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue