Your IP : 216.73.216.172


Current Path : /lib/python3/dist-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/certbot/plugins/__pycache__/dns_common_lexicon.cpython-38.pyc

U

�]��@s�dZddlZddlmZmZddlmZmZmZddl	m
Z
ddlmZzddl
mZWnek
rpdZYnXe�e�ZGdd	�d	e�Zd
d�ZdS)z;Common code for DNS Authenticator Plugins built on Lexicon.�N)�	HTTPError�RequestException)�Union�Dict�Any)�errors)�
dns_common)�ConfigResolverc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
LexiconClientzI
    Encapsulates all communication with a DNS provider via Lexicon.
    cCs
d|_dS)N)�provider)�self�r
�D/usr/lib/python3/dist-packages/certbot/plugins/dns_common_lexicon.py�__init__szLexiconClient.__init__c
Csh|�|�z|jjd||d�WnBtk
rb}z$tjd|dd�t�d�|���W5d}~XYnXdS)a�
        Add a TXT record using the supplied information.

        :param str domain: The domain to use to look up the managed zone.
        :param str record_name: The record name (typically beginning with '_acme-challenge.').
        :param str record_content: The record content (typically the challenge validation).
        :raises errors.PluginError: if an error occurs communicating with the DNS Provider API
        �TXT��type�nameZcontentz'Encountered error adding TXT record: %sT��exc_infozError adding TXT record: {0}N)	�_find_domain_idrZ
create_recordr�logger�debugr�PluginError�format�r�domainZrecord_nameZrecord_content�er
r
r�add_txt_records	
zLexiconClient.add_txt_recordc
Cs�z|�|�Wn:tjk
rH}ztjd|dd�WY�dSd}~XYnXz|jjd||d�Wn2tk
r�}ztjd|dd�W5d}~XYnXdS)a�
        Delete a TXT record using the supplied information.

        :param str domain: The domain to use to look up the managed zone.
        :param str record_name: The record name (typically beginning with '_acme-challenge.').
        :param str record_content: The record content (typically the challenge validation).
        :raises errors.PluginError: if an error occurs communicating with the DNS Provider  API
        z7Encountered error finding domain_id during deletion: %sTrNrrz)Encountered error deleting TXT record: %s)rrrrrrZ
delete_recordrrr
r
r�del_txt_record0s	�zLexiconClient.del_txt_recordcCs�t�|�}|D]�}z4t|jd�r.||jjd<n||j_|j��WdStk
r|}z|�||�}|rl|�W5d}~XYqt	k
r�}z|�
||�}|r�|�W5d}~XYqXqt�d�
||���dS)z�
        Find the domain_id for a given domain.

        :param str domain: The domain for which to find the domain_id.
        :raises errors.PluginError: if the domain_id cannot be found.
        �optionsrNzAUnable to determine zone identifier for {0} using zone names: {1})rZbase_domain_name_guesses�hasattrrr rZauthenticater�_handle_http_error�	Exception�_handle_general_errorrrr)rrZdomain_name_guesses�domain_namer�resultr
r
rrEs(

�zLexiconClient._find_domain_idcCst�d�||��S)Nz/Error determining zone identifier for {0}: {1}.)rrr�rrr%r
r
rr"is�z LexiconClient._handle_http_errorcCs$t|��d�s t�d�||��SdS)NzNo domain foundz9Unexpected error determining zone identifier for {0}: {1})�str�
startswithrrrr'r
r
rr$ms�z#LexiconClient._handle_general_errorN)
�__name__�
__module__�__qualname__�__doc__rrrrr"r$r
r
r
rr
s$r
cCsLd|i}|�|�ts"|�|�n&i}|�|�|||<t��|���}|S)ao
    Convenient function to build a Lexicon 2.x/3.x config object.
    :param str lexicon_provider_name: the name of the lexicon provider to use
    :param dict lexicon_options: options specific to lexicon
    :param dict provider_options: options specific to provider
    :return: configuration to apply to the provider
    :rtype: ConfigurationResolver or dict
    Z
provider_name)�updater	Z	with_dictZwith_env)Zlexicon_provider_nameZlexicon_optionsZprovider_optionsZconfigZprovider_configr
r
r�build_lexicon_configts


r/)r-ZloggingZrequests.exceptionsrrZacme.magic_typingrrrZcertbotrZcertbot.pluginsrZlexicon.configr	�ImportErrorZ	getLoggerr*r�objectr
r/r
r
r
r�<module>s

]