a ‚oeš2ã@s dZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZddlZdd lmZdd lmZddlmZddlmZddlmZz(ddlmZddlmZddlmZWn e�ydZdZdZYn0e e ¡Z!Gdd„dƒZ"e#e e#efe e#efeee e#effdœdd„Z$Gdd„dej%ƒZ&Gdd„dƒZ'eee'ej(e ƒƒej(e <dS)z;Common code for DNS Authenticator Plugins built on Lexicon.éN)Ú ModuleType)ÚAny)Úcast)ÚDict)ÚList)ÚMapping)ÚOptional)ÚTuple)ÚUnion)Ú HTTPError)ÚRequestException)Ú configuration)Úerrors)Ú dns_common)ÚClient)ÚConfigResolver)ÚProviderc@s†eZdZdZddœdd„Zeeeddœdd„Zeeeddœd d „Zedd œd d „Ze ee e j dœdd„Z eee e j dœdd„ZdS)Ú LexiconClientzº Encapsulates all communication with a DNS provider via Lexicon. .. deprecated:: 2.7.0 Please use certbot.plugins.dns_common_lexicon.LexiconDNSAuthenticator instead. N©ÚreturncCs|dS©N©©ÚselfrrúCC:\Program Files\Certbot\pkgs\certbot\plugins\dns_common_lexicon.pyÚ__init__0szLexiconClient.__init__)ÚdomainÚ record_nameÚrecord_contentrc Csj| |¡z|jjd||d�WnDtyd}z,tjd|dd�t d |¡¡‚WYd}~n d}~00dS)a§ Add a TXT record using the supplied information. :param str domain: The domain to use to look up the managed zone. :param str record_name: The record name (typically beginning with '_acme-challenge.'). :param str record_content: The record content (typically the challenge validation). :raises errors.PluginError: if an error occurs communicating with the DNS Provider API ÚTXT©ZrtypeÚnameZcontentú'Encountered error adding TXT record: %sT©Úexc_infoúError adding TXT record: {0}N) Ú_find_domain_idÚproviderÚ create_recordr ÚloggerÚdebugrÚ PluginErrorÚformat©rrrrÚerrrÚadd_txt_record3s zLexiconClient.add_txt_recordc Cs˜z| |¡Wn8tjyF}ztjd|dd�WYd}~dSd}~00z|jjd||d�Wn4ty’}ztjd|dd�WYd}~n d}~00dS)a« Delete a TXT record using the supplied information. :param str domain: The domain to use to look up the managed zone. :param str record_name: The record name (typically beginning with '_acme-challenge.'). :param str record_content: The record content (typically the challenge validation). :raises errors.PluginError: if an error occurs communicating with the DNS Provider API ú7Encountered error finding domain_id during deletion: %sTr#Nrr ú)Encountered error deleting TXT record: %s)r&rr+r)r*r'Ú delete_recordr r-rrrÚdel_txt_recordDs ÿzLexiconClient.del_txt_record©rrc CsÎt |¡}|D]¨}z4t|jdƒr.||jjd<n||j_|j ¡WdSty~}z | ||¡}|rj|‚WYd}~qd}~0t y´}z |  ||¡}|r |‚WYd}~qd}~00qt   d  ||¡¡‚dS)zÆ Find the domain_id for a given domain. :param str domain: The domain for which to find the domain_id. :raises errors.PluginError: if the domain_id cannot be found. ÚoptionsrNúAUnable to determine zone identifier for {0} using zone names: {1})rÚbase_domain_name_guessesÚhasattrr'r5rZ authenticater Ú_handle_http_errorÚ ExceptionÚ_handle_general_errorrr+r,©rrZdomain_name_guessesÚ domain_namer.Zresult1Zresult2rrrr&Ys&     ÿzLexiconClient._find_domain_id©r.r=rcCst d ||¡¡S©Nz/Error determining zone identifier for {0}: {1}.©rr+r,©rr.r=rrrr9}sÿz LexiconClient._handle_http_errorcCs$t|ƒ d¡s t d ||¡¡SdS©NzNo domain foundz9Unexpected error determining zone identifier for {0}: {1}©ÚstrÚ startswithrr+r,rArrrr;�s ÿz#LexiconClient._handle_general_error)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrDr/r3r&r rrr+r9r:r;rrrrr(s$r)Úlexicon_provider_nameÚlexicon_optionsÚprovider_optionsrcCsRd|i}| |¡tdur(| |¡|Si}| |¡|||<tƒ |¡ ¡SdS)aá Convenient function to build a Lexicon 2.x/3.x config object. :param str lexicon_provider_name: the name of the lexicon provider to use :param dict lexicon_options: options specific to lexicon :param dict provider_options: options specific to provider :return: configuration to apply to the provider :rtype: ConfigurationResolver or dict .. deprecated:: 2.7.0 Please use certbot.plugins.dns_common_lexicon.LexiconDNSAuthenticator instead. Ú provider_nameN)ÚupdaterÚ with_dictÚwith_env)rJrKrLZ config_dictZprovider_configrrrÚbuild_lexicon_configˆs   rQcsîeZdZdZejedœ‡fdd„ Zee j edœdd„ƒƒZ ee dœdd „ƒZ eeed d œd d „Zeedœdd„Zd dœdd„Zeeed dœdd„Zeeed dœdd„Zeedœdd„Zeeeejdœdd„Zeeeejdœdd„Z‡ZS)ÚLexiconDNSAuthenticatorzr Base class for a DNS authenticator that uses Lexicon client as backend to execute DNS record updates )Úconfigr!cstƒ ||¡g|_|dSr)ÚsuperrÚ_provider_options)rrSr!©Ú __class__rrr«sz LexiconDNSAuthenticator.__init__rcCsdS)z9 The name of the Lexicon provider to use NrrrrrÚ_provider_name°sz&LexiconDNSAuthenticator._provider_namecCsdS)zX Time to live to apply to the DNS records created by this Authenticator é<rrrrrÚ_ttl·szLexiconDNSAuthenticator._ttlN)Úcreds_var_nameÚcreds_var_labelÚlexicon_provider_option_namercCs|j |||f¡dSr)rUÚappend)rr[r\r]rrrÚ_add_provider_option¾sÿz,LexiconDNSAuthenticator._add_provider_optionr4c sPtˆdƒsˆ ¡d|d|dˆjdˆjˆj‡fdd„ˆjDƒi}tƒ |¡ ¡S)NÚ _credentialsrZ delegatedrMZttlcs"i|]}|dˆj |d¡“qS)ér)r`Zconf©Ú.0ÚitemrrrÚ ÏsÿzALexiconDNSAuthenticator._build_lexicon_config..)r8Ú_setup_credentialsrXrZrUrrOrP)rrZ dict_configrrrÚ_build_lexicon_configÃs ÿø z-LexiconDNSAuthenticator._build_lexicon_configcCs,|jdd|j›d�dd„|jDƒd�|_dS)NZ credentialszCredentials INI file for z DNS authenticatorcSsi|]}|d|d“qS)rérrbrrrreØóz>LexiconDNSAuthenticator._setup_credentials..)ÚkeyZlabelZrequired_variables)Z_configure_credentialsrXrUr`rrrrrfÔs  ýz*LexiconDNSAuthenticator._setup_credentials)rÚvalidation_nameÚ validationrc Cs–| |¡}zBt| |¡ƒ� }|jd||d�Wdƒn1s@0YWnDty�}z,tjd|dd�t d  |¡¡‚WYd}~n d}~00dS)Nrr r"Tr#r%) Ú_resolve_domainrrgr(r r)r*rr+r,)rrrkrlÚresolved_domainÚ operationsr.rrrÚ_performÛs 2z LexiconDNSAuthenticator._performc CsÄz| |¡}Wn8tjyF}ztjd|dd�WYd}~dSd}~00zBt| |¡ƒ� }|jd||d�Wdƒn1s~0YWn4ty¾}ztjd|dd�WYd}~n d}~00dS)Nr0Tr#rr r1) rmrr+r)r*rrgr2r )rrrkrlrnr.rorrrÚ_cleanupåsÿ2z LexiconDNSAuthenticator._cleanupc CsÖt |¡}|D]°}zcCst d ||¡¡Sr?r@rArrrr9 sÿz*LexiconDNSAuthenticator._handle_http_errorcCs$t|ƒ d¡s t d ||¡¡SdSrBrCrArrrr;s ÿz-LexiconDNSAuthenticator._handle_general_error)rFrGrHrIr ZNamespaceConfigrDrÚpropertyÚabcÚabstractmethodrXÚintrZr_rrgrfrprqrmr rrr+r9r:r;Ú __classcell__rrrVrrR¥s"ÿ  rRc@sbeZdZdZedœdd„Zeedœdd„Zeedd œd d „Z eedœd d „Z e edœdd„Z dS)Ú_DeprecationModulez” Internal class delegating to a module, and displaying warnings when attributes related to deprecated attributes in the current module. )ÚmodulecCs||jd<dS©NÚ_module)Ú__dict__)rrxrrrrsz_DeprecationModule.__init__)ÚattrrcCs0|dvr$tj|›dt›d�tdd�t|j|ƒS)N)rrQz attribute in z/ module is deprecated and will be removed soon.ra)Ú stacklevel)ÚwarningsÚwarnrFÚDeprecationWarningÚgetattrrz©rr|rrrÚ __getattr__ s þz_DeprecationModule.__getattr__N)r|ÚvaluercCst|j||ƒdSr)Úsetattrrz)rr|r„rrrÚ __setattr__'sz_DeprecationModule.__setattr__cCst|j|ƒdSr)Údelattrrzr‚rrrÚ __delattr__*sz_DeprecationModule.__delattr__rcCsdgt|jƒSry)ÚdirrzrrrrÚ__dir__-sz_DeprecationModule.__dir__) rFrGrHrIrrrDrrƒr†rˆrrŠrrrrrws rw))rIrsZloggingÚsysÚtypesrÚtypingrrrrrrr r r~Zrequests.exceptionsr r Zcertbotr rZcertbot.pluginsrZlexicon.clientrZlexicon.configrZlexicon.interfacesrÚ ImportErrorZ getLoggerrFr)rrDrQZDNSAuthenticatorrRrwÚmodulesrrrrÚsF                  `þ s