ó
Á£ô_c           @  s>  d  Z  d d l m Z d d l 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 e j e ƒ Z e j j Z d d	 „ Z d
 d „ Z d d „ Z d „  Z d „  Z d „  Z d d d d d d d d d d d d d d d d  d! g Z d" „  Z d# „  Z d$ „  Z d% „  Z d& „  Z  d S('   s=   Decide which plugins to use for authentication & installationiÿÿÿÿ(   t   print_functionN(   t   errors(   t
   interfaces(   t   os(   t   utils<   How would you like to authenticate and install certificates?c         C  s"   t  |  | | | t j t j f ƒ S(   s   Pick configurator plugin.(   t   pick_pluginR   t   IAuthenticatort
   IInstaller(   t   configt   defaultt   pluginst   question(    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   pick_configurator   s    s+   How would you like to install certificates?c         C  s   t  |  | | | t j f ƒ S(   s   Pick installer plugin.(   R   R   R   (   R   R	   R
   R   (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   pick_installer   s    s4   How would you like to authenticate with the ACME CA?c         C  s   t  |  | | | t j f ƒ S(   s   Pick authentication plugin.(   R   R   R   (   R   R	   R
   R   (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   pick_authenticator"   s    c           sÎ   t  |  ƒ \ } ‰  ˆ  s d S| j ‡  f d †  ƒ } | j |  ƒ | j t j f ƒ } t | ƒ d k r~ t j	 d ˆ  ƒ ‚ n  | r· t
 | j ƒ  ƒ d } t j d | ƒ | j |  ƒ St j	 d ˆ  ƒ ‚ d S(   s9  
    Get an unprepared interfaces.IInstaller object.

    :param certbot.interfaces.IConfig config: Configuration
    :param certbot._internal.plugins.disco.PluginsRegistry plugins:
        All plugins registered as entry points.

    :returns: Unprepared installer plugin or None
    :rtype: IPlugin or None
    c           s   |  j  ˆ  ƒ S(   N(   t
   check_name(   t   p_ep(   t   req_inst(    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   <lambda>9   s    i   sf   Found multiple installers with the name %s, Certbot is unable to determine which one to use. Skipping.i    s   Selecting plugin: %ss:   Could not select or initialize the requested installer %s.N(   t   cli_plugin_requestst   Nonet   filtert   initt   verifyR   R   t   lenR   t   PluginSelectionErrort   listt   valuest   loggert   debug(   R   R
   t   _t
   installerst   inst(    (   R   sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   get_unprepared_installer*   s     c   	        sG  ˆ  d k	 r' | j ‡  f d †  ƒ } n0 |  j rB t j d ƒ ‚ n  | j ƒ  j | ƒ } | j |  ƒ | j | ƒ } | j	 ƒ  | j
 ƒ  } t | ƒ d k rã t j d | ƒ t t t j | ƒ ƒ | ƒ } | d k rÙ d S| j ƒ  St | ƒ d k r2t | j ƒ  ƒ d } t j d | ƒ | j r(d S| j ƒ  St j d ƒ d Sd S(	   sà  Pick plugin.

    :param certbot.interfaces.IConfig: Configuration
    :param str default: Plugin name supplied by user or ``None``.
    :param certbot._internal.plugins.disco.PluginsRegistry plugins:
        All plugins registered as entry points.
    :param str question: Question to be presented to the user in case
        multiple candidates are found.
    :param list ifaces: Interfaces that plugins must provide.

    :returns: Initialized plugin.
    :rtype: IPlugin

    c           s   |  j  ˆ  ƒ S(   N(   R   (   R   (   R	   (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyR   Y   s    s  Missing command line flags. For non-interactive execution, you will need to specify a plugin on the command line.  Run with '--help plugins' to see a list of options, and see https://eff.org/letsencrypt-plugins for more detail on what the plugins do and how to use them.i   s   Multiple candidate plugins: %si    s   Single candidate plugin: %ss   No candidate pluginN(   R   R   t   noninteractive_modeR   t   MissingCommandlineFlagt   visiblet   ifacesR   R   t   preparet	   availableR   R   R   t   choose_pluginR   t   sixt
   itervaluesR   t   misconfigured(	   R   R	   R
   R   R%   t   filteredt   verifiedt   preparedt	   plugin_ep(    (   R	   sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyR   H   s0    	

	
c         C  sX  g  |  D]" } | j  | j r" d n d ^ q } t d „  |  Dƒ ƒ } xt rSt t j ƒ } d t j k r× | d d h k r× g  t	 |  ƒ D]! \ } } | j
 d k r‹ | ^ q‹ d } | j | | d | ƒ\ }	 }
 n | j | | d	 t ƒ\ }	 }
 |	 t j k rL|  |
 } | j rEt t j ƒ j d
 j | j ƒ  ƒ d t ƒqP| SqH d SqH Wd S(   sû   Allow the user to choose their plugin.

    :param list prepared: List of `~.PluginEntryPoint`.
    :param str question: Question to be presented to the user.

    :returns: Plugin entry point chosen by the user.
    :rtype: `~.PluginEntryPoint`

    s    [Misconfigured]t    c         s  s   |  ] } | j  Vq d  S(   N(   t   name(   t   .0R/   (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pys	   <genexpr>‹   s    t   CERTBOT_AUTOt   apachet   nginxi    R	   t   force_interactivesx   The selected plugin encountered an error while parsing your server configuration and cannot be used. The error was:

{0}t   pauseN(   t   description_with_nameR+   t   sett   Truet   z_utilR   t   IDisplayR   t   environt	   enumerateR1   t   menut   display_utilt   OKt   notificationt   formatR&   t   FalseR   (   R.   R   R/   t   optst   namest   dispt   nt   pt
   apache_idxt   codet   index(    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyR(   ~   s"    
,	!8!
	t   webroott   manualt
   standalones   dns-cloudflares   dns-cloudxnss   dns-digitaloceans   dns-dnsimples   dns-dnsmadeeasys
   dns-gehirns
   dns-googles
   dns-linodes
   dns-luadnss	   dns-nsones   dns-ovhs   dns-rfc2136s   dns-route53s   dns-sakuracloudc         C  s_   | r | j  | ƒ j n d |  _ | r9 | j  | ƒ j n d |  _ t j d |  j |  j ƒ d S(   sF   Update the config entries to reflect the plugins we actually selected.s0   Plugins selected: Authenticator %s, Installer %sN(   t	   find_initR1   R   t   authenticatort	   installerR   t   info(   R   R
   t   authR    (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   record_chosen_pluginsª   s    !!	c      
   C  sÍ  t  |  ƒ \ } } d } | d k r- d } n  | d k r“ t } } d d l m } | t k r | r d j | t j | ƒ }	 t	 j
 |	 ƒ ‚ q n
 t } } | d k r² t } n1 | d k rã t } |  j rã t j d	 | ƒ qã n  d }
 } | d k r| | k rt |  | | ƒ }
 } n? | s*| rBt |  | | | ƒ } n  | r]t |  | | ƒ }
 n  t j d
 |
 | ƒ | r| rt d | | ƒ n  | r°|
 r°t d | | ƒ n  t |  | |
 | ƒ | |
 f S(   s;  
    Figure out which configurator we're going to use, modifies
    config.authenticator and config.installer strings to reflect that choice if
    necessary.

    :raises errors.PluginSelectionError if there was a problem

    :returns: (an `IAuthenticator` or None, an `IInstaller` or None)
    :rtype: tuple
    t   enhancesM   Which installer would you like to use to configure the selected enhancements?t   runiÿÿÿÿ(   t   cli_commandsé   With the {0} plugin, you probably want to use the "certonly" command, eg:{1}{1}    {2} certonly --{0}{1}{1}(Alternatively, add a --installer flag. See https://eff.org/letsencrypt-plugins{1} and "--help plugins" for more information.)t   certonlyt   installsR   Specifying an authenticator doesn't make sense when running Certbot with verb "%s"s*   Selected authenticator %s and installer %sRR   RQ   N(   RZ   RV   (   R   R   R:   t   certbot._internal.cliRX   t   noninstaller_pluginsRC   R   t   linesepR   R#   RD   RQ   R   t   warningR   R   R   R   t   diagnose_configurator_problemRU   (   R   R
   t   verbt   req_authR   t   installer_questiont	   need_instt	   need_authRX   t   msgRQ   RR   (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   choose_configurator_plugins²   sB    	

			
c         C  sS   | s
 |  S|  rO |  | k rO d } t  j | j t |  ƒ t | ƒ ƒ ƒ ‚ qO n  | S(   sé   
    Setting configurators multiple ways is okay, as long as they all agree
    :param str previously: previously identified request for the installer/authenticator
    :param str requested: the request currently being processed
    sI   Too many flags setting configurators/installers/authenticators {0} -> {1}(   R   R   RC   t   repr(   t
   previouslyt   nowRe   (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   set_configuratorñ   s    -c         C  sm  |  j  } } t | |  j ƒ } t | |  j ƒ } |  j r[ t | d ƒ } t | d ƒ } n  |  j r… t | d ƒ } t | d ƒ } n  |  j r  t | d ƒ } n  |  j r» t | d ƒ } n  |  j rÖ t | d ƒ } n  |  j	 rñ t | d ƒ } n  |  j
 rt | d ƒ } n  |  j r't | d ƒ } n  |  j rBt | d	 ƒ } n  |  j r]t | d
 ƒ } n  |  j rxt | d ƒ } n  |  j r“t | d ƒ } n  |  j r®t | d ƒ } n  |  j rÉt | d ƒ } n  |  j rät | d ƒ } n  |  j rÿt | d ƒ } n  |  j rt | d ƒ } n  |  j r5t | d ƒ } n  |  j rPt | d ƒ } n  t j d | | ƒ | | f S(   s¿   
    Figure out which plugins the user requested with CLI and config options

    :returns: (requested authenticator string or None, requested installer string or None)
    :rtype: tuple
    R5   R4   RO   RM   RN   s   dns-cloudflares   dns-cloudxnss   dns-digitaloceans   dns-dnsimples   dns-dnsmadeeasys
   dns-gehirns
   dns-googles
   dns-linodes
   dns-luadnss	   dns-nsones   dns-ovhs   dns-rfc2136s   dns-route53s   dns-sakuraclouds+   Requested authenticator %s and installer %s(   t   configuratorRj   RR   RQ   R5   R4   RO   RM   RN   t   dns_cloudflaret   dns_cloudxnst   dns_digitaloceant   dns_dnsimplet   dns_dnsmadeeasyt
   dns_gehirnt
   dns_googlet
   dns_linodet
   dns_luadnst	   dns_nsonet   dns_ovht   dns_rfc2136t   dns_route53t   dns_sakuracloudR   R   (   R   R   Ra   (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyR     sZ    																			c         C  s   | r@ | | k r$ d j  | ƒ } q} d j  | | | j ƒ } n= |  d k rn d d l m } d j  | ƒ } n d j  |  ƒ } t j | ƒ ‚ d S(	   s>  
    Raise the most helpful error message about a plugin being unavailable

    :param str cfg_type: either "installer" or "authenticator"
    :param str requested: the plugin that was requested
    :param .PluginsRegistry plugins: available plugins

    :raises error.PluginSelectionError: if there was a problem
    s8   The requested {0} plugin does not appear to be installedsk   The {0} plugin is not working; there may be problems with your existing configuration.
The error was: {1!r}RR   iÿÿÿÿ(   RX   sû   Certbot doesn't know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run "{0} certonly" to do so. You'll need to manually configure your web server to use the resulting certificate.s/   {0} could not be determined or is not installedN(   RC   t   problemR[   RX   R   R   (   t   cfg_typet	   requestedR
   Re   RX   (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyR_   8  s    (!   t   __doc__t
   __future__R    t   loggingR)   t   zope.componentt   zopet   certbotR   R   t   certbot.compatR   t   certbot.displayR   R@   t	   getLoggert   __name__R   t	   componentt
   getUtilityR;   R   R   R   R!   R   R(   R\   RU   Rf   Rj   R   R_   (    (    (    sG   /usr/lib/python2.7/site-packages/certbot/_internal/plugins/selection.pyt   <module>   s2   			6	'		?		7