← Back
Editing: renewal.cpython-38.pyc
U e�_�S � @ s� d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ e�e �Z!ddddddddddddgZ"ddgZ#ddd d!gZ$e%e�&e$e#e"d"��Z'd#d$� Z(d%d&� Z)d'd(� Z*d)d*� Z+d+d,� Z,d-d.� Z-d/d0� Z.d1d2� Z/d3d4� Z0d5d6� Z1d7d8� Z2d9d:� Z3d;d<� Z4d=d>� Z5dS )?zGFunctionality for autorenewal and associated juggling of configurations� )�print_functionN)�List)�cli)� constants)�crypto_util)�errors)�hooks)� interfaces)�storage)�updater)�util)�os)�discoZ config_dirZlogs_dirZwork_dirZ user_agent�serverZaccount� authenticator� installer� renew_hook�pre_hook� post_hookZhttp01_addressZrsa_key_size�http01_portZmust_stapleZallow_subset_of_names� reuse_keyZ autorenew)�pref_challsc C sX zt �|| �}W nF tjtfk rV tjddd� t�d|� t�dt� � � Y dS X d|j krrt�d|� dS |j d }d |kr�t�d |� dS zt| |� t| |� W nR t tjfk � r� } z,t�d|t|�� t�dt� � � W Y �dS d}~X Y nX zdd � |�� D �| _W n: tjk �rR } zt�d||� W Y �dS d}~X Y nX |S )a� Try to instantiate a RenewableCert, updating config with relevant items. This is specifically for use in renewal and enforces several checks and policies to ensure that we can try to proceed with the renewal request. The config argument is modified by including relevant options read from the renewal configuration file. :param configuration.NamespaceConfig config: configuration for the current lineage :param str full_path: Absolute path to the configuration file that defines this lineage :returns: the RenewableCert object or None if a fatal error occurred :rtype: `storage.RenewableCert` or NoneType � T)�exc_infoz2Renewal configuration file %s is broken. Skipping.�Traceback was: %sN� renewalparamsz<Renewal configuration file %s lacks renewalparams. Skipping.r zJRenewal configuration file %s does not specify an authenticator. Skipping.zHAn error occurred while parsing %s. The error was %s. Skipping the file.c S s g | ]}t �|��qS � )r Zenforce_domain_sanity)�.0�dr r �1/usr/lib/python3/dist-packages/certbot/renewal.py� <listcomp>] s �z!_reconstitute.<locals>.<listcomp>ztRenewal configuration file %s references a cert that contains an invalid domain name. The problem was: %s. Skipping.)r Z RenewableCertr ZCertStorageError�IOError�logger�warning�debug� traceback� format_exc� configuration� restore_required_config_elements�_restore_plugin_configs� ValueError�Error�str�names�domainsZConfigurationError)�config� full_path�renewal_candidater �errorr r r � _reconstitute/ sP � � �� �r3 c C sR d|krt �d�s|d | _d|krNt �d�sN|d }t|tj�rH|g}|| _dS )z� webroot_map is, uniquely, a dict, and the general-purpose configuration restoring logic is not able to correctly parse it from the serialized form. �webroot_map�webroot_pathN)r � set_by_clir4 � isinstance�six�string_typesr5 )r/ r Zwpr r r �_restore_webroot_configh s r: c C s� g }|d dkrt | |� n|�|d � |�d�dk rF|�|d � t|�D ]p}|�dd�}t�|�D ]T\}}|�|d �rht� |�sh|dkr�t | |t|�� qht�|�}t | |||�� qhqNdS )a Sets plugin specific values in config from renewalparams :param configuration.NamespaceConfig config: configuration for the current lineage :param configobj.Section renewalparams: Parameters from the renewal configuration file that defines this lineage r Zwebrootr N�-�_)�None�True�False) r: �append�get�set�replacer8 Z iteritems� startswithr r6 �setattr�evalZ argparse_type)r/ r Zplugin_prefixesZ plugin_prefixZconfig_itemZconfig_value�castr r r r) y s r) c C s� t �dtfftj�tt �t��tj�t t �t ��tj�tt �t���}|D ]4\}}||krJt �|�sJ|||| �}t| ||� qJdS )a Sets non-plugin specific values in config from renewalparams :param configuration.NamespaceConfig config: configuration for the current lineage :param configobj.Section renewalparams: parameters from the renewal configuration file that defines this lineage r N)� itertools�chain�_restore_pref_challsr8 Zmoves�zip�BOOL_CONFIG_ITEMS�repeat� _restore_bool�INT_CONFIG_ITEMS�_restore_int�STR_CONFIG_ITEMS�_restore_strr r6 rE )r/ r Zrequired_itemsZ item_nameZrestore_func�valuer r r r( � s �r( c C s t |tj�r|gn|}t�|�S )a� Restores preferred challenges from a renewal config file. If value is a `str`, it should be a single challenge type. :param str unused_name: option name :param value: option value :type value: `list` of `str` or `str` :returns: converted option value to be stored in the runtime config :rtype: `list` of `str` :raises errors.Error: if value can't be converted to an bool )r7 r8 r9 r Zparse_preferred_challenges)Zunused_namerS r r r rJ � s rJ c C s* |� � }|dkr"t�d�| |���|dkS )a% Restores an boolean key-value pair from a renewal config file. :param str name: option name :param str value: option value :returns: converted option value to be stored in the runtime config :rtype: bool :raises errors.Error: if value can't be converted to an bool )�trueZfalsez,Expected True or False for {0} but found {1}rT )�lowerr r+ �format)�namerS Zlowercase_valuer r r rN � s �rN c C sX | dkr$|dkr$t �d� t�d�S z t|�W S tk rR t�d�| ���Y nX dS )a# Restores an integer key-value pair from a renewal config file. :param str name: option name :param str value: option value :returns: converted option value to be stored in the runtime config :rtype: int :raises errors.Error: if value can't be converted to an int r r= z!updating legacy http01_port valuez Expected a numeric value for {0}N) r"