????

Your IP : 3.23.92.150


Current Path : /usr/lib/python3.6/site-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/certbot/plugins/__pycache__/dns_common.cpython-36.pyc

3

گa�5�@sTdZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZddlZdd
l
mZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZeje�ZGdd�dej ej!ej"d�Z#Gdd�d�Z$e%dd�dd�Z&e%dd�dd�Z'e%ee%d�dd �Z(dS)!z*Common code for DNS Authenticator Plugins.�N)�sleep)�Callable)�Iterable)�List)�Mapping)�Optional)�Type)�
challenges)�achallenges)�
configuration)�errors)�
interfaces)�
filesystem)�os)�ops)�util)�commoncs�eZdZdZejedd��fdd�Zed2e	d3e
dd�d	d
��Zee
jed�dd
�Zeeeejd�dd�Zdd�dd�Zed�dd�Zee
jeejd�dd�Zee
jdd�dd�Zejdd�dd��Zejeeedd�dd��Zejeeedd�d d!��Zeedd"�d#d$�Zd4eee e	egdfdd%�d&d'�Z!d5eee e"eefe e	d(gdfd(d)�d*d+�Z#e$eed,�d-d.��Z%e$d6ee e	egdfed/�d0d1��Z&�Z'S)7�DNSAuthenticatorz!Base class for DNS AuthenticatorsN)�config�name�returncst�j||�d|_dS)NF)�super�__init__�_attempt_cleanup)�selfrr)�	__class__�� /usr/lib/python3.6/dns_common.pyrszDNSAuthenticator.__init__�
.)�add�default_propagation_secondsrcCs|d|tdd�dS)Nzpropagation-secondszjThe number of seconds to wait for DNS to propagate before asking the ACME server to verify the DNS record.)�default�type�help)�int)�clsrr rrr�add_parser_arguments$sz%DNSAuthenticator.add_parser_arguments)�failed_achallsrcCs(|jd�}dj|j||dkr dndd�S)z,See certbot.plugins.common.Plugin.auth_hint.zpropagation-secondsz�The Certificate Authority failed to verify the DNS TXT records created by --{name}. Ensure the above domains are hosted by this DNS provider, or try increasing --{name}-propagation-seconds (currently {secs} second{suffix}).��s�)rZsecs�suffix)�conf�formatr)rr'Zdelayrrr�	auth_hint-s
zDNSAuthenticator.auth_hint)�
unused_domainrcCstjgS)N)r	ZDNS01)rr/rrr�get_chall_pref7szDNSAuthenticator.get_chall_pref)rcCsdS)Nr)rrrr�prepare:szDNSAuthenticator.preparecCs
t��dS)N)�NotImplementedError)rrrr�	more_info=szDNSAuthenticator.more_info)�achallsrcCs�|j�d|_g}xH|D]@}|j}|j|�}|j|j�}|j|||�|j|j|j��qWt	j
d|jd��t|jd��|S)NTz/Waiting %d seconds for DNS changes to propagatezpropagation-seconds)
�_setup_credentialsr�domain�validation_domain_name�
validation�account_key�_perform�append�response�display_utilZnotifyr,r)rr4Z	responses�achallr6r7r8rrr�perform@s

zDNSAuthenticator.performcCsB|jr>x6|D].}|j}|j|�}|j|j�}|j|||�qWdS)N)rr6r7r8r9�_cleanup)rr4r>r6r7r8rrr�cleanupXs

zDNSAuthenticator.cleanupcCs
t��dS)z@
        Establish credentials, prompting if necessary.
        N)r2)rrrrr5asz#DNSAuthenticator._setup_credentials)r6�validation_namer8rcCs
t��dS)aX
        Performs a dns-01 challenge by creating a DNS TXT record.

        :param str domain: The domain being validated.
        :param str validation_domain_name: The validation record domain name.
        :param str validation: The validation record content.
        :raises errors.PluginError: If the challenge cannot be performed
        N)r2)rr6rBr8rrrr:hszDNSAuthenticator._performcCs
