
    M/e=                        d 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	 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      Z	 d,dej0                  dee   dej4                  dedeej6                     f
dZ	 d-dej0                  dee   dej4                  dedeej:                     f
dZ	 d.dej0                  dee   dej4                  dedeej>                     f
dZ dej0                  dej4                  deej:                     fdZ! e	dej6                        Z"dej0                  dee   dej4                  dedee   dee"   fdZ#deejH                     dedeejH                     fdZ%g dZ&dej0                  dej4                  d eej>                     d!eej:                     ddf
d"Z'dej0                  dej4                  d#edeeej:                     eej>                     f   fd$Z(d%ee   d&ee   dee   fd'Z)dej0                  deee   ee   f   fd(Z*d)ed*ee   dej4                  ddfd+Z+y)/z=Decide which plugins to use for authentication & installation    N)cast)Iterable)List)Optional)Tuple)Type)TypeVar)configuration)errors)
interfaces)disco)os)utilconfigdefaultpluginsquestionreturnc                 \    t        | |||t        j                  t        j                  f      S )zPick configurator plugin.)pick_pluginr   Authenticator	Installerr   r   r   r   s       E/usr/lib/python3/dist-packages/certbot/_internal/plugins/selection.pypick_configuratorr      s.    
 (		!	!:#7#78: :    c                 >    t        | |||t        j                  f      S )zPick installer plugin.)r   r   r   r   s       r   pick_installerr       s     
 vwJ<P<P;RSSr   c                 >    t        | |||t        j                  f      S )zPick authentication plugin.)r   r   r   r   s       r   pick_authenticatorr    (   s'     (Z-E-E,GI Ir   c                 v   t        |       \  }sy|j                  fd      }|j                  |        t        |      dkD  rt	        j
                  dz        |rCt        |j                               d   }t        j                  d|       |j                  |       S t	        j
                  dz        )aB  
    Get an unprepared interfaces.Installer object.

    :param certbot.configuration.NamespaceConfig config: Configuration
    :param certbot._internal.plugins.disco.PluginsRegistry plugins:
        All plugins registered as entry points.

    :returns: Unprepared installer plugin or None
    :rtype: Plugin or None
    Nc                 &    | j                        S N
check_name)p_epreq_insts    r   <lambda>z*get_unprepared_installer.<locals>.<lambda>B   s    T__X-F r      zfFound multiple installers with the name %s, Certbot is unable to determine which one to use. Skipping.r   zSelecting plugin: %sz:Could not select or initialize the requested installer %s.)
cli_plugin_requestsfilterinitlenr   PluginSelectionErrorlistvaluesloggerdebug)r   r   _
installersinstr'   s        @r   get_unprepared_installerr6   2   s     &f-KAx FGJOOF
:))46>?@ 	@ J%%'(++T2yy  

%
%DxOQ Qr   P)boundifacesc                    |j                  fd      }n1| j                  rt        j                  d      |j	                         }|j                  |      }|j                  |        |j                          |j                         }t        |      dkD  rZt        j                  d|       t        t        |j                               |      }|yt        t         |j                               S t        |      dk(  rOt        |j                               d   }t        j                  d|       |j"                  ry|j                         S t        j                  d       y)	a  Pick plugin.

    :param certbot.configuration.NamespaceConfig config: 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: Plugin

    Nc                 &    | j                        S r#   r$   )r&   r   s    r   r(   zpick_plugin.<locals>.<lambda>f   s    tw/G r   a  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.r)   zMultiple candidate plugins: %sr   zSingle candidate plugin: %szNo candidate plugin)r+   noninteractive_moder   MissingCommandlineFlagvisibler9   r,   prepare	availabler-   r1   r2   choose_pluginr/   r0   r   r7   misconfigured)	r   r   r   r   r9   filteredprepared
plugin_ep1
plugin_ep2s	    `       r   r   r   S   s)   " >>"GH%% //67 7 ??$v&HMM&!!#H
8}q5x@"4(9#:HE
Az())	X!	(//+,Q/
2J?##  *+r   rD   c                 R   | D cg c]  }|j                   |j                  rdndz   ! }}	 t        j                  ||d      \  }}|t        j                  k(  rH| |   }|j                  r5t        j
                  dj                  |j                               d       n|S yxc c}w )	zAllow 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`

    z [Misconfigured] T)force_interactivezxThe selected plugin encountered an error while parsing your server configuration and cannot be used. The error was:

{0}F)pauseN)description_with_namerB   display_utilmenuOKnotificationformatr?   )rD   r   	plugin_epoptscodeindexs         r   rA   rA      s     &' ++#,#:#:D 'D ' "''$$Oe<??" I&&))""(&):):)<"=UL
 !  	's   $B$)webrootmanual
standalonedns-cloudflaredns-digitaloceandns-dnsimpledns-dnsmadeeasy
dns-gehirn
dns-google
dns-linode
dns-luadns	dns-nsonedns-ovhdns-rfc2136dns-route53dns-sakuracloudauthr5   c                    d| _         |r$|j                  |      }|r|j                  | _         d| _        |r$|j                  |      }|r|j                  | _        t        j                  d| j                   | j                         y)zFUpdate the config entries to reflect the plugins we actually selected.Nz0Plugins selected: Authenticator %s, Installer %s)authenticator	find_initname	installerr1   info)r   r   re   r5   auth_epinst_eps         r   record_chosen_pluginsrn      sx      F##D)#*<<F F##D)&||F
KKB$$f&6&68r   verbc                 ~   t        |       \  }}d}|dk(  rd}|dk(  rJdx}}ddlm} |t        v r<|s:dj	                  |t
        j                  |      }	t        j                  |	      d	x}}|d
