1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

support email/token and just token for cloudflare

This commit is contained in:
Mark Mercado
2019-09-25 20:53:45 -04:00
parent f200d91e49
commit 16121be4de
2 changed files with 37 additions and 28 deletions

View File

@@ -38,6 +38,8 @@ class CloudflareProvider(BaseProvider):
cloudflare:
class: octodns.provider.cloudflare.CloudflareProvider
# The api key (required)
# Your Cloudflare account email address (required)
email: dns-manager@example.com (optional if using token)
token: foo
# Import CDN enabled records as CNAME to {}.cdn.cloudflare.net. Records
# ending at .cdn.cloudflare.net. will be ignored when this provider is
@@ -64,17 +66,24 @@ class CloudflareProvider(BaseProvider):
MIN_TTL = 120
TIMEOUT = 15
def __init__(self, id, token, cdn=False, *args, **kwargs):
def __init__(self, id, token, email=None, cdn=False, *args, **kwargs):
self.log = getLogger('CloudflareProvider[{}]'.format(id))
self.log.debug('__init__: id=%s, token=***, cdn=%s', id, cdn)
self.log.debug('__init__: id=%s, email=%s, token=***, cdn=%s', id,
email, cdn)
super(CloudflareProvider, self).__init__(id, *args, **kwargs)
sess = Session()
# https://api.cloudflare.com/#getting-started-requests
# https://tools.ietf.org/html/rfc6750#section-2.1
sess.headers.update({
'Authorization': 'Bearer ' + token,
})
if not email:
sess.headers.update({
'Authorization': 'Bearer %s'.format(token),
})
else:
sess.headers.update({
'X-Auth-Email': email,
'X-Auth-Key': token,
})
self.cdn = cdn
self._sess = sess