t��dS)aX
        Deletes the DNS TXT record which would have been created by `_perform_achall`.

        Fails gracefully if no such record exists.

        :param str domain: The domain being validated.
        :param str validation_domain_name: The validation record domain name.
        :param str validation: The validation record content.
        N)r2)rr6rBr8rrrr@uszDNSAuthenticator._cleanup)�key�labelrcCs0|j|�}|s,|j|�}t|j|j|�|�dS)a
        Ensure that a configuration value is available.

        If necessary, prompts the user and stores the result.

        :param str key: The configuration key.
        :param str label: The user-friendly label for this piece of information.
        N)r,�_prompt_for_data�setattrr�dest)rrCrD�configured_value�	new_valuerrr�
_configure�s


zDNSAuthenticator._configure)rCrD�	validatorrcCsB|j|�}|s>|j||�}t|j|j|�tjjtjj|���dS)a
        Ensure that a configuration value is available for a path.

        If necessary, prompts the user and stores the result.

        :param str key: The configuration key.
        :param str label: The user-friendly label for this piece of information.
        N)	r,�_prompt_for_filerFrrGr�path�abspath�
expanduser)rrCrDrKrHrIrrr�_configure_file�s
z DNSAuthenticator._configure_file�CredentialsConfiguration)rCrD�required_variablesrKrcsVtdd����fdd�}�j|||�t�j|��j�}�rF|j���rR�|�|S)a�
        As `_configure_file`, but for a credential configuration file.

        If necessary, prompts the user and stores the result.

        Always stores absolute paths to avoid issues during renewal.

        :param str key: The configuration key.
        :param str label: The user-friendly label for this piece of information.
        :param dict required_variables: Map of variable which must be present to error to display.
        :param callable validator: A method which will be called to validate the
            `CredentialsConfiguration` resulting from the supplied input after it has been validated
            to contain the `required_variables`. Should throw a `~certbot.errors.PluginError` to
            indicate any issue.
        N)�filenamercs*t|�j�}�r|j���r&�|�dS)N)rQrG�require)rSZapplied_configuration)rRrrKrr�__validator�s

z<DNSAuthenticator._configure_credentials.<locals>.__validator)�strrPrQr,rGrT)rrCrDrRrK�_DNSAuthenticator__validatorZcredentials_configurationr)rRrrKr�_configure_credentials�s	
z'DNSAuthenticator._configure_credentials)rDrcsPtdd��fdd�}tj|dj��dd�\}}|tjkr<|Stjdj����dS)	z�
        Prompt the user for a piece of information.

        :param str label: The user-friendly label for this piece of information.
        :returns: The user's response (guaranteed non-empty).
        :rtype: str
        N)�ircs|stjdj����dS)NzPlease enter your {0}.)r�PluginErrorr-)rY)rDrrrU�sz6DNSAuthenticator._prompt_for_data.<locals>.__validatorzInput your {0}T)�force_interactivez{0} required to proceed.)rVrZvalidated_inputr-r=�OKrrZ)rDrW�coder<r)rDrrE�s

z!DNSAuthenticator._prompt_for_data)rDrKrcsRtdd���fdd�}tj|dj��dd�\}}|tjkr>|Stjdj����dS)	a�
        Prompt the user for a path.

        :param str label: The user-friendly label for the file.
        :param callable validator: A method which will be called to validate the supplied input
            after it has been validated to be a non-empty path to an existing file. Should throw a
            `~certbot.errors.PluginError` to indicate any issue.
        :returns: The user's response (guaranteed to exist).
        :rtype: str
        N)rSrcs8|stjdj����tjj|�}t|��r4�|�dS)Nz&Please enter a valid path to your {0}.)rrZr-rrMrO�
validate_file)rS)rDrKrrrU�sz6DNSAuthenticator._prompt_for_file.<locals>.__validatorzInput the path to your {0}T)r[z{0} required to proceed.)rVrZvalidated_directoryr-r=r\rrZ)rDrKrWr]r<r)rDrKrrL�s

