
\\                 @   s   d  Z  d d l Z d d l Z d d l m Z d d l Z d d l m Z d d l m	 Z	 d d l m
 Z
 d d l m Z d d l m Z e j j e j  Gd	 d
   d
 e   Z d d   Z d S)z$Certbot user-supplied configuration.    N)parse)compat)	constants)errors)
interfaces)utilc               @   sN  e  Z d  Z d Z d d   Z d d   Z d d   Z e d d	    Z e d
 d    Z	 d d   Z
 e d d    Z e d d    Z e d d    Z e d d    Z e d d    Z d d   Z e d d    Z e d d    Z e d d    Z e d  d!    Z e d" d#    Z e d$ d%    Z e d& d'    Z d( S))NamespaceConfiga|  Configuration wrapper around :class:`argparse.Namespace`.

    For more documentation, including available attributes, please see
    :class:`certbot.interfaces.IConfig`. However, note that
    the following attributes are dynamically resolved using
    :attr:`~certbot.interfaces.IConfig.work_dir` and relative
    paths defined in :py:mod:`certbot.constants`:

      - `accounts_dir`
      - `csr_dir`
      - `in_progress_dir`
      - `key_dir`
      - `temp_checkpoint_dir`

    And the following paths are dynamically resolved using
    :attr:`~certbot.interfaces.IConfig.config_dir` and relative
    paths defined in :py:mod:`certbot.constants`:

      - `default_archive_dir`
      - `live_dir`
      - `renewal_configs_dir`

    :ivar namespace: Namespace typically produced by
        :meth:`argparse.ArgumentParser.parse_args`.
    :type namespace: :class:`argparse.Namespace`

    c             C   s{   t  j |  d |  t j j |  j j  |  j _ t j j |  j j  |  j _ t j j |  j j  |  j _ t	 |   d  S)N	namespace)
object__setattr__ospathabspathr	   
config_dirwork_dirZlogs_dircheck_config_sanity)selfr	    r   7/usr/lib/python3/dist-packages/certbot/configuration.py__init__-   s
    zNamespaceConfig.__init__c             C   s   t  |  j |  S)N)getattrr	   )r   namer   r   r   __getattr__7   s    zNamespaceConfig.__getattr__c             C   s   t  |  j | |  d  S)N)setattrr	   )r   r   valuer   r   r   r   :   s    zNamespaceConfig.__setattr__c             C   s5   t  j |  j j  } | j | j j d t j j  S)zFile path based on ``server``./)	r   Zurlparser	   ZserverZnetlocr   replacer   sep)r   Zparsedr   r   r   server_path=   s    zNamespaceConfig.server_pathc             C   s   |  j  |  j  S)N)accounts_dir_for_server_pathr   )r   r   r   r   accounts_dirC   s    zNamespaceConfig.accounts_dirc             C   s.   t  j |  } t j j |  j j t j |  S)z/Path to accounts directory based on server_path)	r   Z.underscores_for_unsupported_characters_in_pathr   r   joinr	   r   r   ZACCOUNTS_DIR)r   r   r   r   r   r   G   s    	z,NamespaceConfig.accounts_dir_for_server_pathc             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   Z
BACKUP_DIR)r   r   r   r   
backup_dirM   s    zNamespaceConfig.backup_dirc             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   ZCSR_DIR)r   r   r   r   csr_dirQ   s    zNamespaceConfig.csr_dirc             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   ZIN_PROGRESS_DIR)r   r   r   r   in_progress_dirU   s    zNamespaceConfig.in_progress_dirc             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   ZKEY_DIR)r   r   r   r   key_dirY   s    zNamespaceConfig.key_dirc             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   ZTEMP_CHECKPOINT_DIR)r   r   r   r   temp_checkpoint_dir]   s    	z#NamespaceConfig.temp_checkpoint_dirc             C   s"   t  j |  j  } t |   |  S)N)copydeepcopyr	   type)r   Z_memoZnew_nsr   r   r   __deepcopy__b   s    zNamespaceConfig.__deepcopy__c             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   ZARCHIVE_DIR)r   r   r   r   default_archive_dirh   s    z#NamespaceConfig.default_archive_dirc             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   ZLIVE_DIR)r   r   r   r   live_dirl   s    zNamespaceConfig.live_dirc             C   s   t  j j |  j j t j  S)N)r   r   r!   r	   r   r   ZRENEWAL_CONFIGS_DIR)r   r   r   r   renewal_configs_dirp   s    	z#NamespaceConfig.renewal_configs_dirc             C   s   t  j j |  j j t j  S)z>Path to directory with hooks to run with the renew subcommand.)r   r   r!   r	   r   r   ZRENEWAL_HOOKS_DIR)r   r   r   r   renewal_hooks_diru   s    z!NamespaceConfig.renewal_hooks_dirc             C   s   t  j j |  j t j  S)z8Path to the pre-hook directory for the renew subcommand.)r   r   r!   r.   r   ZRENEWAL_PRE_HOOKS_DIR)r   r   r   r   renewal_pre_hooks_dir{   s    z%NamespaceConfig.renewal_pre_hooks_dirc             C   s   t  j j |  j t j  S)z;Path to the deploy-hook directory for the renew subcommand.)r   r   r!   r.   r   ZRENEWAL_DEPLOY_HOOKS_DIR)r   r   r   r   renewal_deploy_hooks_dir   s    z(NamespaceConfig.renewal_deploy_hooks_dirc             C   s   t  j j |  j t j  S)z9Path to the post-hook directory for the renew subcommand.)r   r   r!   r.   r   ZRENEWAL_POST_HOOKS_DIR)r   r   r   r   renewal_post_hooks_dir   s    z&NamespaceConfig.renewal_post_hooks_dirN)__name__
__module____qualname____doc__r   r   r   propertyr   r    r   r"   r#   r$   r%   r&   r*   r+   r,   r-   r.   r/   r0   r1   r   r   r   r   r      s(   
r   c             C   sg   |  j  |  j k r- t j d j |  j    |  j j d k	 rc x! |  j j D] } t j |  qL Wd S)zValidate command line options and display error message if
    requirements are not met.

    :param config: IConfig instance holding user configuration
    :type args: :class:`certbot.interfaces.IConfig`

    z;Trying to run http-01 and tls-sni-01 on the same port ({0})N)	Zhttp01_portZtls_sni_01_portr   ZConfigurationErrorformatr	   Zdomainsr   Zenforce_domain_sanity)configZdomainr   r   r   r      s    	r   )r5   r'   r   Zsix.moves.urllibr   Zzope.interfacezopeZcertbotr   r   r   r   r   Z	interfaceZimplementerZIConfigr
   r   r   r   r   r   r   <module>   s   ~