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*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) VERB_HELP) VERB_HELP_MAP)obj)disco)os)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|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 everythingupdate_symlinks 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)0certbot._internalr r"r#r$Z plugins_cmdr%r&r'r(r)r*r+r-r.r/r0r1VERBS 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_usagerV>C:\Program Files\Certbot\pkgs\certbot\_internal\cli\helpful.py__init__.sf    zHelpfulArgumentParser.__init__)ZcommandZcommandsZ subcommand subcommandsverbs)rcCsTtddtD}d}ttD](\}}|dd}|dj|||d7}q|d7}|S) Ncss|]}t|VqdSN)len).0vrVrVrW xz: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 )maxrsortedrgetrR)rUZlongesttextverbZpropsdocrVrVrW_list_subcommandsws z'HelpfulArgumentParser._list_subcommands)rrKrcCsd|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)Trr2r;N) rrBrrr@exitrErjrIrLrrf)rUrrKZ nginx_docZ apache_docr;ZcustomrVrVrWrMs&     z#HelpfulArgumentParser._usage_string)configrcCs2|jdusJ|jdtjkr.|jdkr.g|_dS)z8Make "certbot renew" safe if domains are set in cli.ini.Ndomainsr))Zargument_sourcesr CONFIG_FILErhrm)rUrlrVrVrW&remove_config_file_domains_for_renewals zr`z=HelpfulArgumentParser._build_sources_dict..) settings_dictsourcercs2fdd|D}fdd|DdS)Ncs*g|]"\}\}}|dur"|n|qSr[)_find_action_for_arg)r]argrr_)rUrVrW s zTHelpfulArgumentParser._build_sources_dict..update_result..csi|] }|jqSrV)rprqrurVrWrsr`zTHelpfulArgumentParser._build_sources_dict..update_result..)itemsupdate)rtrurCresultrUrzrW update_results z@HelpfulArgumentParser._build_sources_dict..update_resultZ config_fileZenv_varZ command_linerb-)r8r9 config_dir=r --)rCrTZget_source_to_settings_dictrrLrrQActionr startswithrnrfZENV_VARZ COMMAND_LINEsplitappendrvrp) rUZsource_to_settings_dictrZ source_keyrtrxZunprocessed_argsrrwZ short_argrrrVr}rW_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)rCoption_stringsrAssertionError)rUrwrr option_stringrVrVrWrvs       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|VqdSr[)r Zis_wildcard_domainr]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.rz8Only *one* --key-type type may be provided at this time.)#rT parse_argsrr>rhfuncrZset_argument_sourcesrroZforce_interactiver ErrorrRr ZFORCE_INTERACTIVE_FLAGZnoninteractive_modestagingdry_runset_test_servercsr handle_csrZ must_stapleZstapleZvalidate_hooksr allow_subset_of_namesanyrmZhstsZ auto_hstsrIZkey_typerDr\)rUZ parsed_argsrlrVrVrWrsP         z HelpfulArgumentParser.parse_argscCstdtjf}|jr(|j|vr(td|jtdkr>tj|_|jr|jdvr^td|jd|_ |_t t j |jtjdrd|_d|_dS)zGWe have --staging/--dry-run; perform sanity check and set config.serverserverz'--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_URIrrr rrrhZbreak_my_certsglobrpathrSrZ ACCOUNTS_DIRZtosZregister_unsafely_without_email)rUrlZdefault_serversrVrVrWr@s    z%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|] }|qSrV)lowerrrVrVrW wr`z3HelpfulArgumentParser.handle_csr..zMInconsistent domain requests: From the CSR: {0} From command line/config: {1}z, N)rhr rrrr Zimport_csr_filerZ actual_csrsetrmZConfigurationErrorrRrS) rUrlZcsrfilecontentstyprrmdomainZ csr_domainsZconfig_domainsrVrVrWr]s.      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. r6r5r4Nr!r"r,r#)rrh enumerater>pop)rUitokenrhrVrVrWrGs  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)rUrrposZnxtrVrVrWrHs    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)rCr_add)rUrrrrVrVrWadds 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)Nrrrr4) rfr ZDeprecatedArgumentActionrT add_argumentrIrDrKrJrOrPargparseSUPPRESS)rUrrrrrtopicgrouprVrVrWrs      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)rUrrZadd_funcrVrVrWrsz-HelpfulArgumentParser.add_deprecated_argumentrV)rrZrrcKsZ|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` ra)r4)rOrTadd_argument_grouprPrKrrr)rUrrZrr^rVrVrW 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)rUrnameZ plugin_epZparser_or_grouprVrVrWadd_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#r2cSsi|]}||dkqS)zcertbot-route53:authrVr]trVrVrWrs,r`z?HelpfulArgumentParser.determine_help_topics..cSsi|] }|dqS)FrVrrVrVrWrs.r`csi|]}||kqSrVrVrrrVrWrs/r`)rF)rUrrVrrWrNs z+HelpfulArgumentParser.determine_help_topics)rV)&__name__ __module__ __qualname____doc__rrLrrXrErjrrJrMrrorrrrQrrvrrrrGrrHrrrintrrrrZPluginsRegistryrrNrVrVrVrWr&s:G #D8"       r),rrrrr@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.configurationrrrrVrVrVrWs@