U
    ]                     @   s   d Z ddl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
 ddlmZ dd	lmZ eje	jG d
d deZdd ZdS )z$Certbot user-supplied configuration.    N)parse)	constants)errors)
interfaces)util)misc)osc                   @   s   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   sV   t | d| tj| jj| j_tj| jj| j_tj| jj| j_t	|  d S )N	namespace)
object__setattr__r   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 r   )setattrr
   )r   r   valuer   r   r   r   :   s    zNamespaceConfig.__setattr__c                 C   s&   t | 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S r   )accounts_dir_for_server_pathr   r   r   r   r   accounts_dirC   s    zNamespaceConfig.accounts_dirc                 C   s    t |}t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tjS r   )r   r   r#   r
   r   r   Z
BACKUP_DIRr!   r   r   r   
backup_dirM   s    zNamespaceConfig.backup_dirc                 C   s   t j| jjtjS r   )r   r   r#   r
   r   r   ZCSR_DIRr!   r   r   r   csr_dirQ   s    zNamespaceConfig.csr_dirc                 C   s   t j| jjtjS r   )r   r   r#   r
   r   r   ZIN_PROGRESS_DIRr!   r   r   r   in_progress_dirU   s    zNamespaceConfig.in_progress_dirc                 C   s   t j| jjtjS r   )r   r   r#   r
   r   r   ZKEY_DIRr!   r   r   r   key_dirY   s    zNamespaceConfig.key_dirc                 C   s   t j| jjtjS r   )r   r   r#   r
   r   r   ZTEMP_CHECKPOINT_DIRr!   r   r   r   temp_checkpoint_dir]   s     z#NamespaceConfig.temp_checkpoint_dirc                 C   s   t | j}t| |S r   )copydeepcopyr
   type)r   Z_memoZnew_nsr   r   r   __deepcopy__b   s    zNamespaceConfig.__deepcopy__c                 C   s   t j| jjtjS r   )r   r   r#   r
   r   r   ZARCHIVE_DIRr!   r   r   r   default_archive_dirh   s    z#NamespaceConfig.default_archive_dirc                 C   s   t j| jjtjS r   )r   r   r#   r
   r   r   ZLIVE_DIRr!   r   r   r   live_dirl   s    zNamespaceConfig.live_dirc                 C   s   t j| jjtjS r   )r   r   r#   r
   r   r   ZRENEWAL_CONFIGS_DIRr!   r   r   r   renewal_configs_dirp   s     z#NamespaceConfig.renewal_configs_dirc                 C   s   t 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_DIRr!   r   r   r   renewal_hooks_diru   s    z!NamespaceConfig.renewal_hooks_dirc                 C   s   t j| jtjS )z8Path to the pre-hook directory for the renew subcommand.)r   r   r#   r0   r   ZRENEWAL_PRE_HOOKS_DIRr!   r   r   r   renewal_pre_hooks_dir{   s    
z%NamespaceConfig.renewal_pre_hooks_dirc                 C   s   t j| jtjS )z;Path to the deploy-hook directory for the renew subcommand.)r   r   r#   r0   r   ZRENEWAL_DEPLOY_HOOKS_DIRr!   r   r   r   renewal_deploy_hooks_dir   s    
z(NamespaceConfig.renewal_deploy_hooks_dirc                 C   s   t j| jtjS )z9Path to the post-hook directory for the renew subcommand.)r   r   r#   r0   r   ZRENEWAL_POST_HOOKS_DIRr!   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/   r0   r1   r2   r3   r   r   r   r   r	      sD   













r	   c                 C   sF   | j | jkrtd| j| jjdk	rB| jjD ]}t| q2d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 https-port on the same port ({0})N)	Zhttp01_portZ
https_portr   ZConfigurationErrorformatr
   Zdomainsr   Zenforce_domain_sanity)ZconfigZdomainr   r   r   r      s    	r   )r7   r)   Zzope.interfacezopeZsix.moves.urllibr   Zcertbotr   r   r   r   Zcertbot.compatr   r   Z	interfaceZimplementerZIConfigr   r	   r   r   r   r   r   <module>   s   ~