M/eXtdZddlZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z ddl Z dd l mZdd l mZdd l mZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z#ddl$m%Z%ddl&m'Z'ddl&m(Z(GddZ)y)z$Certbot command line argument parserN)Any)Dict)Iterable)List)Optional)Tuple)Union) crypto_util)errors)util) constants)hooks)COMMAND_OVERVIEW)HELP_AND_VERSION_USAGE) SHORT_USAGE) add_domains)CustomHelpFormatter) flag_default)HelpfulArgumentGroup)set_test_server_options) VERB_HELP) VERB_HELP_MAP)obj)disco)ArgumentSource)NamespaceConfigc eZdZdZdeedeeddfdZgdZdefdZ deed e ee fdefd Z d e ddfd Zdeeeffd Zdedej&fdZde fdZd e ddfdZd e ddfdZd$dZdedeeede ee ffdZdee eeeefdededdfdZdee eeeefdededej&fdZdededdfdZd%dedeedede fd Z!de"jFddfd!Z$d"e ee fdeeee ffd#Z%y)&HelpfulArgumentParserzArgparse Wrapper. This class wraps argparse, adding the ability to make --help less verbose, and request help on specific subcategories at a time, eg 'certbot --help security' for security options. argspluginsreturnNcddlm}id|jd|jd|jd|jd|j d|j d |jd |jd |jd |jd |jd|jd|jd|jd|jd|jd|j d|j"i|_t'j(t*j,j.|_g|_gd}|t5|j$|j6zdgzz }t5|}||zdgz|_||_|j:r!|j:ddk(rd|j:d<|j=|j?d|j8}|j?d|j8}|tA|tBrtA|tBr |xs||_"ntA|tFr|n||_"|jI||jD}|jK|jD|_&i|_'tQjRd|tTddgtWddjYdj[tWd |_.d!|j\_/|y)"Nr)mainauthcertonlyruninstallr registerupdate_account show_account unregisterrenewrevokerollback everythingupdate_symlinks certificatesdeleteenhance reconfigure)allsecuritypaths automationtestingmanagehelp--help-hcertbot-c--config config_filesz"path to config file (default: {0})z and )progusageformatter_classargs_for_setting_config_pathdefault_config_filesconfig_arg_help_messageF)0certbot._internalr#r%r&r' plugins_cmdr(r)r*r+r,r-r.r0r1r2r3r4VERBS display_objNoninteractiveDisplaysysstdout notificationnotifyactionslistCOMMANDS_TOPICS help_topicsrdetermine_verbprescan_for_flag isinstanceboolhelp_argstr _usage_stringdetermine_help_topicsvisible_topicsgroupsconfigargparse ArgParserrrformatjoinparser_add_config_file_help) selfrr r# HELP_TOPICS plugin_nameshelp1help2 short_usages ?/usr/lib/python3/dist-packages/certbot/_internal/cli/helpful.py__init__zHelpfulArgumentParser.__init__-s* DMM    488  t||  t''     d11  D--  $//  TZZ  dkk     $((  t33  D-- dkk! " t||# $ 4++%  ,"77 CPP 46 ,a tDJJ'$*>*>>(KK ,0M 0;l0JdV0S 991/#DIIaL %%dD,<,<=%%h0@0@A eT "z%'>!NUDM%/s%;EDM(($--@ "88G;= $../*. );!-n!=$H$O$O \.9:%< = -2 ) )commandcommands subcommand subcommandsverbsctdtD}d}ttD].\}}|j dd}|dj |||z }0|dz }|S)Nc32K|]}t|ywN)len).0vs rk z:HelpfulArgumentParser._list_subcommands..ws4c!f4sz,The full list of available SUBCOMMANDS is: shortz{0:<{length}} {1} )lengthzG You can get more help on a specific subcommand with --help SUBCOMMAND )maxrsortedrgetra)relongesttextverbpropsdocs rk_list_subcommandsz'HelpfulArgumentParser._list_subcommandsvsp4m44?!), PKD%))GR(C -44T3w4O OD P [[ rmrYcd|vrd}nd}d|vrd}nd}t}|dur;|j|t||fzztzt j d|S||j vr9|j||jzt j d|S|d k(r|t||fzz }|St|tr,tj|ijd d }|r|n|}|S) a#Make usage strings late so that plugins can be initialised late :param plugins: all discovered plugins :param help_arg: False for none; True for --help; "TOPIC" for --help TOPIC :rtype: str :returns: a short usage string for the top of --help TOPIC) nginxzH--nginx Use the Nginx plugin for authentication & installationz+(the certbot nginx plugin is not installed)apachezI--apache Use the Apache plugin for authentication & installationz,(the certbot apache plugin is not installed)Trr5rCN) rrPrrrMexitrSrrWrZrr)rer rY nginx_doc apache_docrCcustoms rkr[z#HelpfulArgumentParser._usage_strings g bIEI w dJGJ t  KK 0J 3J JJMcc d HHQK -- - KK 6 6 88 9 HHQK   %Y(?? ?E  # &"&&x488$GF$F%E rmconfigc|jJ|jdtjk(r|jdk(rg|_yyy)z8Make "certbot renew" safe if domains are set in cli.ini.Ndomainsr,)argument_sourcesr CONFIG_FILErrrers rk&remove_config_file_domains_for_renewalz.update_resultsz0=/B/B/DFF+3 :@t005VSFGF MMgGFFKK/G HFGs "A' A. config_fileenv_var command_liner{-)r?r@ config_dir=r --)rQrrDEFAULTrcget_source_to_settings_dictrrZrr_Action startswithrrENV_VAR COMMAND_LINEsplitappendr) rersource_to_settings_dictr source_keyrrunprocessed_argsrr short_argrs ` @rk_build_sources_dictz)HelpfulArgumentParser._build_sources_dicts FJ\\S66;; 6 66S#'++"I"I"K Ic59N9NPS9S3T.T)U I"0 I59 I2 _J$$]35jA>C]C]^ _ -11)R@.BXBXY 4 43NCM$1"$5 !Q D' 5~~c*,,+9+F+FF<(#:))C.+CCZ))C.+C>>$'KK$&)W5  a {O45) 5. B2237&4&A&Av{{# B  yTs"Grc|ddk7rd|z}|jD]}||jvs|cS|jD]*}|jD]}|j|s|ccS,td|d)Nrrrz!Action corresponding to argument z is None)rQoption_stringsrAssertionError)rerr option_strings rkrz*HelpfulArgumentParser._find_action_for_args q6S=*Cll Ff+++   ll "F!'!6!6 "  ++C0!M " " @XNOOrmc|jj|j}|j|j|_|j|_t |}|j|j|j||jdk(rE|jr2tjdjtjd|_|jr>|j r2tjdjtj|j"s |j$r|j'||j(r|j+||j,r|j.sd|_|j0rt3j0||j4r1t7d|j8Drtjd|j:r!|j<rtjdt?|j@tBr-tE|j@dkDrtjd |S) zParses command line arguments and returns the result. :returns: parsed command line arguments :rtype: configuration.NamespaceConfig r,z{0} cannot be used with renewTz.Flag for non-interactive mode and {0} conflictc3FK|]}tj|ywru)r is_wildcard_domain)rwds rkryz3HelpfulArgumentParser.parse_args..1sF!4**1-Fs!zFUsing --allow-subset-of-names with a wildcard domain is not supported.z@Parameters --hsts and --auto-hsts cannot be used simultaneously.rz8Only *one* --key-type type may be provided at this time.)#rc parse_argsrrJrfuncrset_argument_sourcesrrforce_interactiver Errorrar FORCE_INTERACTIVE_FLAGnoninteractive_modestagingdry_runset_test_servercsr handle_csr must_staplestaplevalidate_hooksrallow_subset_of_namesanyrhsts auto_hstsrWkey_typerRrv)re parsed_argsrs rkrz HelpfulArgumentParser.parse_argsskk,,TYY7 ::dii0 99  -##D$<$<$>? 33F; 99 ''ll3::!88:;;*.F &  # #(B(B,,@GG4467 7 >>V^^   ( :: OOF #   fmm FM    (  ' 'Fv~~FFll$HII ;;6++,,RT T foot ,V__1E1I,,JL L rmc.t|j|S)zUpdates server, break_my_certs, staging, tos, and register_unsafely_without_email in config as necessary to prepare to use the test server.)rrrs rkrz%HelpfulArgumentParser.set_test_server?s'tyy&99rmcj|jdk7rtjd|jrtjd|jdd\}}t j ||\}}}|D]}t|||s%tjd|jdz||f|_|Dchc]}|j} }t|j} | | k7rCtjdjdj| dj| y cc}w) zProcess a --csr flag.r%zCurrently, a CSR file may only be specified when obtaining a new or replacement via the certonly command. Please try the certonly command instead.z1--allow-subset-of-names cannot be used with --csrrzJUnfortunately, your CSR %s needs to have a SubjectAltName for every domainzMInconsistent domain requests: From the CSR: {0} From command line/config: {1}z, N)rr rrrr import_csr_filer actual_csrlowersetrConfigurationErrorrarb) rercsrfilecontentstyprrdomainr csr_domainsconfig_domainss rkrz HelpfulArgumentParser.handle_csrEs- ;;* $,, ;< <  ' ',,RS S"JJqO'77JS' (F  ' (,,\**Q- ! !!#J*12Qqwwy2 2V^^, . (++a +. .0IJL L )3s9D0cd|jvsd|jvrd|_yt|jD]G\}}||jvs|}|dk(rd}|dk(rd}||_|jj |yd|_y) zDetermines the verb/subcommand provided by the user. This function works around some of the limitations of argparse. r=r<r;Nr$r%r/r&)rr enumeraterJpop)reitokenrs rkrUz$HelpfulArgumentParser.determine_verbgs 499 DII 5DI !$)), HAu "6>%D<' D   a   rmflagpossible_argumentsc||jvry|jj|} |j|dz}||vr|S y#t$rYywxYw)asChecks cli input for flags. Check for a flag, which accepts a fixed set of possible arguments, in the command line; we will use this information to configure argparse's help correctly. Return the flag's argument, if it has one that matches the sequence @possible_arguments; otherwise return whether the flag is present. FrT)rindex IndexError)rerrposnxts rkrVz&HelpfulArgumentParser.prescan_for_flagsk tyy iiood# ))C!G$C(( )   sA AAtopicskwargscb|jj|j|g|i|y)a1Add a new command line argument. :param topics: str or [str] help topic(s) this should be listed under, or None for options that don't fit under a specific topic which will only be shown in "--help all" output. The first entry determines where the flag lives in the "--help all" output (None -> "optional arguments"). :param list *args: the names of this argument flag :param dict **kwargs: various argparse settings for this argument N)rQr_add)rerrrs rkaddzHelpfulArgumentParser.adds+ IDIIf>t>v>?rmc|jd}|tjur|jj|i|St |t r |j|vr |jn|d}n|}t |tsZ|j|rK||jvr!|j|}|j|i|S|jj|i|Stj|d<|jj|i|S)Nrrr;) rr DeprecatedArgumentActionrc add_argumentrWrRrYrXr]r^argparseSUPPRESS)rerrrrtopicgroups rkrzHelpfulArgumentParser._addsH% T22 2,4;;++T+>u+E # E*)u))4:6::/t{{//@@@%..F6N+4;;++T\}}|j||j}|jj ||@y)z Let each of the plugins add its own command line arguments, which may or may not be displayed as help topics. ) descriptionN)rrlong_description plugin_clsinject_parser_options)rer name plugin_epparser_or_groups rkadd_plugin_argsz%HelpfulArgumentParser.add_plugin_argssT '}} NOD)"nnT9B9S9S-UO  6 6 M Nrm chosen_topicc|dk(rd}|dk(rd}|dk(r|jDcic]}||dk7 c}S|s|jDcic]}|dc}S|jDcic]}|||k( c}Scc}wcc}wcc}w)z The user may have requested help on a topic, return a dict of which topics to display. @chosen_topic has prescan_for_flag's return type :returns: dict r$r%r/r&r5zcertbot-route53:authF)rT)rer ts rkr\z+HelpfulArgumentParser.determine_help_topicss 6 !%L < ' L 5 <@.>?1 $$??N7?s A- A2 A7)r!N))&__name__ __module__ __qualname____doc__rrZrrlrSrr rXr[rrrrrr_rrrrrrUrrVrrrintrrrrPluginsRegistryr r\rrmrkrr%s.DT#YD#D4DNTO 3 !Xc]!eCI>N!SV!F _ QU BT#~*=%>BHPP0E0EP.6O6p:o:$: LLTLD0ShxPS}>U#CI., @(5hsm)HSHCHDH81s18C=11$81. Nu'<'< N N@%T 2B@#' t(;#<@rmr)*rrrrMtypingrrrrrrr r_r>r r r rHr r#certbot._internal.cli.cli_constantsrrrcertbot._internal.cli.cli_utilsrrrrrcertbot._internal.cli.verb_helprrcertbot._internal.displayrrKcertbot._internal.pluginsrcertbot.configurationrrrrrmrkrsp* '#@F;7?8@C598+01r@r@rm