a ‚oev]ã@svdZddlZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z ddl Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl(m*Z*Gdd„dƒZ+dS)z$Certbot command line argument parseréN)Ú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)Ú VERB_HELP)Ú VERB_HELP_MAP)Úobj)Údisco)Úos)ÚArgumentSource)ÚNamespaceConfigc@s¨eZdZdZeeeeddœdd„Zgd¢Zedœdd „Z eee ee fed œd d „Z e dd œdd„Zeeefdœdd„Zeejdœdd„Ze dœdd„Ze dd œdd„Ze dd œdd„Zddœdd„Zeeeee ee fdœdd„Zee 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/œd0d1„Z%dS)3ÚHelpfulArgumentParserzØArgparse 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)ÚargsÚpluginsÚreturnc Cs–ddlm}|j|j|j|j|j|j|j|j|j |j |j |j |j|j |j|j|j|jdœ|_t tj¡j|_g|_gd¢}|t|jƒ|jdg7}t|ƒ}||dg|_||_|jrÐ|jddkrÐd|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)ÚauthÚcertonlyÚrunÚinstallrÚregisterÚupdate_accountÚ show_accountÚ unregisterÚrenewÚrevokeÚrollbackÚ everythingÚupdate_symlinksÚ certificatesÚdeleteÚenhanceÚ reconfigure)ÚallZsecurityÚpathsZ automationZtestingZmanageÚhelpú--helpú-hÚcertbotú-cú--configZ config_filesz"path to config file (default: {0})z and )ÚprogÚusageÚformatter_classZargs_for_setting_config_pathZdefault_config_filesZconfig_arg_help_messageF)0Úcertbot._internalr r"r#r$Z plugins_cmdr%r&r'r(r)r*r+r-r.r/r0r1ÚVERBSÚ display_objZNoninteractiveDisplayÚsysÚstdoutZ notificationÚnotifyÚactionsÚlistÚCOMMANDS_TOPICSÚ help_topicsrÚdetermine_verbÚprescan_for_flagÚ isinstanceÚboolÚhelp_argÚstrÚ _usage_stringÚdetermine_help_topicsÚvisible_topicsÚgroupsÚconfigargparseZ ArgParserrrÚformatÚjoinÚparserZ_add_config_file_help) Úselfrrr Z HELP_TOPICSZ plugin_namesZhelp1Zhelp2Z short_usage©rVú>C:\Program Files\Certbot\pkgs\certbot\_internal\cli\helpful.pyÚ__init__.sf î  ÿú zHelpfulArgumentParser.__init__)ZcommandZcommandsZ subcommandÚ subcommandsÚverbs)rcCsTtdd„tDƒƒ}d}ttƒD](\}}| dd¡}|dj|||d�7}q|d7}|S) Ncss|]}t|ƒVqdS©N)Úlen)Ú.0ÚvrVrVrWÚ xóz:HelpfulArgumentParser._list_subcommands..z,The full list of available SUBCOMMANDS is: ÚshortÚz{0:<{length}} {1} )ÚlengthzG You can get more help on a specific subcommand with --help SUBCOMMAND )ÚmaxrÚsortedrÚgetrR)rUZlongestÚtextÚverbZpropsÚdocrVrVrWÚ_list_subcommandsws z'HelpfulArgumentParser._list_subcommands)rrKrcCsÆd|vrd}nd}d|vr d}nd}t}|durV| |t||ft¡t d¡nl||jvr~| || ¡¡t d¡nD|d kr˜|t||f7}n*t|t ƒrÂt   |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)Trr2r;N) rrBrrr@ÚexitrErjrIrLrrf)rUrrKZ nginx_docZ apache_docr;ZcustomrVrVrWrM‚s&     z#HelpfulArgumentParser._usage_string)ÚconfigrcCs2|jdusJ‚|jdtjkr.|jdkr.g|_dS)z8Make "certbot renew" safe if domains are set in cli.ini.NÚdomainsr))Zargument_sourcesrÚ CONFIG_FILErhrm)rUrlrVrVrWÚ&remove_config_file_domains_for_renewal¥s ÿz³r`z=HelpfulArgumentParser._build_sources_dict..)Ú settings_dictÚsourcercs2‡fdd„| ¡Dƒ}ˆ ‡fdd„|Dƒ¡dS)Ncs*g|]"\}\}}|dur"ˆ |¡n|‘qSr[)Ú_find_action_for_arg)r]ÚargrrÚ_)rUrVrWÚ Âs ÿzTHelpfulArgumentParser._build_sources_dict..update_result..csi|] }|jˆ“qSrV)rprq©rurVrWrsÄr`zTHelpfulArgumentParser._build_sources_dict..update_result..)ÚitemsÚupdate)rtrurC©ÚresultrUrzrWÚ update_resultÀs ÿz@HelpfulArgumentParser._build_sources_dict..update_resultZ config_fileZenv_varZ command_linerbú-)r8r9Ú config_dirú=rú ú--é)rCrTZget_source_to_settings_dictrrLrrQÚActionrÚ startswithrnrfZENV_VARZ COMMAND_LINEÚsplitÚappendrvrp) rUZsource_to_settings_dictrZ source_keyrtrxZunprocessed_argsrrwZ short_argrrrVr}rWÚ_build_sources_dict­s> ÿ        z)HelpfulArgumentParser._build_sources_dict)rwrcCst|ddkrd|}|jD]}||jvr|Sq|jD]&}|jD]}| |¡rB|SqBq8td|›d�ƒ‚dS)Nrr€r„z!Action corresponding to argument z is None)rCÚoption_stringsr‡ÚAssertionError)rUrwrrÚ option_stringrVrVrWrvñs       z*HelpfulArgumentParser._find_action_for_argcCs<|j |j¡}|j|j|_|j|_t|ƒ}| | ¡¡|  |¡|jdkrl|j rft   d  tj¡¡‚d|_|j rŠ|jrŠt   d  tj¡¡‚|js–|jr | |¡|jr°| |¡|jrÂ|jsÂd|_|jrÒt |¡|jrötdd„|jDƒƒröt   d¡‚|j�r|j�rt   d¡‚t|j t!ƒ�r8t"|j ƒd k�r8t   d ¡‚|S) zžParses 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 |¡VqdSr[)r Zis_wildcard_domain©r]ÚdrVrVrWr_2r`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.r…z8Only *one* --key-type type may be provided at this time.)#rTÚ parse_argsrr>rhÚfuncrZset_argument_sourcesrŠroZforce_interactiver ÚErrorrRr ZFORCE_INTERACTIVE_FLAGZnoninteractive_modeÚstagingÚdry_runÚset_test_serverÚcsrÚ handle_csrZ must_stapleZstapleZvalidate_hooksr Úallow_subset_of_namesÚanyrmZhstsZ auto_hstsrIZkey_typerDr\)rUZ parsed_argsrlrVrVrWr�sP  ÿÿ ÿÿ      ÿÿz HelpfulArgumentParser.parse_argscCs”tdƒtjf}|jr(|j|vr(t d¡‚|jtdƒkr>tj|_|jr�|jdvr^t d|j¡‚d|_ |_t   t j   |jtjd¡¡r�d|_d|_dS)zGWe have --staging/--dry-run; perform sanity check and set config.serverÚserverz'--server value conflicts with --staging)r"r)zN--dry-run currently only works with the 'certonly' or 'renew' subcommands (%r)TÚ*N)rr Z STAGING_URIr“ršr r’r”rhZbreak_my_certsÚglobrÚpathrSr�Z ACCOUNTS_DIRZtosZregister_unsafely_without_email)rUrlZdefault_serversrVrVrWr•@s   ÿ z%HelpfulArgumentParser.set_test_serverc CsÀ|jdkrt d¡‚|jr$t d¡‚|jdd…\}}t ||¡\}}}|D]}t||ƒqL|stt d|jd¡‚||f|_dd„|Dƒ}t |j ƒ} || kr¼t  d   d   |¡d   | ¡¡¡‚d S) zProcess a --csr flag.r"z’Currently, 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 --csrrézJUnfortunately, your CSR %s needs to have a SubjectAltName for every domaincSsh|] }| ¡’qSrV)ÚlowerrŽrVrVrWÚ wr`z3HelpfulArgumentParser.handle_csr..zMInconsistent domain requests: From the CSR: {0} From command line/config: {1}z, N)rhr r’r˜r–r Zimport_csr_filerZ actual_csrÚsetrmZConfigurationErrorrRrS) rUrlZcsrfileÚcontentsÚtypr–rmÚdomainZ csr_domainsZconfig_domainsrVrVrWr—]s.    ÿÿ  ÿÿz HelpfulArgumentParser.handle_csrcCszd|jvsd|jvrd|_dSt|jƒD]F\}}||jvr(|}|dkrJd}|dkrVd}||_|j |¡dSq(d|_dS) z‡Determines the verb/subcommand provided by the user. This function works around some of the limitations of argparse. r6r5r4Nr!r"r,r#)rrhÚ enumerater>Úpop)rUÚiÚtokenrhrVrVrWrGs  z$HelpfulArgumentParser.determine_verb)ÚflagÚpossible_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. Fr…T)rÚindexÚ IndexError)rUr©rªÚposZnxtrVrVrWrH—s    z&HelpfulArgumentParser.prescan_for_flag)ÚtopicsrÚkwargsrcOs$|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)rCr‰Ú_add)rUr®rr¯rVrVrWÚadd­s zHelpfulArgumentParser.addcOsº| d¡}|tjur&|jj|i|¤ŽSt|tƒrJ|j|vr@|jn|d}n|}t|tƒsš|j |rš||j vr†|j |}|j|i|¤ŽS|jj|i|¤ŽSnt j |d<|jj|i|¤ŽSdS)Nrrrr4) rfr ZDeprecatedArgumentActionrTÚ add_argumentrIrDrKrJrOrPÚargparseÚSUPPRESS)rUr®rr¯rrÚtopicÚgrouprVrVrWr°¼s      zHelpfulArgumentParser._add)Ú argument_nameÚnum_argsrcCs t |jd¡}t |||¡dS)aŒAdds 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)Ú functoolsÚpartialr±r Úadd_deprecated_argument)rUr·r¸Zadd_funcrVrVrWr»Ûsz-HelpfulArgumentParser.add_deprecated_argumentrV)rµrZr¯rcKsZ|j|rP|jj|fi|¤Ž|j|<|jrP|D] }|j|j|t|dd�q.t||ƒS)aÙCreate 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` ra)r4)rOrTÚadd_argument_grouprPrKr²rr)rUrµrZr¯r^rVrVrWÚ add_group÷s  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{r½Zlong_descriptionZ plugin_clsZinject_parser_options)rUrÚnameZ plugin_epZparser_or_grouprVrVrWÚadd_plugin_argss ÿz%HelpfulArgumentParser.add_plugin_args)Ú chosen_topicrcsXˆdkr d‰ˆdkrd‰ˆdkr0dd„|jDƒSˆsDdd„|jDƒS‡fd d„|jDƒS) 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#r2cSsi|]}||dk“qS)zcertbot-route53:authrV©r]ÚtrVrVrWrs,r`z?HelpfulArgumentParser.determine_help_topics..cSsi|] }|d“qS)FrVrÂrVrVrWrs.r`csi|]}||ˆk“qSrVrVr©rÁrVrWrs/r`)rF)rUrÁrVrÄrWrNs z+HelpfulArgumentParser.determine_help_topics)rV)&Ú__name__Ú __module__Ú __qualname__Ú__doc__rrLrrXrErjrrJrMrrorrrŠrQr†rvr�r•r—rGrrHrr±r°Úintr»rr½rZPluginsRegistryrÀrNrVrVrVrWr&s:G #D8"  ÿ ÿ ÿ  ÿ  ÿr),rÈr³r¹rœr@ÚtypingrrrrrrrrQr7r r r r=r r Z#certbot._internal.cli.cli_constantsrrrZcertbot._internal.cli.cli_utilsrrrrZcertbot._internal.cli.verb_helprrZcertbot._internal.displayrr?Zcertbot._internal.pluginsrZcertbot.compatrZcertbot.configurationrrrrVrVrVrWÚs@