diff options
Diffstat (limited to 'certbot-dns-cloudflare/certbot_dns_cloudflare/_internal/dns_cloudflare.py')
-rw-r--r-- | certbot-dns-cloudflare/certbot_dns_cloudflare/_internal/dns_cloudflare.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/certbot-dns-cloudflare/certbot_dns_cloudflare/_internal/dns_cloudflare.py b/certbot-dns-cloudflare/certbot_dns_cloudflare/_internal/dns_cloudflare.py index eac29a85b..e8bf560c6 100644 --- a/certbot-dns-cloudflare/certbot_dns_cloudflare/_internal/dns_cloudflare.py +++ b/certbot-dns-cloudflare/certbot_dns_cloudflare/_internal/dns_cloudflare.py @@ -82,8 +82,9 @@ class Authenticator(dns_common.DNSAuthenticator): if not self.credentials: # pragma: no cover raise errors.Error("Plugin has not been prepared.") if self.credentials.conf('api-token'): - return _CloudflareClient(None, self.credentials.conf('api-token')) - return _CloudflareClient(self.credentials.conf('email'), self.credentials.conf('api-key')) + return _CloudflareClient(api_token = self.credentials.conf('api-token')) + return _CloudflareClient(email = self.credentials.conf('email'), + api_key = self.credentials.conf('api-key')) class _CloudflareClient: @@ -91,8 +92,19 @@ class _CloudflareClient: Encapsulates all communication with the Cloudflare API. """ - def __init__(self, email: Optional[str], api_key: str) -> None: - self.cf = CloudFlare.CloudFlare(email, api_key) + def __init__(self, email: Optional[str] = None, api_key: Optional[str] = None, + api_token: Optional[str] = None) -> None: + if email: + # If an email was specified, we're using an email/key combination and not a token. + # We can't use named arguments in this case, as it would break compatibility with + # the Cloudflare library since version 2.10.1, as the `token` argument was used for + # tokens and keys alike and the `key` argument did not exist in earlier versions. + self.cf = CloudFlare.CloudFlare(email, api_key) + else: + # If no email was specified, we're using just a token. Let's use the named argument + # for simplicity, which is compatible with all (current) versions of the Cloudflare + # library. + self.cf = CloudFlare.CloudFlare(token=api_token) def add_txt_record(self, domain: str, record_name: str, record_content: str, record_ttl: int) -> None: |