z!DNSAuthenticator._prompt_for_file)r).N)N)NN)N)(�__name__�
__module__�__qualname__�__doc__rZNamespaceConfigrVr�classmethodrr$r&rr
ZAnnotatedChallenger.rrr	Z	Challenger0r1r3ZChallengeResponser?rA�abc�abstractmethodr5r:r@rJrrPrrX�staticmethodrErL�
__classcell__rr)rrrs8
	$$%r)�	metaclassc@s|eZdZdZdd�feeegefdd�dd�Zeeefdd�d	d
�Zeed�dd
�Z	ee
d�dd�Zeed�dd�ZdS)rQz>Represents a user-supplied filed which stores API credentials.cCs|S)Nr)�xrrr�<lambda>sz!CredentialsConfiguration.<lambda>N)rS�mapperrcCsht|�ytj|�|_WnDtjk
r\}z&tjd|dd�tjdj	|���WYdd}~XnX||_
dS)z�
        :param str filename: A path to the configuration file.
        :param callable mapper: A transformation to apply to configuration key names
        :raises errors.PluginError: If the file does not exist or is not a valid format.
        z+Error parsing credentials configuration: %sT)�exc_infoz,Error parsing credentials configuration: {0}N)�validate_file_permissions�	configobjZ	ConfigObj�confobjZConfigObjError�logger�debugrrZr-rk)rrSrk�errrrs"z!CredentialsConfiguration.__init__)rRrcCs�g}xZ|D]R}|j|�s6|jdj|j|�||��q
|j|�s
|jdj|j|�||��q
W|r�tjdjt|�dkr|dnd|jj	dj
|����dS)	z�Ensures that the supplied set of variables are all present in the file.

        :param dict required_variables: Map of variable which must be present to error to display.
        :raises errors.PluginError: If one or more are missing.
        z)Property "{0}" not found (should be {1}).z'Property "{0}" not set (should be {1}).z9Missing {0} in credentials configuration file {1}:
 * {2}r(�propertyZ
propertiesz
 * N)�_hasr;r-rk�_getrrZ�lenrorS�join)rrRZmessages�varrrrrTs


z CredentialsConfiguration.require)rxrcCs
|j|�S)z�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
        )ru)rrxrrrr,1szCredentialsConfiguration.confcCs|j|�|jkS)N)rkro)rrxrrrrt;szCredentialsConfiguration._hascCs|jj|j|��S)N)ro�getrk)rrxrrrru>szCredentialsConfiguration._get)
r_r`rarbrVrrrrTr,�boolrtrurrrrrQs$
rQ)rSrcCs<tjj|�stjdj|���tjj|�r8tjdj|���dS)z&Ensure that the specified file exists.zFile not found: {0}zPath is a directory: {0}N)rrM�existsrrZr-�isdir)rSrrrr^Bsr^cCs"t|�tj|�rtjd|�dS)zHEnsure that the specified file exists and warn about unsafe permissions.z8Unsafe permissions on credentials configuration file: %sN)r^rZhas_world_permissionsrpZwarning)rSrrrrmLs
rm)r6rcs&|jd���fdd�tdt���D�S)a�Return a list of progressively less-specific domain names.

    One of these will probably be the domain name known to the DNS provider.

    :Example:

    >>> base_domain_name_guesses('foo.bar.baz.example.com')
    ['foo.bar.baz.example.com', 'bar.baz.example.com', 'baz.example.com', 'example.com', 'com']

    :param str domain: The domain for which to return guesses.
    :returns: The a list of less specific domain names.
    :rtype: list
    �.csg|]}dj�|d���qS)r}N)rw)�.0rY)�	fragmentsrr�
<listcomp>esz,base_domain_name_guesses.<locals>.<listcomp>r)�split�rangerv)r6r)rr�base_domain_name_guessesUs
r�))rbrdZloggingZtimerZtypingrrrrrrrnZacmer	Zcertbotr
rrr
Zcertbot.compatrrZcertbot.displayrrr=Zcertbot.pluginsrZ	getLoggerr_rpZPluginZ
Authenticator�ABCMetarrQrVr^rmr�rrrr�<module>s6
j=