mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
Merge pull request #9673 from certbot/types-dns-common-get
types: CredentialsConfiguration.conf can return None
This commit is contained in:
commit
399b932a86
11 changed files with 36 additions and 26 deletions
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
import digitalocean
|
||||
|
|
@ -56,7 +57,7 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
def _get_digitalocean_client(self) -> "_DigitalOceanClient":
|
||||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _DigitalOceanClient(self.credentials.conf('token'))
|
||||
return _DigitalOceanClient(cast(str, self.credentials.conf('token')))
|
||||
|
||||
|
||||
class _DigitalOceanClient:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
from lexicon.providers import dnsimple
|
||||
|
|
@ -58,7 +59,7 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
def _get_dnsimple_client(self) -> "_DNSimpleLexiconClient":
|
||||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _DNSimpleLexiconClient(self.credentials.conf('token'), self.ttl)
|
||||
return _DNSimpleLexiconClient(cast(str, self.credentials.conf('token')), self.ttl)
|
||||
|
||||
|
||||
class _DNSimpleLexiconClient(dns_common_lexicon.LexiconClient):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
from lexicon.providers import dnsmadeeasy
|
||||
|
|
@ -62,8 +63,8 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
def _get_dnsmadeeasy_client(self) -> "_DNSMadeEasyLexiconClient":
|
||||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _DNSMadeEasyLexiconClient(self.credentials.conf('api-key'),
|
||||
self.credentials.conf('secret-key'),
|
||||
return _DNSMadeEasyLexiconClient(cast(str, self.credentials.conf('api-key')),
|
||||
cast(str, self.credentials.conf('secret-key')),
|
||||
self.ttl)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
from lexicon.providers import gehirn
|
||||
|
|
@ -64,8 +65,8 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _GehirnLexiconClient(
|
||||
self.credentials.conf('api-token'),
|
||||
self.credentials.conf('api-secret'),
|
||||
cast(str, self.credentials.conf('api-token')),
|
||||
cast(str, self.credentials.conf('api-secret')),
|
||||
self.ttl
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import logging
|
|||
import re
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
def _get_linode_client(self) -> '_LinodeLexiconClient':
|
||||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
api_key = self.credentials.conf('key')
|
||||
api_key = cast(str, self.credentials.conf('key'))
|
||||
api_version: Optional[Union[str, int]] = self.credentials.conf('version')
|
||||
if api_version == '':
|
||||
api_version = None
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
from lexicon.providers import luadns
|
||||
|
|
@ -59,8 +60,8 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
def _get_luadns_client(self) -> "_LuaDNSLexiconClient":
|
||||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _LuaDNSLexiconClient(self.credentials.conf('email'),
|
||||
self.credentials.conf('token'),
|
||||
return _LuaDNSLexiconClient(cast(str, self.credentials.conf('email')),
|
||||
cast(str, self.credentials.conf('token')),
|
||||
self.ttl)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
from lexicon.providers import nsone
|
||||
|
|
@ -58,7 +59,7 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
def _get_nsone_client(self) -> "_NS1LexiconClient":
|
||||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _NS1LexiconClient(self.credentials.conf('api-key'), self.ttl)
|
||||
return _NS1LexiconClient(cast(str, self.credentials.conf('api-key')), self.ttl)
|
||||
|
||||
|
||||
class _NS1LexiconClient(dns_common_lexicon.LexiconClient):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
from lexicon.providers import ovh
|
||||
|
|
@ -65,10 +66,10 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _OVHLexiconClient(
|
||||
self.credentials.conf('endpoint'),
|
||||
self.credentials.conf('application-key'),
|
||||
self.credentials.conf('application-secret'),
|
||||
self.credentials.conf('consumer-key'),
|
||||
cast(str, self.credentials.conf('endpoint')),
|
||||
cast(str, self.credentials.conf('application-key')),
|
||||
cast(str, self.credentials.conf('application-secret')),
|
||||
cast(str, self.credentials.conf('consumer-key')),
|
||||
self.ttl
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
import dns.flags
|
||||
|
|
@ -59,7 +60,7 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
'RFC 2136 Dynamic Updates.'
|
||||
|
||||
def _validate_credentials(self, credentials: CredentialsConfiguration) -> None:
|
||||
server = credentials.conf('server')
|
||||
server = cast(str, credentials.conf('server'))
|
||||
if not is_ipaddress(server):
|
||||
raise errors.PluginError("The configured target DNS server ({0}) is not a valid IPv4 "
|
||||
"or IPv6 address. A hostname is not allowed.".format(server))
|
||||
|
|
@ -89,11 +90,11 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
def _get_rfc2136_client(self) -> "_RFC2136Client":
|
||||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _RFC2136Client(self.credentials.conf('server'),
|
||||
int(self.credentials.conf('port') or self.PORT),
|
||||
self.credentials.conf('name'),
|
||||
self.credentials.conf('secret'),
|
||||
self.ALGORITHMS.get(self.credentials.conf('algorithm'),
|
||||
return _RFC2136Client(cast(str, self.credentials.conf('server')),
|
||||
int(cast(str, self.credentials.conf('port')) or self.PORT),
|
||||
cast(str, self.credentials.conf('name')),
|
||||
cast(str, self.credentials.conf('secret')),
|
||||
self.ALGORITHMS.get(self.credentials.conf('algorithm') or '',
|
||||
dns.tsig.HMAC_MD5))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
|
||||
from lexicon.providers import sakuracloud
|
||||
|
|
@ -64,8 +65,8 @@ class Authenticator(dns_common.DNSAuthenticator):
|
|||
if not self.credentials: # pragma: no cover
|
||||
raise errors.Error("Plugin has not been prepared.")
|
||||
return _SakuraCloudLexiconClient(
|
||||
self.credentials.conf('api-token'),
|
||||
self.credentials.conf('api-secret'),
|
||||
cast(str, self.credentials.conf('api-token')),
|
||||
cast(str, self.credentials.conf('api-secret')),
|
||||
self.ttl
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -312,12 +312,12 @@ class CredentialsConfiguration:
|
|||
)
|
||||
)
|
||||
|
||||
def conf(self, var: str) -> str:
|
||||
def conf(self, var: str) -> Optional[str]:
|
||||
"""Find a configuration value for variable `var`, as transformed by `mapper`.
|
||||
|
||||
:param str var: The variable to get.
|
||||
:returns: The value of the variable.
|
||||
:rtype: str
|
||||
:returns: The value of the variable, if it exists.
|
||||
:rtype: str or None
|
||||
"""
|
||||
|
||||
return self._get(var)
|
||||
|
|
@ -325,7 +325,7 @@ class CredentialsConfiguration:
|
|||
def _has(self, var: str) -> bool:
|
||||
return self.mapper(var) in self.confobj
|
||||
|
||||
def _get(self, var: str) -> str:
|
||||
def _get(self, var: str) -> Optional[str]:
|
||||
return self.confobj.get(self.mapper(var))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue