a }|gyX@sndZddlZddlZddlZddlmZddlmZddlmZddlmZddlm 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(GdddZ)dS)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@seZdZdZeeeeddddZgdZeddd Z eee ee fed d d Z e dd ddZeeefdddZeejdddZe dddZe dd ddZe dd ddZddddZeeeee ee fdddZee eeeefeedd d!d"Zee eeeefeeejd d#d$Zeedd%d&d'Zd2eeeee d)d*d+Z!e"j#dd,d-d.Z$e ee feeee fd/d0d1Z%dS)3HelpfulArgumentParserzArgparse 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. N)argspluginsreturnc Csddlm}|j|j|j|j|j|j|j|j|j |j |j |j |j|j |j|j|jd|_ttjj|_g|_gd}|t|j|jdg7}t|}||dg|_||_|jr|jddkrd|jd<||d|j}|d|j}|t|t rt|t r|p||_!nt|t"r*|n||_!|#||j!}|$|j!|_%i|_&t'j(d |t)d d gt*d d +d,t*d d|_-d|j-_.|dS)Nr)main)authcertonlyruninstallrregisterupdate_account show_account unregisterrenewrevokerollback everything certificatesdeleteenhance reconfigure)allZsecuritypathsZ automationZtestingZmanagehelp--help-hcertbot-c--configZ config_filesz"path to config file (default: {0})z and )progusageformatter_classZargs_for_setting_config_pathZdefault_config_filesZconfig_arg_help_messageF)/certbot._internalr r"r#r$Z plugins_cmdr%r&r'r(r)r*r+r-r.r/r0VERBS display_objZNoninteractiveDisplaysysstdoutZ notificationnotifyactionslistCOMMANDS_TOPICS help_topicsrdetermine_verbprescan_for_flag isinstanceboolhelp_argstr _usage_stringdetermine_help_topicsvisible_topicsgroupsconfigargparseZ ArgParserrrformatjoinparserZ_add_config_file_help) selfrrr Z HELP_TOPICSZ plugin_namesZhelp1Zhelp2Z short_usagerUA/usr/lib/python3.9/site-packages/certbot/_internal/cli/helpful.py__init__-sd    zHelpfulArgumentParser.__init__)ZcommandZcommandsZ subcommand subcommandsverbs)rcCsTtddtD}d}ttD](\}}|dd}|dj|||d7}q|d7}|S) Ncss|]}t|VqdSN)len).0vrUrUrV vz:HelpfulArgumentParser._list_subcommands..z,The full list of available SUBCOMMANDS is: shortz{0:<{length}} {1} )lengthzG You can get more help on a specific subcommand with --help SUBCOMMAND )maxrsortedrgetrQ)rTZlongesttextverbZpropsdocrUrUrV_list_subcommandsus z'HelpfulArgumentParser._list_subcommands)rrJrcCsd|vrd}nd}d|vr d}nd}t}|durV||t||fttdnl||jvr~|||tdnD|d kr|t||f7}n*t|t rt |i d 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) ZnginxzH--nginx Use the Nginx plugin for authentication & installationz+(the certbot nginx plugin is not installed)ZapachezI--apache Use the Apache plugin for authentication & installationz,(the certbot apache plugin is not installed)Trr1r:N) rrArrr?exitrDrirHrKrre)rTrrJZ nginx_docZ apache_docr:ZcustomrUrUrVrLs&     z#HelpfulArgumentParser._usage_string)configrcCs$|jdtjkr |jdkr g|_dS)z8Make "certbot renew" safe if domains are set in cli.ini.domainsr)N)Zargument_sourcesr CONFIG_FILErgrlrTrkrUrUrV&remove_config_file_domains_for_renewalszr_z=HelpfulArgumentParser._build_sources_dict..) settings_dictsourcercs2fdd|D}fdd|DdS)Ncs*g|]"\}\}}|dur"|n|qSrZ)_find_action_for_arg)r\argrr_)rTrUrV s zTHelpfulArgumentParser._build_sources_dict..update_result..csi|] }|jqSrU)rprqrurUrVrsr_zTHelpfulArgumentParser._build_sources_dict..update_result..)itemsupdate)rtrurBresultrTrzrV update_results z@HelpfulArgumentParser._build_sources_dict..update_resultZ config_fileZenv_varZ command_linera-)r7r8Z config_dir=r --)rBrSZget_source_to_settings_dictrrKrrPActionr startswithrmreZENV_VARZ COMMAND_LINEsplitappendrvrp) rTZsource_to_settings_dictrZ source_keyrtrxZunprocessed_argsrrwZ short_argrrrUr}rV_build_sources_dicts>         z)HelpfulArgumentParser._build_sources_dict)rwrcCst|ddkrd|}|jD]}||jvr|Sq|jD]&}|jD]}||rB|SqBq8td|ddS)Nrrrz!Action corresponding to argument z is None)rBoption_stringsrAssertionError)rTrwrr option_stringrUrUrVrvs       z*HelpfulArgumentParser._find_action_for_argcCs<|j|j}|j|j|_|j|_t|}||| ||jdkrl|j rft d tjd|_|j r|jrt d tj|js|jr|||jr|||jr|jsd|_|jrt||jrtdd|jDrt d|jr|jrt dt|j t!r8t"|j d kr8t d |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} conflictcss|]}t|VqdSrZ)r Zis_wildcard_domainr\drUrUrVr^0r_z3HelpfulArgumentParser.parse_args..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.)#rS parse_argsrr=rgfuncrZset_argument_sourcesrroZforce_interactiver ErrorrQr ZFORCE_INTERACTIVE_FLAGZnoninteractive_modeZstagingdry_runset_test_servercsr handle_csrZ must_stapleZstapleZvalidate_hooksr allow_subset_of_namesanyrlZhstsZ auto_hstsrHZkey_typerCr[)rTZ parsed_argsrkrUrUrVrsP         z HelpfulArgumentParser.parse_argscCs 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.)rrgrnrUrUrVr>sz%HelpfulArgumentParser.set_test_serverc Cs|jdkrtd|jr$td|jdd\}}t||\}}}|D]}t||qL|sttd|jd||f|_dd|D}t |j } || krt d d |d | d S) 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 domaincSsh|] }|qSrU)lowerrrUrUrV ^r_z3HelpfulArgumentParser.handle_csr..zMInconsistent domain requests: From the CSR: {0} From command line/config: {1}z, N)rgr rrrr Zimport_csr_filerZ actual_csrsetrlZConfigurationErrorrQrR) rTrkZcsrfilecontentstyprrldomainZ csr_domainsZconfig_domainsrUrUrVrDs.      z HelpfulArgumentParser.handle_csrcCszd|jvsd|jvrd|_dSt|jD]F\}}||jvr(|}|dkrJd}|dkrVd}||_|j|dSq(d|_dS) zDetermines the verb/subcommand provided by the user. This function works around some of the limitations of argparse. r5r4r3Nr!r"r,r#)rrg enumerater=pop)rTitokenrgrUrUrVrFfs  z$HelpfulArgumentParser.determine_verb)flagpossible_argumentsrcCsR||jvrdS|j|}z |j|d}||vr8|WSWntyLYn0dS)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)rTrrposZnxtrUrUrVrG~s    z&HelpfulArgumentParser.prescan_for_flag)topicsrkwargsrcOs$|j|j|g|Ri|dS)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)rBr_add)rTrrrrUrUrVadds zHelpfulArgumentParser.addcOs|d}|tjur&|jj|i|St|trJ|j|vr@|jn|d}n|}t|ts|j |r||j vr|j |}|j|i|S|jj|i|Snt j |d<|jj|i|SdS)Nrrrr3) rer ZDeprecatedArgumentActionrS add_argumentrHrCrJrIrNrOargparseSUPPRESS)rTrrrrrtopicgrouprUrUrVrs      zHelpfulArgumentParser._add) argument_namenum_argsrcCs t|jd}t|||dS)aAdds a deprecated argument with the name argument_name. Deprecated arguments are not shown in the help. If they are used on the command line, a warning is shown stating that the argument is deprecated and no other action is taken. :param str argument_name: Name of deprecated argument. :param int num_args: Number of arguments the option takes. N) functoolspartialrr add_deprecated_argument)rTrrZadd_funcrUrUrVrsz-HelpfulArgumentParser.add_deprecated_argumentrU)rrYrrcKsZ|j|rP|jj|fi||j|<|jrP|D] }|j|j|t|ddq.t||S)aCreate a new argument group. This method must be called once for every topic, however, calls to this function are left next to the argument definitions for clarity. :param str topic: Name of the new argument group. :param str verbs: List of subcommands that should be documented as part of this help group / topic :returns: The new argument group. :rtype: `HelpfulArgumentGroup` r`)r3)rNrSadd_argument_grouprOrJrrr)rTrrYrr]rUrUrV add_groups  zHelpfulArgumentParser.add_group)rrcCs4|D]&\}}|j||jd}|j||qdS)z Let each of the plugins add its own command line arguments, which may or may not be displayed as help topics. ) descriptionN)r{rZlong_descriptionZ plugin_clsZinject_parser_options)rTrnameZ plugin_epZparser_or_grouprUrUrVadd_plugin_argss z%HelpfulArgumentParser.add_plugin_args) chosen_topicrcsXdkr ddkrddkr0dd|jDSsDdd|jDSfd d|jDS) 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#r1cSsi|]}||dkqS)zcertbot-route53:authrUr\trUrUrVrsr_z?HelpfulArgumentParser.determine_help_topics..cSsi|] }|dqS)FrUrrUrUrVrsr_csi|]}||kqSrUrUrrrUrVrsr_)rE)rTrrUrrVrMs z+HelpfulArgumentParser.determine_help_topics)rU)&__name__ __module__ __qualname____doc__rrKrrWrDrirrIrLrrorrrrPrrvrrrrFrrGrrrintrrrrZPluginsRegistryrrMrUrUrUrVr%s:F #D8"       r)*rrrr?typingrrrrrrrrPr6r r r r<r r Z#certbot._internal.cli.cli_constantsrrrZcertbot._internal.cli.cli_utilsrrrrrZcertbot._internal.cli.verb_helprrZcertbot._internal.displayrr>Zcertbot._internal.pluginsrZcertbot.configurationrrrrUrUrUrVs>