File: //lib/python3/dist-packages/certbot/plugins/__pycache__/dns_common.cpython-310.pyc
o
6��a�1 � @ s� d Z ddlZddlZddlmZ ddlZddlmZ ddlm Z ddlm
Z
ddlmZ ddlm
Z
dd lmZ dd
lmZ ddlmZ e�e�ZG dd
� d
eje
jejd�ZG dd� d�Zdd� Zdd� Zdd� ZdS )z*Common code for DNS Authenticator Plugins.� N)�sleep)�
challenges)�errors)�
interfaces)�
filesystem)�os)�ops)�util)�commonc s� e Zd ZdZ� fdd�Zed&dd��Zdd� Zd d
� Zdd� Z d
e
fdd�Zdd� Zdd� Z
ejdd� �Zejdd� �Zejdd� �Zdd� Zd'dd�Z d( d)d d!�Zed"d#� �Zed'd$d%��Z� ZS )*�DNSAuthenticatorz!Base class for DNS Authenticatorsc s t � �||� d| _d S )NF)�super�__init__�_attempt_cleanup)�self�config�name�� __class__� �</usr/lib/python3/dist-packages/certbot/plugins/dns_common.pyr
s
zDNSAuthenticator.__init__�
c C s |d|t dd� d S )N�propagation-secondszjThe number of seconds to wait for DNS to propagate before asking the ACME server to verify the DNS record.)�default�type�help)�int)�cls�add�default_propagation_secondsr r r �add_parser_arguments s
�z%DNSAuthenticator.add_parser_argumentsc C s, | � d�}dj| j||dkrdd�S dd�S )z,See certbot.plugins.common.Plugin.auth_hint.r z�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� )r �secs�suffix)�conf�formatr )r �failed_achalls�delayr r r � auth_hint% s
����zDNSAuthenticator.auth_hintc C s t jgS �N)r �DNS01)r �
unused_domainr r r �get_chall_pref/ s zDNSAuthenticator.get_chall_prefc C s d S r* r �r r r r �prepare2 s zDNSAuthenticator.prepare�returnc C � t � �r* ��NotImplementedErrorr. r r r � more_info5 s zDNSAuthenticator.more_infoc C s~ | � � d| _g }|D ] }|j}|�|�}|�|j�}| �|||� |�|�|j�� qt �
d| �d� � t| �d�� |S )NTz/Waiting %d seconds for DNS changes to propagater )
�_setup_credentialsr �domain�validation_domain_name�
validation�account_key�_perform�append�response�display_util�notifyr% r )r �achalls� responses�achallr6 r7 r8 r r r �perform8 s
�zDNSAuthenticator.performc C sB | j r|D ]}|j}|�|�}|�|j�}| �|||� qd S d S r* )r r6 r7 r8 r9 �_cleanup)r r? rA r6 r7 r8 r r r �cleanupO s
�zDNSAuthenticator.cleanupc C r1 )z@
Establish credentials, prompting if necessary.
r2 r. r r r r5 X s z#DNSAuthenticator._setup_credentialsc C r1 )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
r2 �r r6 �validation_namer8 r r r r: _ s
zDNSAuthenticator._performc C r1 )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.
r2 rE r r r rC k s zDNSAuthenticator._cleanupc C s4 | � |�}|s| �|�}t| j| �|�|� dS 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)r �key�label�configured_value� new_valuer r r �
_configurex s
�zDNSAuthenticator._configureNc C sF | � |�}|s!| �||�}t| j| �|�tj�tj�|��� dS 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_filerH r rI r �path�abspath�
expanduser)r rJ rK � validatorrL rM r r r �_configure_file� s
(�z DNSAuthenticator._configure_file�CredentialsConfigurationc sN � ��fdd�}�� |||� t��|��j�}� r|�� � �r%�|� |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.
c s. t | �j�}� r
|�� � �r�|� d S d S r* )rU rI �require)�filename�
configuration��required_variablesr rS r r �__validator� s
�z<DNSAuthenticator._configure_credentials.<locals>.__validator)rT rU r% rI rV )r rJ rK rZ rS �_DNSAuthenticator__validator�credentials_configurationr rY r �_configure_credentials� s
z'DNSAuthenticator._configure_credentialsc sD � fdd�}t j|d�� �dd�\}}|tjkr|S t�d�� ���)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
c s | s
t �d�� ���d S )NzPlease enter your {0}.)r �PluginErrorr&