k(  rd}n(|dv r$d}| j                  rt        j                  d|       d}
d}|dk(  rU||k(  rPt        | ||      }t        t        t        j                      |      }
t        t        t        j"                     |      }n!|s|rt%        | |||      }|rt'        | ||      }
|r|st)        d||       |r|
st)        d||       |d
k(  rU|
S| j*                  xs | j,                  }|du xr |
j.                  dv }|s|r!t        t        t        j"                     |
      }t        j1                  d|
|       t3        | ||
|       ||
fS )a<  
    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: tuple of (`Installer` or None, `Authenticator` or None)
    :rtype: tuple
    rH   enhancezMWhich installer would you like to use to configure the selected enhancements?runTr   cli_commandzWith 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.)Fcertonly)installrq   zRSpecifying an authenticator doesn't make sense when running Certbot with verb "%s"Nrj   rg   )nginxapachez*Selected authenticator %s and installer %s)r*   certbot._internal.clirt   noninstaller_pluginsrP   r   linesepr   r=   rg   r1   warningr   r   r   r   r   r   r   r    diagnose_configurator_problemrw   rx   ri   r2   rn   )r   r   ro   req_authr'   installer_question	need_inst	need_authrt   msgrg   rj   configuratorselected_configuratorinteractively_selecteds                  r   choose_configurator_pluginsr      s    -V4HhyE u} $$	I5++HE FLV[F:  //44 %%	Iz		'	'	NN >?CE 9=M04Iu}X- )7CXj&>&>?N*"6"67F	&vxBTUI.vxIM %k8WE%oxI
 zm7 & = "*T!1!_m6H6HL_6_ $:Xj&:&:;]KI
LL=}iX&'=)Dm##r   
previouslynowc                     |s| S | r>| |k7  r9d}t        j                  |j                  t        |       t        |                  |S )z
    Setting configurators multiple ways is okay, as long as they all agree
    :param str previously: previously identified request for the installer/authenticator
    :param str now: the request currently being processed
    zIToo many flags setting configurators/installers/authenticators {0} -> {1})r   r.   rP   repr)r   r   r   s      r   set_configuratorr     sH     ]C--cjjj9I4PS9.UVVJr   c                 <   | j                   x}}t        || j                        }t        || j                        }| j                  rt        |d      }t        |d      }| j
                  rt        |d      }t        |d      }| j                  rt        |d      }| j                  rt        |d      }| j                  rt        |d      }| j                  rt        |d      }| j                  rt        |d      }| j                  rt        |d      }| j                  rt        |d	      }| j                  rt        |d
      }| j                  rt        |d      }| j                  rt        |d      }| j                   rt        |d      }| j"                  rt        |d      }| j$                  rt        |d      }| j&                  rt        |d      }| j(                  rt        |d      }| j*                  rt        |d      }t,        j/                  d||       ||fS )z
    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
    rw   rx   rW   rU   rV   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   z+Requested authenticator %s and installer %s)r   r   rj   rg   rw   rx   rW   rU   rV   dns_cloudflaredns_digitaloceandns_dnsimpledns_dnsmadeeasy
dns_gehirn
dns_google
dns_linode
dns_luadns	dns_nsonedns_ovhdns_rfc2136dns_route53dns_sakuracloudr1   r2   )r   r'   r~   s      r   r*   r*   $  s    !---Hx&*:*:;H&*>*>?H||#Hg6#Hg6}}#Hh7#Hh7#Hl;~~#Hi8}}#Hh7#H.>?#H.@A#Hn=#H.?@#Hl;#Hl;#Hl;#Hl;#Hk:~~#Hi8#Hm<#Hm<#H.?@
LL>(SXr   cfg_type	requestedc                     |r6||vrdj                  |      }nNdj                  |||   j                        }n.| dk(  rddlm} dj                  |      }ndj                  |       }t	        j
                  |      )a>  
    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
    z8The requested {0} plugin does not appear to be installedzkThe {0} plugin is not working; there may be problems with your existing configuration.
The error was: {1!r}rj   r   rs   zCertbot 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.z/{0} could not be determined or is not installed)rP   problemry   rt   r   r.   )r   r   r   r   rt   s        r   r}   r}   Z  s     G#LSST]^CHF9gi&8&@&@A  
[	 5 !&-	 	 @FFxP

%
%c
**r   )z<How would you like to authenticate and install certificates?)z+How would you like to install certificates?)z4How would you like to authenticate with the ACME CA?),__doc__loggingtypingr   r   r   r   r   r   r	   certbotr
   r   r   certbot._internal.pluginsr   certbot.compatr   certbot.displayr   rL   	getLogger__name__r1   NamespaceConfigstrPluginsRegistryPluginr   r   r   r   r    r6   r7   r   PluginEntryPointrA   rz   rn   r   r   r*   r}    r   r   <module>r      s8   C         !   +  0			8	$
'6:m;; :hsm :$44: #: ;C:CTCT:U: $QT=88 T8C= T!11T T !!5!56T(PI}<< IxPS} I % 5 5I!$I %Z%=%=>	IQ]%B%B Q&+&;&;Q@HI]I]@^Q< Cz(()555 5 5..5:=5 5+3A;5pD!7!78 $,U-C-C$D>I 8-"?"? 8%J_J_ 8 ()A)A B8 ()=)= >8CG8$O$(E(E O$).)>)>O$&)O$.3HZ=Q=Q4R4<Z=U=U4V5W /XO$d# Xc] xPS}  3 = = 3"8C=(3-#?@3l+C +HSM ++0+@+@+EI+r   