a }|g2@sdZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZddlZdd lmZdd lmZddlmZddlmZddlmZz(ddlmZddlmZddlmZWn eydZdZdZYn0ee Z!GdddZ"e#e e#efe e#efeee e#effdddZ$Gdddej%Z&GdddZ'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@seZdZdZddddZeeeddddZeeeddd d Zedd d d Ze ee e j dddZ eee e j dddZdS) LexiconClientz Encapsulates all communication with a DNS provider via Lexicon. .. deprecated:: 2.7.0 Please use certbot.plugins.dns_common_lexicon.LexiconDNSAuthenticator instead. NreturncCs|dSNselfrrF/usr/lib/python3.9/site-packages/certbot/plugins/dns_common_lexicon.py__init__0szLexiconClient.__init__)domain record_namerecord_contentrc Csj||z|jjd||dWnDtyd}z,tjd|ddtd|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 TXTZrtypenameZcontent'Encountered error adding TXT record: %sTexc_infoError adding TXT record: {0}N) _find_domain_idprovider create_recordr loggerdebugr PluginErrorformatrrrrerrradd_txt_record3s zLexiconClient.add_txt_recordc Csz||Wn8tjyF}ztjd|ddWYd}~dSd}~00z|jjd||dWn4ty}ztjd|ddWYd}~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-rrrdel_txt_recordDs zLexiconClient.del_txt_recordrrc Cst|}|D]}z4t|jdr.||jjd<n||j_|jWdSty~}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. optionsrNAUnable to determine zone identifier for {0} using zone names: {1})rbase_domain_name_guesseshasattrr'r5rZ authenticater _handle_http_error Exception_handle_general_errorrr+r,rrZdomain_name_guesses domain_namer.Zresult1Zresult2rrrr&Ys&     zLexiconClient._find_domain_idr.r=rcCstd||SNz/Error determining zone identifier for {0}: {1}.rr+r,rr.r=rrrr9}sz LexiconClient._handle_http_errorcCs$t|ds td||SdSNzNo 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_namelexicon_optionsprovider_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_dictwith_env)rJrKrLZ config_dictZprovider_configrrrbuild_lexicon_configs   rQcseZdZdZejedfdd Zee j edddZ ee ddd Z eeed d d d ZeedddZd dddZeeed dddZeeed dddZeedddZeeeejdddZeeeejdddZZS)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__rrrsz LexiconDNSAuthenticator.__init__rcCsdS)z9 The name of the Lexicon provider to use Nrrrrr_provider_namesz&LexiconDNSAuthenticator._provider_namecCsdS)zX Time to live to apply to the DNS records created by this Authenticator <rrrrr_ttlszLexiconDNSAuthenticator._ttlN)creds_var_namecreds_var_labellexicon_provider_option_namercCs|j|||fdSr)rUappend)rr[r\r]rrr_add_provider_optionsz,LexiconDNSAuthenticator._add_provider_optionr4c sPtdsd|d|djdjjfddjDi}t|S)N _credentialsrZ delegatedrMZttlcs"i|]}|dj|dqS)r)r`Zconf.0itemrrr szALexiconDNSAuthenticator._build_lexicon_config..)r8_setup_credentialsrXrZrUrrOrP)rrZ dict_configrrr_build_lexicon_configs  z-LexiconDNSAuthenticator._build_lexicon_configcCs,|jdd|jddd|jDd|_dS)NZ credentialszCredentials INI file for z DNS authenticatorcSsi|]}|d|dqS)rrrbrrrrez>LexiconDNSAuthenticator._setup_credentials..)keyZlabelZrequired_variables)Z_configure_credentialsrXrUr`rrrrrfs  z*LexiconDNSAuthenticator._setup_credentials)rvalidation_name validationrc Cs||}zBt|| }|jd||dWdn1s@0YWnDty}z,tjd|ddtd |WYd}~n d}~00dS)Nrr r"Tr#r%) _resolve_domainrrgr(r r)r*rr+r,)rrrkrlresolved_domain operationsr.rrr_performs 2z LexiconDNSAuthenticator._performc Csz||}Wn8tjyF}ztjd|ddWYd}~dSd}~00zBt|| }|jd||dWdn1s~0YWn4ty}ztjd|ddWYd}~n d}~00dS)Nr0Tr#rr r1) rmrr+r)r*rrgr2r )rrrkrlrnr.rorrr_cleanups2z LexiconDNSAuthenticator._cleanupc Cst|}|D]}zcCstd||Sr?r@rArrrr9 sz*LexiconDNSAuthenticator._handle_http_errorcCs$t|ds td||SdSrBrCrArrrr;s z-LexiconDNSAuthenticator._handle_general_error)rFrGrHrIr ZNamespaceConfigrDrpropertyabcabstractmethodrXintrZr_rrgrfrprqrmr rrr+r9r:r; __classcell__rrrVrrRs"  rRc@sbeZdZdZedddZeedddZeedd d d Z eedd d Z e edddZ dS)_DeprecationModulez Internal class delegating to a module, and displaying warnings when attributes related to deprecated attributes in the current module. )modulecCs||jd<dSN_module)__dict__)rrxrrrrsz_DeprecationModule.__init__)attrrcCs0|dvr$tj|dtdtddt|j|S)N)rrQz attribute in z/ module is deprecated and will be removed soon.ra) stacklevel)warningswarnrFDeprecationWarninggetattrrzrr|rrr __getattr__ s z_DeprecationModule.__getattr__N)r|valuercCst|j||dSr)setattrrz)rr|rrrr __setattr__'sz_DeprecationModule.__setattr__cCst|j|dSr)delattrrzrrrr __delattr__*sz_DeprecationModule.__delattr__rcCsdgt|jSry)dirrzrrrr__dir__-sz_DeprecationModule.__dir__) rFrGrHrIrrrDrrrrrrrrrrrws rw))rIrsZloggingsystypesrtypingrrrrrrr r r~Zrequests.exceptionsr r Zcertbotr rZcertbot.pluginsrZlexicon.clientrZlexicon.configrZlexicon.interfacesr ImportErrorZ getLoggerrFr)rrDrQZDNSAuthenticatorrRrwmodulesrrrrsF                  ` s