3 گa@s$dZddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z dd l m Z dd lmZdd lmZydd lmZdd lmZWnek reZeZYnXddddddddZejeZeeeedddZGdddeZGdddeZGddde Z dS)z0Module configuring Certbot in a snap environmentN)Iterable)List)Optional)Session) HTTPAdapter) HTTPError)RequestException)os)Error)HTTPConnection)HTTPConnectionPoolzaarch64-linux-gnuzarm-linux-gnueabihfzi386-linux-gnuzpowerpc64le-linux-gnuzpowerpc-linux-gnuzx86_64-linux-gnuzs390x-linux-gnu)Zarm64ZarmhfZi386Zppc64elZpowerpcamd64Zs390x)cli_argsreturncCstjjd}|tkr"tdj|djtjjdt|tjd<t}|jdty|jd}|j Wn\t k r}z@t |t r|j jdkrtjd tjd n tjd |WYd d }~XnXWd QRX|j}d d|jdijdgD}dj|tjd<|jd|S)z Prepare runtime environment for a certbot execution in snap. :param list cli_args: List of command line arguments :return: Update list of command line arguments :rtype: list Z SNAP_ARCHz$Unrecognized value of SNAP_ARCH: {0}z{0}/usr/lib/{1}/libaugeas.so.0ZSNAPZCERTBOT_AUGEAS_PATHz http://snapd/z:http://snapd/v2/connections?snap=certbot&interface=contentizYAn error occurred while fetching Certbot snap plugins: your version of snapd is outdated.z[Please run "sudo snap install core; sudo snap refresh core" in your terminal and try again.z^An error occurred while fetching Certbot snap plugins: make sure the snapd service is running.NcSsJg|]B}|jdijddkr|jdijddkrdj|ddqS)ZplugZpluginz plug-attrsZcontentz certbot-1z./snap/{0}/current/lib/python3.8/site-packages/ZslotZsnap)getformat).0itemr!/usr/lib/python3.6/snap_config.py Gszprepare_env..resultZ established:ZCERTBOT_PLUGIN_PATHz--preconfigured-renewal)r environr_ARCH_TRIPLET_MAPr rrZmount _SnapdAdapterZraise_for_statusr isinstancerresponseZ status_codeLOGGERerrorZjsonjoinappend)rZ snap_archZsessionredataZ connectionsrrr prepare_env&s,        r$cs0eZdZddfdd ZddddZZS)_SnapdConnectionN)rcstjdd|_dS)N localhost)super__init__sock)self) __class__rrr(Ts z_SnapdConnection.__init__cCs"tjtjtj|_|jjddS)Nz/run/snapd.socket)socketZAF_UNIXZ SOCK_STREAMr)connect)r*rrrr-Xsz_SnapdConnection.connect)__name__ __module__ __qualname__r(r- __classcell__rr)r+rr%Ssr%cs0eZdZddfdd ZedddZZS)_SnapdConnectionPoolN)rcstjddS)Nr&)r'r()r*)r+rrr(^sz_SnapdConnectionPool.__init__cCstS)N)r%)r*rrr _new_connasz_SnapdConnectionPool._new_conn)r.r/r0r(r%r3r1rr)r+rr2]sr2c@s(eZdZdeeeeedddZdS)rN)urlproxiesrcCstS)N)r2)r*r4r5rrrget_connectionfsz_SnapdAdapter.get_connection)N)r.r/r0strrrr2r6rrrrresr)!__doc__Zloggingr,ZtypingrrrZrequestsrZrequests.adaptersrZrequests.exceptionsrrZcertbot.compatr Zcertbot.errorsr Zurllib3.connectionr Zurllib3.connectionpoolr ImportErrorobjectrZ getLoggerr.rr7r$r%r2rrrrrs:            -