§
    ÎÑßj‡  ã                   ó`  — d Z ddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
mZ ddlmZmZ ddlmZmZmZmZ ddlmZmZmZmZ ddlmZmZ ddlmZ 	 ddlZn# e $ r ddlZY nw xY w	 dd	l!m"Z" dd
l#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* n# e $ r dZ(Y nw xY wdZ+ ej,        e-¦  «        Z.d„ Z/d„ Z0d„ Z1d7dee2         fd„Z3 G d„ de¦  «        Z4 G d„ de¦  «        Z5 G d„ de5¦  «        Z6 G d„ de5¦  «        Z7 G d„ de5¦  «        Z8 G d„ d e5¦  «        Z9 G d!„ d"e5¦  «        Z: G d#„ d$e5¦  «        Z; G d%„ d&e¦  «        Z< G d'„ d(e¦  «        Z= G d)„ d*e¦  «        Z> G d+„ d,e>¦  «        Z? G d-„ d.e>¦  «        Z@ G d/„ d0e>¦  «        ZA G d1„ d2¦  «        ZB G d3„ d4¦  «        ZC G d5„ d6ee¦  «        ZDdS )8aƒ  
Module for Google Connection and Authentication classes.

Information about setting up your Google OAUTH2 credentials:

For libcloud, there are two basic methods for authenticating to Google using
OAUTH2: Service Accounts and Client IDs for Installed Applications.

Both are initially set up from the Cloud Console Console -
https://cloud.google.com/console

Setting up Service Account authentication (note that you need the cryptography
package installed to use this):

- Go to the Console
- Go to your project and then to "APIs & auth" on the left
- Click on "Credentials"
- Click on "Create New Client ID..."
- Select "Service account" and click on "Create Client ID"
- Download the Private Key (should happen automatically).  The key you download
  is in JSON format.
- Move the .json file to a safe location.
- Optionally, you may choose to Generate a PKCS12 key from the Console.
  It needs to be converted to the PEM format.  Please note, the PKCS12 format
  is deprecated and may be removed in a future release.
  - Convert the key using OpenSSL (the default password is 'notasecret').
  - Move the .pem file to a safe location.
- To Authenticate, you will need to pass the Service Account's "Email
  address" in as the user_id and the path to the .pem file as the key.

Setting up Installed Application authentication:

- Go to the Console
- Go to your project and then to "APIs & auth" on the left
- Click on "Credentials"
- Select "Installed application" and "Other" then click on
  "Create Client ID"
- To Authenticate, pass in the "Client ID" as the user_id and the "Client
  secret" as the key
- The first time that you do this, the libcloud will give you a URL to
  visit.  Copy and paste the URL into a browser.
- When you go to the URL it will ask you to log in (if you aren't already)
  and ask you if you want to allow the project access to your account.
- Click on Accept and you will be given a code.
- Paste that code at the prompt given to you by the Google libcloud
  connection.
- At that point, a token & refresh token will be stored in your home
  directory and will be used for authentication.

Please remember to secure your keys and access tokens.
é    N)ÚOptional)Ú
HTTPServerÚBaseHTTPRequestHandler)ÚbÚhttplibÚurlparseÚ	urlencode)Ú
BaseDriverÚJsonResponseÚPollingConnectionÚConnectionUserAndKey)ÚLibcloudErrorÚProviderError)Úget_response_object)Ú
exceptions)Údefault_backend)Úserialization)ÚSHA256)ÚPKCS1v15z%Y-%m-%dT%H:%M:%SZc                  ó>   — t           j                              ¦   «         S )z?
    Mocked in libcloud.test.common.google.GoogleTestCase.
    )ÚdatetimeÚutcnow© ó    úJ/opt/saltstack/salt/lib/python3.11/site-packages/libcloud/common/google.pyÚ_utcnowr   i   s   € õ Ô×#Ò#Ñ%Ô%Ð%r   c                 ó6   — |                       t          ¦  «        S )zC
    Return string of datetime_obj in the UTC Timestamp Format
    )ÚstrftimeÚUTC_TIMESTAMP_FORMAT)Údatetime_objs    r   Ú_utc_timestampr!   p   s   € ð × Ò Õ!5Ñ6Ô6Ð6r   c                 óL   — t           j                              | t          ¦  «        S )zS
    Return datetime obj where date and time are pulled from timestamp string.
    )r   Ústrptimer   )Ú	timestamps    r   Ú_from_utc_timestampr%   w   s   € õ Ô×%Ò% iÕ1EÑFÔFÐFr   Ú Úretry_failedc                 óÐ   — 	 d|                       d¦  «        z   }ddi}t          |||¬¦  «        }|j        d|j        fS # t          $ r}dt          |¦  «        d fcY d }~S d }~ww xY w)Nz3http://metadata.google.internal/computeMetadata/v1/ú/zMetadata-FlavorÚGoogle)Úheadersr'   r&   éÿÿÿÿ)Úlstripr   ÚstatusÚbodyÚ	ExceptionÚstr)Úpathr'   Úurlr+   ÚresponseÚes         r   Ú_get_gce_metadatar6   ~   sŽ   € ð ØCÀdÇkÂkÐRUÑFVÔFVÑVˆØ$ hÐ/ˆÝ& s°GÈ,ÐWÑWÔWˆØŒ  H¤MÐ1Ð1øÝð  ð  ð  Ø•3�q‘6”6˜4ÐÐÐÐÐÐÐøøøøð øøøs   ‚<? ¿
A%Á	A ÁA%Á A%c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚGoogleAuthErrorz6Generic Error class for various authentication errors.c                 ó   — || _         d S ©N)Úvalue)Úselfr;   s     r   Ú__init__zGoogleAuthError.__init__‹   s   € ØˆŒ
ˆ
ˆ
r   c                 ó*   — t          | j        ¦  «        S r:   )Úreprr;   ©r<   s    r   Ú__repr__zGoogleAuthError.__repr__Ž   s   € Ý�D”JÑÔÐr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r=   rA   r   r   r   r8   r8   ˆ   s8   € € € € € Ø@Ð@ðð ð ð ð  ð  ð  ð  r   r8   c                   ó    ‡ — e Zd Zdˆ fd„	Zˆ xZS )ÚGoogleBaseErrorNc                 ó\   •— || _         t          ¦   «                              |||¦  «         d S r:   )ÚcodeÚsuperr=   ©r<   r;   Ú	http_coderI   ÚdriverÚ	__class__s        €r   r=   zGoogleBaseError.__init__“   s,   ø€ ØˆŒ	Ý‰Œ×Ò˜ 	¨6Ñ2Ô2Ð2Ð2Ð2r   r:   ©rB   rC   rD   r=   Ú__classcell__©rN   s   @r   rG   rG   ’   s=   ø€ € € € € ð3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3r   rG   c                   ó   — e Zd ZdS )ÚInvalidRequestErrorN©rB   rC   rD   r   r   r   rS   rS   ˜   ó   € € € € € Ø€Dr   rS   c                   ó   — e Zd ZdS )ÚJsonParseErrorNrT   r   r   r   rW   rW   œ   rU   r   rW   c                   ó    ‡ — e Zd Zdˆ fd„	Zˆ xZS )ÚResourceNotFoundErrorNc                 ó&  •— || _         t          |t          ¦  «        rPd|v rL|d                              d¦  «        dk    r-|d                              d¦  «        dk    r|d         dz   |d<   t	          ¦   «                              |||¦  «         d S )NÚmessager)   é   z	projects/zs. A missing project error may be an authentication issue. Please  ensure your auth credentials match your project. )rI   Ú
isinstanceÚdictÚcountrJ   r=   rK   s        €r   r=   zResourceNotFoundError.__init__¡   s¥   ø€ ØˆŒ	å�u�dÑ#Ô#ð	à˜UÐ"Ð"Ø�iÔ ×&Ò& sÑ+Ô+¨qÒ0Ð0Ø�iÔ ×&Ò& {Ñ3Ô3°qÒ8Ð8ð �iÔ ð $!ñ !ð �)Ñõ 	‰Œ×Ò˜ 	¨6Ñ2Ô2Ð2Ð2Ð2r   r:   rO   rQ   s   @r   rY   rY       s=   ø€ € € € € ð3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3r   rY   c                   ó   — e Zd ZdS )ÚQuotaExceededErrorNrT   r   r   r   ra   ra   ²   rU   r   ra   c                   ó   — e Zd ZdS )ÚResourceExistsErrorNrT   r   r   r   rc   rc   ¶   rU   r   rc   c                   ó   — e Zd ZdS )ÚResourceInUseErrorNrT   r   r   r   re   re   º   rU   r   re   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚGoogleResponsez%
    Google Base Response class.
    c                 ó   — dS )zÖ
        Determine if the request was successful.

        For the Google response class, tag all responses as successful and
        raise appropriate Exceptions from parse_body.

        :return: C{True}
        Tr   r@   s    r   ÚsuccesszGoogleResponse.successÃ   s	   € ð ˆtr   c                 ó  — d|d         v r|d         d         d         }n|d         }d|v r+|                      d¦  «        }|                      d¦  «        }n1d}d|v r|                      d¦  «        }|                      d|¦  «        }||fS )	aU  
        Get the error code and message from a JSON response.

        Return just the first error if there are multiple errors.

        :param  body: The body of the JSON response dictionary
        :type   body: ``dict``

        :return:  Tuple containing error code and message
        :rtype:   ``tuple`` of ``str`` or ``int``
        ÚerrorsÚerrorr   rI   r[   NÚreasonÚerror_description)Úget)r<   r/   ÚerrrI   r[   s        r   Ú
_get_errorzGoogleResponse._get_errorÎ   s™   € ð �t˜G”}Ð$Ð$Ø�w”- Ô)¨!Ô,ˆCˆCà�w”-ˆCà�Sˆ=ˆ=Ø—7’7˜6‘?”?ˆDØ—g’g˜iÑ(Ô(ˆGˆGàˆDØ˜3ˆˆØ—w’w˜xÑ(Ô(�Ø—h’hÐ2°CÑ8Ô8ˆGà�gˆÐr   c                 óh  — t          | j        ¦  «        dk    r| j        s| j        S d}	 t          j        | j        ¦  «        }n# t
          $ r | j        }d}Y nw xY wt          j        t          j        t          j	        t          j
        g}| j        |v rË|rt          || j        d¦  «        ‚d|v r­|                      |¦  «        \  }}|dk    rt          || j        |¦  «        ‚|dk    rt          || j        |¦  «        ‚|dk    rt          || j        |¦  «        ‚|                     d	¦  «        rt#          || j        |¦  «        ‚t%          || j        |¦  «        ‚|S | j        t          j        k    r9|sd|v r|                      |¦  «        \  }}n|}d}t)          || j        |¦  «        ‚| j        t          j        k    r9|sd|v r|                      |¦  «        \  }}n|}d}t-          || j        |¦  «        ‚|sd|v r|                      |¦  «        \  }}n|}d}t%          || j        |¦  «        ‚)
z‘
        Parse the JSON response body, or raise exceptions as appropriate.

        :return:  JSON dictionary
        :rtype:   ``dict``
        r   FTNrl   ÚQUOTA_EXCEEDEDÚRESOURCE_ALREADY_EXISTSÚalreadyExistsÚRESOURCE_IN_USE)Úlenr/   Úparse_zero_length_bodyÚjsonÚloadsr0   r   ÚOKÚCREATEDÚACCEPTEDÚCONFLICTr.   rW   rq   ra   rc   Ú
startswithre   rG   Ú	NOT_FOUNDrY   ÚBAD_REQUESTrS   )r<   Ú
json_errorr/   Úvalid_http_codesrI   r[   s         r   Ú
parse_bodyzGoogleResponse.parse_bodyê   sn  € õ ˆtŒy‰>Œ>˜QÒÐ tÔ'BÐØ”9Ðàˆ
ð	Ý”:˜dœiÑ(Ô(ˆDˆDøÝð 	ð 	ð 	ð ”9ˆDØˆJˆJˆJð	øøøõ ŒJÝŒOÝÔÝÔð	
Ðð Œ;Ð*Ð*Ð*Øð Ý$ T¨4¬;¸Ñ=Ô=Ð=Ø˜D��Ø $§¢°Ñ 5Ô 5‘��gØÐ+Ò+Ð+Ý,¨W°d´kÀ4ÑHÔHÐHØÐ6Ò6Ð6Ý-¨g°t´{ÀDÑIÔIÐIØ˜_Ò,Ð,Ý-¨g°t´{ÀDÑIÔIÐIØ—_’_Ð%6Ñ7Ô7ð FÝ,¨W°d´kÀ4ÑHÔHÐHå)¨'°4´;ÀÑEÔEÐEà�àŒ[�GÔ-Ò-Ð-Øð  W° _ _Ø $§¢°Ñ 5Ô 5‘��g�gà�Ø�Ý'¨°´¸dÑCÔCÐCàŒ[�GÔ/Ò/Ð/Øð  W° _ _Ø $§¢°Ñ 5Ô 5‘��g�gà�Ø�Ý% g¨t¬{¸DÑAÔAÐAð ð  W° _ _Ø $§¢°Ñ 5Ô 5‘��g�gà�Ø�Ý! '¨4¬;¸Ñ=Ô=Ð=s   ªA ÁAÁAN)rB   rC   rD   rE   ri   rq   r„   r   r   r   rg   rg   ¾   sP   € € € € € ðð ð	ð 	ð 	ðð ð ð8B>ð B>ð B>ð B>ð B>r   rg   c                   ó   — e Zd ZdZdS )ÚGoogleBaseDriverz
Google APIN)rB   rC   rD   Únamer   r   r   r†   r†   /  s   € € € € € Ø€D€D€Dr   r†   c                   óV   ‡ — e Zd ZdZeZeZdZdZ	dZ
dZ	 	 	 	 dˆ fd„	Zd	„ Zd
„ Zd„ Zˆ xZS )ÚGoogleBaseAuthConnectionzo
    Base class for Google Authentication.  Should be subclassed for specific
    types of authentication.
    zGoogle Authzaccounts.google.comz/o/oauth2/authi—  Núhttp://127.0.0.1c                 ó–   •— |pg }d                      |¦  «        | _        || _        || _         t	          ¦   «         j        ||fi |¤Ž dS )aÜ  
        :param  user_id: The email address (for service accounts) or Client ID
                         (for installed apps) to be used for authentication.
        :type   user_id: ``str``

        :param  key: The RSA Key (for service accounts) or file path containing
                     key or Client Secret (for installed apps) to be used for
                     authentication.
        :type   key: ``str``

        :param  scopes: A list of urls defining the scope of authentication
                       to grant.
        :type   scopes: ``list``

        :keyword  redirect_uri: The Redirect URI for the authentication
                                request.  See Google OAUTH2 documentation for
                                more info.
        :type     redirect_uri: ``str``

        :keyword  login_hint: Login hint for authentication request.  Useful
                              for Installed Application authentication.
        :type     login_hint: ``str``
        ú N)ÚjoinÚscopesÚredirect_uriÚ
login_hintrJ   r=   )r<   Úuser_idÚkeyrŽ   r�   r�   ÚkwargsrN   s          €r   r=   z!GoogleBaseAuthConnection.__init__@  sX   ø€ ð@ �˜2ˆà—h’h˜vÑ&Ô&ˆŒØ(ˆÔØ$ˆŒà�‰ŒÔ˜ #Ð0Ð0¨Ð0Ð0Ð0Ð0Ð0r   c                 ó$   — d|d<   | j         |d<   |S )zE
        Add defaults for 'Content-Type' and 'Host' headers.
        z!application/x-www-form-urlencodedúContent-TypeÚHost©Úhost©r<   r+   s     r   Úadd_default_headersz,GoogleBaseAuthConnection.add_default_headersh  s   € ð #Fˆ�ÑØœ)ˆ�‰Øˆr   c                 ó   — t          |¦  «        }	 |                      dd|¬¦  «        }n# t          $ r t          d¦  «        ‚w xY w|j        }d|v r<t          ¦   «         t          j        |d         ¬¦  «        z   }t          |¦  «        |d<   |S )aC  
        Return an updated token from a token request body.

        :param  request_body: A dictionary of values to send in the body of the
                              token request.
        :type   request_body: ``dict``

        :return:  A dictionary with updated token information
        :rtype:   ``dict``
        z/o/oauth2/tokenÚPOST)ÚmethodÚdatazMInvalid authorization response, please check your credentials and time drift.Ú
expires_in©ÚsecondsÚexpire_time)	r	   ÚrequestÚAttributeErrorr8   Úobjectr   r   Ú	timedeltar!   )r<   Úrequest_bodyrž   r4   Ú
token_infor¢   s         r   Ú_token_requestz'GoogleBaseAuthConnection._token_requestp  s­   € õ ˜Ñ&Ô&ˆð	Ø—|’|Ð$5¸fÈ4�|ÑPÔPˆHˆHøÝð 	ð 	ð 	Ý!Øbñô ð ð	øøøð ”_ˆ
Ø˜:Ð%Ð%Ý!™)œ)¥hÔ&8ÀÈLÔAYÐ&ZÑ&ZÔ&ZÑZˆKÝ(6°{Ñ(CÔ(CˆJ�}Ñ%ØÐs	   ‘* ªAc                 ó*   — |                       ¦   «         S )aƒ  
        Refresh the current token.

        Fetch an updated refresh token from internal metadata service.

        :param  token_info: Dictionary containing token information.
                            (Not used, but here for compatibility)
        :type   token_info: ``dict``

        :return:  A dictionary containing updated token information.
        :rtype:   ``dict``
        )Úget_new_token)r<   r¨   s     r   Úrefresh_tokenz&GoogleBaseAuthConnection.refresh_tokenˆ  s   € ð ×!Ò!Ñ#Ô#Ð#r   )NNrŠ   N)rB   rC   rD   rE   r†   rM   rg   ÚresponseClsr‡   r˜   Ú	auth_pathÚredirect_uri_portr=   rš   r©   r¬   rP   rQ   s   @r   r‰   r‰   3  s¤   ø€ € € € € ðð ð
 €FØ €KØ€DØ €DØ €IØÐð
 ØØ'Øð&1ð &1ð &1ð &1ð &1ð &1ðPð ð ðð ð ð0$ð $ð $ð $ð $ð $ð $r   r‰   c                   óD   — e Zd ZdZdZd„ Zd„ Zd„ Zed„ ¦   «         Z	d„ Z
dS )	Ú GoogleInstalledAppAuthConnectionzEAuthentication connection for "Installed Application" authentication.zLibcloud Requestc                 ó$  — d| j         | j        | j        | j        dœ}| j        r
| j        |d<   t          |¦  «        }d                     | j        | j        |¦  «        }t          d¦  «         t          |¦  «         |  
                    ¦   «         }|S )zå
        Give the user a URL that they can visit to authenticate.

        Mocked in libcloud.test.common.google.GoogleTestCase.

        :return:  Code supplied by the user after authenticating
        :rtype:   ``str``
        rI   )Úresponse_typeÚ	client_idr�   ÚscopeÚstater�   zhttps://{}{}?{}z,
Please Go to the following URL and sign in:)r‘   Ú_redirect_uri_with_portrŽ   Ú_stater�   r	   Úformatr˜   r®   ÚprintÚ$_receive_code_through_local_loopback)r<   Úauth_paramsrž   r3   rI   s        r   Úget_codez)GoogleInstalledAppAuthConnection.get_codež  s˜   € ð $ØœØ Ô8Ø”[Ø”[ð
ð 
ˆð Œ?ð 	8Ø(,¬ˆK˜Ñ%å˜Ñ%Ô%ˆà×&Ò& t¤y°$´.À$ÑGÔGˆÝÐ=Ñ>Ô>Ð>Ýˆc‰
Œ
ˆ
Ø×8Ò8Ñ:Ô:ˆØˆr   c                 ó‚   — |                       ¦   «         }|| j        | j        | j        ddœ}|                      |¦  «        S )zÊ
        Get a new token. Generally used when no previous token exists or there
        is no refresh token

        :return:  Dictionary containing token information
        :rtype:   ``dict``
        Úauthorization_code)rI   r´   Úclient_secretr�   Ú
grant_type)r½   r‘   r’   r·   r©   )r<   rI   Útoken_requests      r   r«   z.GoogleInstalledAppAuthConnection.get_new_token¹  sK   € ð �}Š}‰Œˆð ØœØ!œXØ Ô8Ø.ð
ð 
ˆð ×"Ò" =Ñ1Ô1Ð1r   c                 ó¬   — d|vr|                       ¦   «         S |d         | j        | j        ddœ}|                      |¦  «        }d|vr|d         |d<   |S )a)  
        Use the refresh token supplied in the token info to get a new token.

        :param  token_info: Dictionary containing current token information
        :type   token_info: ``dict``

        :return:  A dictionary containing updated token information.
        :rtype:   ``dict``
        r¬   )r¬   r´   rÀ   rÁ   )r«   r‘   r’   r©   )r<   r¨   Úrefresh_requestÚ	new_tokens       r   r¬   z.GoogleInstalledAppAuthConnection.refresh_tokenÍ  sw   € ð  *Ð,Ð,Ø×%Ò%Ñ'Ô'Ð'à'¨Ô8ØœØ!œXØ)ð	
ð 
ˆð ×'Ò'¨Ñ8Ô8ˆ	Ø )Ð+Ð+Ø)3°OÔ)DˆI�oÑ&ØÐr   c                 ó@   — | j         dz   t          | j        ¦  «        z   S )Nú:)r�   r1   r¯   r@   s    r   r·   z8GoogleInstalledAppAuthConnection._redirect_uri_with_portå  s    € àÔ  3Ñ&­¨TÔ-CÑ)DÔ)DÑDÐDr   c                 ó  ‡ ‡— dŠ G ˆˆ fd„dt           ¦  «        }d‰ j        v sd‰ j        v s	d‰ j        v r
d‰ j        f}n‰ j        ‰ j        f}t          ||¬¦  «        }|                     ¦   «          ‰€t          d¦  «        ‚‰S )	a�  
        Start a local HTTP server that listens to a single GET request that is expected to be made
        by the loopback in the sign-in process and stops again afterwards.
        See https://developers.google.com/identity/protocols/oauth2/native-app#redirect-uri_loopback

        :return: The access code that was extracted from the local loopback GET request
        :rtype: ``str``
        Nc                   ó   •— e Zd Zˆ ˆfd„ZdS )úaGoogleInstalledAppAuthConnection._receive_code_through_local_loopback.<locals>.AccessCodeReceiverc                 óR  •— t          j         | j        ¦  «        j        }t          d„ |                     d¦  «        D ¦   «         ¦  «        }d|v r\|d         t
          j                             ‰j        ¦  «        k    r.t          d 
                    ‰j        |d         ¦  «        ¦  «        ‚|d         Š|                      d¦  «         |                      dd¦  «         |                      ¦   «          | j                             d	¦  «         | j                             d
¦  «         d S )Nc              3   ó@   K  — | ]}|                      d ¦  «        V — ŒdS )ú=N)Úsplit)Ú.0Úqcs     r   ú	<genexpr>z{GoogleInstalledAppAuthConnection._receive_code_through_local_loopback.<locals>.AccessCodeReceiver.do_GET.<locals>.<genexpr>ø  s,   è è € Ð'QÐ'Q¸"¨¯ª°©¬Ð'QÐ'QÐ'QÐ'QÐ'QÐ'Qr   ú&r¶   z9States do not match: {} != {}, can't trust authenticationrI   éÈ   zContent-typez	text/htmls2   <html><head><title>Libcloud Sign-In</title></head>s'   <body><p>You can now close this tab</p>)r   r2   Úqueryr^   rÎ   ÚurllibÚparseÚquoter¸   Ú
ValueErrorr¹   Úsend_responseÚsend_headerÚend_headersÚwfileÚwrite)Úself_rÔ   Úquery_componentsÚaccess_coder<   s      €€r   Údo_GETzhGoogleInstalledAppAuthConnection._receive_code_through_local_loopback.<locals>.AccessCodeReceiver.do_GETö  s,  ø€ Ý Ô)¨%¬*Ñ5Ô5Ô;�Ý#'Ð'QÐ'QÀÇÂÈCÑ@PÔ@PÐ'QÑ'QÔ'QÑ#QÔ#QÐ ØÐ.Ð.Ð.Ð3CÀGÔ3LÕPVÔP\×PbÒPbØ”KñQô Qò 4ð 4õ %ØS×ZÒZØ œKÐ)9¸'Ô)Bñô ñô ð ð /¨vÔ6�Ø×#Ò# CÑ(Ô(Ð(Ø×!Ò! .°+Ñ>Ô>Ð>Ø×!Ò!Ñ#Ô#Ð#Ø”×!Ò!Ð"WÑXÔXÐXØ”×!Ò!Ð"LÑMÔMÐMÐMÐMr   N)rB   rC   rD   rá   )rà   r<   s   €€r   ÚAccessCodeReceiverrÊ   ô  s;   ø€ € € € € ðNð Nð Nð Nð Nð Nð Nð Nr   râ   z	127.0.0.1z[::1]Ú	localhost)Úserver_addressÚRequestHandlerClasszECould not receive OAuth2 code: could not extract code though loopback)r   r�   r¯   r   Úhandle_requestÚRuntimeError)r<   râ   rä   Úserverrà   s   `   @r   r»   zEGoogleInstalledAppAuthConnection._receive_code_through_local_loopbacké  så   øø€ ð ˆð	Nð 	Nð 	Nð 	Nð 	Nð 	Nð 	Nð 	NÕ!7ñ 	Nô 	Nð 	Nð, ˜4Ô,Ð,Ð,Ø˜$Ô+Ð+Ð+Ø˜dÔ/Ð/Ð/ð )¨$Ô*@Ð@ˆNˆNà!Ô.°Ô0FÐFˆNå¨>ÐOaÐbÑbÔbˆà×ÒÑÔÐØÐÝØWñô ð ð Ðr   N)rB   rC   rD   rE   r¸   r½   r«   r¬   Úpropertyr·   r»   r   r   r   r±   r±   ™  sy   € € € € € ØOÐOà€Fðð ð ð62ð 2ð 2ð(ð ð ð0 ðEð Eñ „XðEð1ð 1ð 1ð 1ð 1r   r±   c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )ÚGoogleServiceAcctAuthConnectionz:Authentication class for "Service Account" authentication.c                 óü  •— t           €t          d¦  «        ‚t          |t          ¦  «        r|}d}n¾t          j                             |¦  «        }t          j                             |¦  «        r|t          j                             |¦  «        r]	 t          |¦  «        5 }| 
                    ¦   «         }ddd¦  «         n# 1 swxY w Y   n$# t          $ r t          d|z  ¦  «        ‚w xY w|}d}	 t          j        |¦  «        }n# t          $ r Y nt          $ r Y nw xY wd|v r	|d         }n|}n# d|v r	|d         }n|}w xY w	 t!          j        t%          |¦  «        dt'          ¦   «         ¬¦  «         ng# t          $ r}t          d|z  ¦  «        ‚d}~wt          $ r}t          d|z  ¦  «        ‚d}~wt(          j        $ r}t          d|z  ¦  «        ‚d}~ww xY w t-          ¦   «         j        ||g|¢R i |¤Ž dS )aà  
        Check to see if cryptography is available, and convert PEM key file
        into a key string, or extract the key from JSON object, string or
        file.

        :param  user_id: Email address to be used for Service Account
                authentication.
        :type   user_id: ``str``

        :param  key: The path to a PEM/JSON file containing the private RSA
        key, or a str/dict containing the PEM/JSON.
        :type   key: ``str`` or ``dict``

        NzAcryptography library required for Service Account Authentication.z&Missing (or unreadable) key file: '%s'Úprivate_key©ÚpasswordÚbackendz%Unable to decode provided PEM key: %s)r   r8   r]   r^   Úosr2   Ú
expanduserÚexistsÚisfileÚopenÚreadÚOSErrorry   rz   Ú	TypeErrorrØ   r   Úload_pem_private_keyr   r   r   ÚUnsupportedAlgorithmrJ   r=   )
r<   r‘   r’   Úargsr“   Úkey_contentÚkey_pathÚfr5   rN   s
            €r   r=   z(GoogleServiceAcctAuthConnection.__init__   s»  ø€ õ ˆ>Ý!ØVñô ð õ �c�4Ñ Ô ð 	àˆKØˆCˆCå”w×)Ò)¨#Ñ.Ô.ˆHÝŒw�~Š~˜hÑ'Ô'ð 
­B¬G¯NªN¸8Ñ,DÔ,Dð 
ð]Ý˜h™œð /¨1Ø&'§f¢f¡h¤h˜ð/ð /ð /ñ /ô /ð /ð /ð /ð /ð /ð /øøøð /ð /ð /ð /øøåð ]ð ]ð ]Ý)Ð*UÐX[Ñ*[Ñ\Ô\Ð\ð]øøøð "�Ø�ð	"Ýœ* [Ñ1Ô1ˆKˆKøåð 	ð 	ð 	àˆDÝð 	ð 	ð 	àˆDð	øøøð  Ð+Ð+Ø! -Ô0��à!��øð  Ð+Ð+Ø! -Ô0��à!�Ð!Ð!Ð!Ð!ð	OåÔ.­q°©v¬vÀÍoÑN_ÔN_Ð`Ñ`Ô`Ð`Ð`øÝð 	Oð 	Oð 	OÝ!Ð"IÈAÑ"MÑNÔNÐNøøøøÝð 	Oð 	Oð 	OÝ!Ð"IÈAÑ"MÑNÔNÐNøøøøÝÔ.ð 	Oð 	Oð 	OÝ!Ð"IÈAÑ"MÑNÔNÐNøøøøð	Oøøøð 	�‰ŒÔ˜ #Ð7¨Ð7Ð7Ð7°Ð7Ð7Ð7Ð7Ð7s–   ÂC ÂC Â4C Ã CÃC ÃCÃC ÃC)Ã1D ÄD1 Ä
DÄD1 Ä	DÄD1 ÄDÄD1 Ä1EÅ0E7 Å7
GÆFÆGÆ F2Æ2GÇGÇGc                 ó  — dddœ}t          j        t          t          j        |¦  «        ¦  «        ¦  «        }| j        | j        dt          t          j        ¦   «         ¦  «        dz   t          t          j        ¦   «         ¦  «        dœ}t          j        t          t          j        |¦  «        ¦  «        ¦  «        }d 	                    ||f¦  «        }t          j        t          | j        ¦  «        dt          ¦   «         ¬	¦  «        }|                     t          |¦  «        t          ¦   «         t!          ¦   «         ¬
¦  «        }t          j        |¦  «        }d 	                    ||f¦  «        }d|dœ}	|                      |	¦  «        S )zœ
        Get a new token using the email address and RSA Key.

        :return:  Dictionary containing token information
        :rtype:   ``dict``
        ÚRS256ÚJWT)ÚalgÚtypz*https://accounts.google.com/o/oauth2/tokeni  )Úissrµ   ÚaudÚexpÚiató   .Nrî   )rž   ÚpaddingÚ	algorithmz+urn:ietf:params:oauth:grant-type:jwt-bearer)rÁ   Ú	assertion)Úbase64Úurlsafe_b64encoder   ry   Údumpsr‘   rŽ   ÚintÚtimer�   r   rù   r’   r   Úsignr   r   r©   )
r<   ÚheaderÚ
header_encÚ	claim_setÚclaim_set_encr[   r’   Ú	signatureÚjwtr£   s
             r   r«   z-GoogleServiceAcctAuthConnection.get_new_tokena  sT  € ð !¨Ð/Ð/ˆÝÔ-­aµ´
¸6Ñ0BÔ0BÑ.CÔ.CÑDÔDˆ
ð ”<Ø”[Ø?Ý•t”y‘{”{Ñ#Ô# dÑ*Ý•t”y‘{”{Ñ#Ô#ð
ð 
ˆ	õ Ô0µµ4´:¸iÑ3HÔ3HÑ1IÔ1IÑJÔJˆð —)’)˜Z¨Ð7Ñ8Ô8ˆåÔ0ÝˆdŒh‰KŒK $µÑ0AÔ0Að
ñ 
ô 
ˆð —H’H¥! G¡*¤*µh±j´jÍFÉHÌH�HÑUÔUˆ	ÝÔ,¨YÑ7Ô7ˆ	ð �iŠi˜ )Ð,Ñ-Ô-ˆàGØð
ð 
ˆð
 ×"Ò" 7Ñ+Ô+Ð+r   )rB   rC   rD   rE   r=   r«   rP   rQ   s   @r   rë   rë     sN   ø€ € € € € ØDÐDð?8ð ?8ð ?8ð ?8ð ?8ðB%,ð %,ð %,ð %,ð %,ð %,ð %,r   rë   c                   ó   — e Zd ZdZd„ ZdS )Ú"GoogleGCEServiceAcctAuthConnectionzrAuthentication class for self-authentication when used with a GCE
    instance that supports serviceAccounts.
    c                 ót  — d}t          |¦  «        \  }}}|t          j        k    rt          d¦  «        ‚|t          j        k    rt          dt          |¦  «        z  ¦  «        ‚t          j        |¦  «        }d|v r<t          ¦   «         t          j
        |d         ¬¦  «        z   }t          |¦  «        |d<   |S )z›
        Get a new token from the internal metadata service.

        :return:  Dictionary containing token information
        :rtype:   ``dict``
        z(/instance/service-accounts/default/tokenz7Service Accounts are not enabled for this GCE instance.z'Internal GCE Authorization failed: '%s'rŸ   r    r¢   )r6   r   r€   rØ   r{   r1   ry   rz   r   r   r¦   r!   )r<   r2   rL   Úhttp_reasonr¨   r¢   s         r   r«   z0GoogleGCEServiceAcctAuthConnection.get_new_tokenŽ  s·   € ð :ˆÝ->¸tÑ-DÔ-DÑ*ˆ	�; 
Ø�Ô)Ò)Ð)ÝÐYÑZÔZÐZØ�œ
Ò"Ð"ÝÐIÍCÐP[ÑL\ÔL\Ñ\Ñ]Ô]Ð]Ý”Z 
Ñ+Ô+ˆ
Ø˜:Ð%Ð%Ý!™)œ)¥hÔ&8ÀÈLÔAYÐ&ZÑ&ZÔ&ZÑZˆKÝ(6°{Ñ(CÔ(CˆJ�}Ñ%ØÐr   N)rB   rC   rD   rE   r«   r   r   r   r  r  ‰  s-   € € € € € ðð ðð ð ð ð r   r  c                   ó¼   — e Zd ZdZdZdZdZdZeeeegZeeegZ	e
d„ ¦   «         Ze
d„ ¦   «         Zed„ ¦   «         Zed	„ ¦   «         Zed
„ ¦   «         Zed„ ¦   «         ZdS )ÚGoogleAuthTypez½
    SA (Service Account),
    IA (Installed Application),
    GCE (Auth from a GCE instance with service account enabled)
    GCS_S3 (Cloud Storage S3 interoperability authentication)
    ÚSAÚIAÚGCEÚGCS_S3c                 óî   — |                       |¦  «        r| j        S |                      |¦  «        r| j        S |                      |¦  «        r| j        S |                      ¦   «         r| j        S | j        S r:   )Ú_is_sar  Ú
_is_gcs_s3r!  Ú_is_installed_applicationr  Ú_is_gcer   )Úclsr‘   s     r   Ú
guess_typezGoogleAuthType.guess_type²  sx   € à�:Š:�gÑÔð 	Ø”6ˆMØ�^Š^˜GÑ$Ô$ð 	Ø”:ÐØ×*Ò*¨7Ñ3Ô3ð 		ð ”6ˆMØ�[Š[‰]Œ]ð 	Ø”7ˆNð ”6ˆMr   c                 ó   — || j         v S r:   )ÚOAUTH2_TYPES)r'  Ú	auth_types     r   Ú	is_oauth2zGoogleAuthType.is_oauth2Ã  s   € à˜CÔ,Ð,Ð,r   c                 ó,   — |                       d¦  «        S )Nzapps.googleusercontent.com©Úendswith©r‘   s    r   r%  z(GoogleAuthType._is_installed_applicationÇ  s   € à×ÒÐ <Ñ=Ô=Ð=r   c                  óV   — t          d¬¦  «        \  } }}| t          j        k    r|rdS dS )z€
        Checks if we can access the GCE metadata server.
        Mocked in libcloud.test.common.google.GoogleTestCase.
        F)r'   T)r6   r   r{   )rL   r  r/   s      r   r&  zGoogleAuthType._is_gceË  s7   € õ (9ÀeÐ'LÑ'LÔ'LÑ$ˆ	�; Ø�œ
Ò"Ð" tÐ"Ø�4Øˆur   c                 ó,   — |                       d¦  «        S )zN
        Checks S3 key format: alphanumeric chars starting with GOOG.
        ÚGOOG)r   r0  s    r   r$  zGoogleAuthType._is_gcs_s3Ú  s   € ð
 ×!Ò! &Ñ)Ô)Ð)r   c                 ó,   — |                       d¦  «        S )Nz.gserviceaccount.comr.  r0  s    r   r#  zGoogleAuthType._is_saá  s   € à×ÒÐ 6Ñ7Ô7Ð7r   N)rB   rC   rD   rE   r  r  r   r!  Ú	ALL_TYPESr*  Úclassmethodr(  r,  Ústaticmethodr%  r&  r$  r#  r   r   r   r  r  ¢  sí   € € € € € ðð ð 
€BØ	€BØ
€CØ€Fà�R˜˜fÐ%€IØ˜˜C�=€Làðð ñ „[ðð  ð-ð -ñ „[ð-ð ð>ð >ñ „\ð>ð ðð ñ „\ðð ð*ð *ñ „\ð*ð ð8ð 8ñ „\ð8ð 8ð 8r   r  c                   óX   — e Zd ZdZd	d„Zed„ ¦   «         Zed„ ¦   «         Zd„ Zd„ Z	d„ Z
dS )
ÚGoogleOAuth2Credentialz~/.google_libcloud_authNc                 ó¾  — |pt                                |¦  «        | _        | j        t           j        vrt	          d| j        z  ¦  «        ‚t                                | j        ¦  «        st	          d| j        z  ¦  «        ‚|| _        || _        d                     | j	        |g¦  «        }|p|| _
        |pg d¢| _        |                      ¦   «         | _        | j        t           j        k    rt          | j        | j        fi |¤Ž| _        n–| j        t           j        k    r$t%          | j        | j        | j        fi |¤Ž| _        n]| j        t           j        k    r$t)          | j        | j        | j        fi |¤Ž| _        n$t	          dt+          | j        ¦  «        z  ¦  «        ‚| j        €4| j                             ¦   «         | _        |                      ¦   «          d S d S )NzInvalid auth type: %sz'Auth type %s cannot be used with OAuth2ú.)z'https://www.googleapis.com/auth/computez7https://www.googleapis.com/auth/devstorage.full_controlz7https://www.googleapis.com/auth/ndev.clouddns.readwritezInvalid auth_type: %s)r  r(  r+  r5  r8   r,  r‘   r’   r�   Údefault_credential_fileÚcredential_filerŽ   Ú_get_token_from_fileÚtokenr   r  Úoauth2_connr  rë   r  r±   r1   r«   Ú_write_token_to_file)r<   r‘   r’   r+  r=  rŽ   r“   r<  s           r   r=   zGoogleOAuth2Credential.__init__é  sò  € Ø"ÐH¥n×&?Ò&?ÀÑ&HÔ&HˆŒØŒ>¥Ô!9Ð9Ð9Ý!Ð"9¸D¼NÑ"JÑKÔKÐKÝ×'Ò'¨¬Ñ7Ô7ð 	^Ý!Ð"KÈdÌnÑ"\Ñ]Ô]Ð]ØˆŒØˆŒà"%§(¢(¨DÔ,HÈ'Ð+RÑ"SÔ"SÐØ.ÐIÐ2IˆÔàð 
ð !
ð !
ð !
ˆŒð ×.Ò.Ñ0Ô0ˆŒ
àŒ>�^Ô/Ò/Ð/ÝAØ”˜dœkð ð  Ø-3ð ð  ˆDÔÐð Œ^�~Ô0Ò0Ð0Ý>Ø”˜dœh¨¬ð ð  Ø7=ð ð  ˆDÔÐð Œ^�~Ô0Ò0Ð0Ý?Ø”˜dœh¨¬ð ð  Ø7=ð ð  ˆDÔÐõ "Ð"9½CÀÄÑ<OÔ<OÑ"OÑPÔPÐPàŒ:ÐØÔ)×7Ò7Ñ9Ô9ˆDŒJØ×%Ò%Ñ'Ô'Ð'Ð'Ð'ð Ðr   c                 ór   — | j         t          ¦   «         k     r|                      ¦   «          | j        d         S )NÚaccess_token)Útoken_expire_utc_datetimer   Ú_refresh_tokenr?  r@   s    r   rC  z#GoogleOAuth2Credential.access_token  s3   € àÔ)­G©I¬IÒ5Ð5Ø×ÒÑ!Ô!Ð!ØŒz˜.Ô)Ð)r   c                 ó6   — t          | j        d         ¦  «        S )Nr¢   )r%   r?  r@   s    r   rD  z0GoogleOAuth2Credential.token_expire_utc_datetime  s   € å" 4¤:¨mÔ#<Ñ=Ô=Ð=r   c                 óv   — | j                              | j        ¦  «        | _        |                      ¦   «          d S r:   )r@  r¬   r?  rA  r@   s    r   rE  z%GoogleOAuth2Credential._refresh_token  s4   € ØÔ%×3Ò3°D´JÑ?Ô?ˆŒ
Ø×!Ò!Ñ#Ô#Ð#Ð#Ð#r   c                 ó¼  — d}t           j                             t           j                             | j        ¦  «        ¦  «        }	 t          |¦  «        5 }|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   t          j        |¦  «        }nG# t          t          f$ r3}t                               d|t          |¦  «        ¦  «         Y d}~nd}~ww xY w|S )zâ
        Read credential file and return token information.
        Mocked in libcloud.test.common.google.GoogleTestCase.

        :return:  Token information dictionary, or None
        :rtype:   ``dict`` or ``None``
        Nz3Failed to read cached auth token from file "%s": %s)rñ   r2   Úrealpathrò   r=  rõ   rö   ry   rz   r÷   rØ   ÚLOGÚinfor1   )r<   r?  Úfilenamerþ   rž   r5   s         r   r>  z+GoogleOAuth2Credential._get_token_from_file  s  € ð ˆÝ”7×#Ò#¥B¤G×$6Ò$6°tÔ7KÑ$LÔ$LÑMÔMˆð	^Ý�h‘”ð   1Ø—v’v‘x”x�ð ð  ð  ñ  ô  ð  ð  ð  ð  ð  ð  øøøð  ð  ð  ð  å”J˜tÑ$Ô$ˆEˆEøÝ�Ð$ð 	^ð 	^ð 	^õ �HŠHÐJÈHÕVYÐZ[ÑV\ÔV\Ñ]Ô]Ð]Ð]Ð]Ð]Ð]Ð]øøøøð	^øøøð
 ˆs<   ÁB ÁA5Á)B Á5A9Á9B Á<A9Á=B ÂCÂ&)CÃCc           
      óX  — t           j                             | j        ¦  «        }t           j                             |¦  «        }	 t          j        | j        ¦  «        }t           j        t           j	        z  t           j
        z  }t          j        t          j        ||t          dd¦  «        ¦  «        d¦  «        5 }|                     |¦  «         ddd¦  «         dS # 1 swxY w Y   dS # t          $ r4}t                                d|t%          |¦  «        ¦  «         Y d}~dS d}~ww xY w)zo
        Write token to credential file.
        Mocked in libcloud.test.common.google.GoogleTestCase.
        Ú600é   ÚwNz+Failed to write auth token to file "%s": %s)rñ   r2   rò   r=  rI  ry   r  r?  ÚO_CREATÚO_WRONLYÚO_TRUNCÚfdopenrõ   r  rÝ   r0   rJ  rK  r1   )r<   rL  rž   Úwrite_flagsrþ   r5   s         r   rA  z+GoogleOAuth2Credential._write_token_to_file4  sK  € õ
 ”7×%Ò% dÔ&:Ñ;Ô;ˆÝ”7×#Ò# HÑ-Ô-ˆð		VÝ”:˜dœjÑ)Ô)ˆDÝœ*¥r¤{Ñ2µR´ZÑ?ˆKÝ”�2œ7 8¨[½#¸eÀQ¹-¼-ÑHÔHÈ#ÑNÔNð ÐRSØ—’˜‘”�ðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð øåð 	Vð 	Vð 	Võ �HŠHÐBÀHÍcÐRSÉfÌfÑUÔUÐUÐUÐUÐUÐUÐUÐUøøøøð		Vøøøs=   ÁA6C+ Â;CÃC+ ÃC"Ã"C+ Ã%C"Ã&C+ Ã+
D)Ã5)D$Ä$D))NNN)rB   rC   rD   r<  r=   ré   rC  rD  rE  r>  rA  r   r   r   r9  r9  æ  s—   € € € € € Ø7Ðð%(ð %(ð %(ð %(ðN ð*ð *ñ „Xð*ð
 ð>ð >ñ „Xð>ð$ð $ð $ðð ð ð,Vð Vð Vð Vð Vr   r9  c                   ón   ‡ — e Zd ZdZeZeZdZdZ	dZ
	 	 	 	 dˆ fd„	Zd„ Zd„ Zd	„ Zˆ fd
„Zd„ Zd„ Zd„ Zˆ xZS )ÚGoogleBaseConnectionz7Base connection class for interacting with Google APIs.zwww.googleapis.comg       @é´   Nc                 ób  •—  t          ¦   «         j        ||fi |¤Ž t          |||||fi |¤Ž| _        d                     t
          j        d         t
          j        d         t
          j        d         ¦  «        }d                     |t
          j        ¦  «        }|                      |¦  «         dS )a   
        Determine authentication type, set up appropriate authentication
        connection and get initial authentication information.

        :param  user_id: The email address (for service accounts) or Client ID
                         (for installed apps) to be used for authentication.
        :type   user_id: ``str``

        :param  key: The RSA Key (for service accounts) or file path containing
                     key or Client Secret (for installed apps) to be used for
                     authentication.
        :type   key: ``str``

        :keyword  auth_type: See GoogleAuthType class for list and description
                             of accepted values.
                             If not supplied, auth_type will be guessed based
                             on value of user_id or if the code is running
                             on a GCE instance.
        :type     auth_type: ``str``

        :keyword  credential_file: Path to file for caching authentication
                                   information.
        :type     credential_file: ``str``

        :keyword  scopes: List of OAuth2 scope URLs. The empty default sets
                          read/write access to Compute, Storage, and DNS.
        :type     scopes: ``list``
        z{}.{}.{}r   r\   é   zPython {}/{}N)	rJ   r=   r9  Úoauth2_credentialr¹   ÚsysÚversion_infoÚplatformÚuser_agent_append)
r<   r‘   r’   r+  r=  rŽ   r“   Ú
python_verÚver_platformrN   s
            €r   r=   zGoogleBaseConnection.__init__Q  s¼   ø€ ðJ 	�‰ŒÔ˜ #Ð0Ð0¨Ð0Ð0Ð0å!7Ø�S˜) _°fð"
ð "
Ø@Fð"
ð "
ˆÔð  ×&Ò&ÝÔ˜QÔÝÔ˜QÔÝÔ˜QÔñ
ô 
ˆ
ð
 &×,Ò,¨Z½¼ÑFÔFˆØ×Ò˜|Ñ,Ô,Ð,Ð,Ð,r   c                 ó$   — d|d<   | j         |d<   |S )zD
        @inherits: :class:`Connection.add_default_headers`
        zapplication/jsonr•   r–   r—   r™   s     r   rš   z(GoogleBaseConnection.add_default_headers„  s   € ð #5ˆ�ÑØœ)ˆ�‰Øˆr   c                 ó.   — d| j         j        z   |d<   ||fS )zÇ
        Check to make sure that token hasn't expired.  If it has, get an
        updated token.  Also, add the token to the headers.

        @inherits: :class:`Connection.pre_connect_hook`
        zBearer ÚAuthorization)r[  rC  )r<   Úparamsr+   s      r   Úpre_connect_hookz%GoogleBaseConnection.pre_connect_hookŒ  s#   € ð $-¨tÔ/EÔ/RÑ#Rˆ�Ñ Ø�wˆÐr   c                 ó*   — t          j        |¦  «        S )zEncode data to JSON)ry   r  )r<   rž   s     r   Úencode_dataz GoogleBaseConnection.encode_data–  s   € åŒz˜$ÑÔÐr   c                 óþ   •— d}d}||dz
  k     rW	  t          ¦   «         j        |i |¤ŽS # t          $ r'}|j        t          j        k    r|dz   }n|‚Y d}~nd}~ww xY w||dz
  k     °W t          ¦   «         j        |i |¤ŽS )z8
        @inherits: :class:`Connection.request`
        é   r   r\   N)rJ   r£   r÷   ÚerrnoÚ
ECONNRESET)r<   rû   r“   ÚretriesÚtriesr5   rN   s         €r   r£   zGoogleBaseConnection.requestš  s¸   ø€ ð ˆØˆØ�w ‘{Ò#Ð#ðØ&•u‘w”w”¨Ð7°Ð7Ð7Ð7øÝð ð ð Ø”7�eÔ.Ò.Ð.Ø! A™I�E�Eà�Gð �E�E�E�Eøøøøðøøøð �w ‘{Ò#Ð#ð �u‰wŒwŒ Ð/¨Ð/Ð/Ð/s   �) ©
A³AÁAc                 ó,   — |j         d         dk    rdS dS )zë
        Determine if operation has completed based on response.

        :param  response: JSON response
        :type   response: I{responseCls}

        :return:  True if complete, False otherwise
        :rtype:   ``bool``
        r.   ÚDONETF©r¥   )r<   r4   s     r   Úhas_completedz"GoogleBaseConnection.has_completed­  s    € ð Œ?˜8Ô$¨Ò.Ð.Ø�4à�5r   c                 ó    — d|j         d         iS )zO
        @inherits: :class:`PollingConnection.get_poll_request_kwargs`
        ÚactionÚselfLinkrq  )r<   r4   ÚcontextÚrequest_kwargss       r   Úget_poll_request_kwargsz,GoogleBaseConnection.get_poll_request_kwargs¼  s   € ð ˜(œ/¨*Ô5Ð6Ð6r   c                 óÄ   — |                      d¦  «        r@t          j        |¦  «        }t          j        dd|d         |d         |d         f¦  «        }n
| j        |z   }|S )aç  
        Update action to correct request path.

        In many places, the Google API returns a full URL to a resource.
        This will strip the scheme and host off of the path and just return
        the request.  Otherwise, it will prepend the base request_path to
        the action.

        :param  action: The action to be called in the http request
        :type   action: ``str``

        :return:  The modified request based on the action
        :rtype:   ``str``
        zhttps://r&   rZ  é   rj  )r   r   ÚurlsplitÚ
urlunsplitÚrequest_path)r<   rt  Úur£   s       r   Úmorph_action_hookz&GoogleBaseConnection.morph_action_hookÂ  se   € ð ×Ò˜ZÑ(Ô(ð 	1ÝÔ! &Ñ)Ô)ˆAÝÔ)¨2¨r°1°Q´4¸¸1¼¸qÀ¼tÐ*DÑEÔEˆGˆGàÔ'¨&Ñ0ˆGØˆr   )NNNN)rB   rC   rD   rE   r†   rM   rg   r­   r˜   Úpoll_intervalÚtimeoutr=   rš   rf  rh  r£   rr  rx  r  rP   rQ   s   @r   rW  rW  H  sÞ   ø€ € € € € ØAÐAà€FØ €KØ€DØ€MØ€Gð
 ØØØð1-ð 1-ð 1-ð 1-ð 1-ð 1-ðfð ð ðð ð ð ð  ð  ð0ð 0ð 0ð 0ð 0ð&ð ð ð7ð 7ð 7ðð ð ð ð ð ð r   rW  )r&   N)ErE   rñ   r\  r  rk  r  Úloggingr   Úurllib.parserÕ   Útypingr   Úhttp.serverr   r   Úlibcloud.utils.py3r   r   r   r	   Úlibcloud.common.baser
   r   r   r   Úlibcloud.common.typesr   r   Úlibcloud.utils.connectionr   Ú
simplejsonry   ÚImportErrorÚcryptographyr   Úcryptography.hazmat.backendsr   Úcryptography.hazmat.primitivesr   Ú%cryptography.hazmat.primitives.hashesr   Ú1cryptography.hazmat.primitives.asymmetric.paddingr   r   Ú	getLoggerrB   rJ  r   r!   r%   Úboolr6   r8   rG   rS   rW   rY   ra   rc   re   rg   r†   r‰   r±   rë   r  r  r9  rW  r   r   r   ú<module>r“     sI  ðð 2ð 2ðh 
€	€	€	Ø 
€
€
€
Ø €€€Ø €€€Ø €€€Ø €€€Ø €€€Ø Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :à >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø bÐ bÐ bÐ bÐ bÐ bÐ bÐ bÐ bÐ bÐ bÐ bØ >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9ðØÐÐÐÐøØð ð ð Ø€K€K€K€K€KðøøøðØ'Ð'Ð'Ð'Ð'Ð'Ø<Ð<Ð<Ð<Ð<Ð<Ø<Ð<Ð<Ð<Ð<Ð<Ø<Ð<Ð<Ð<Ð<Ð<ØJÐJÐJÐJÐJÐJÐJøØð ð ð à€F€F€Fðøøøð ,Ð à€gÔ˜Ñ!Ô!€ð&ð &ð &ð7ð 7ð 7ðGð Gð Gð ð  ¨X°d¬^ð  ð  ð  ð  ð ð  ð  ð  ð  �mñ  ô  ð  ð3ð 3ð 3ð 3ð 3�mñ 3ô 3ð 3ð	ð 	ð 	ð 	ð 	˜/ñ 	ô 	ð 	ð	ð 	ð 	ð 	ð 	�_ñ 	ô 	ð 	ð3ð 3ð 3ð 3ð 3˜Oñ 3ô 3ð 3ð$	ð 	ð 	ð 	ð 	˜ñ 	ô 	ð 	ð	ð 	ð 	ð 	ð 	˜/ñ 	ô 	ð 	ð	ð 	ð 	ð 	ð 	˜ñ 	ô 	ð 	ðn>ð n>ð n>ð n>ð n>�\ñ n>ô n>ð n>ðbð ð ð ð �zñ ô ð ðc$ð c$ð c$ð c$ð c$Ð3ñ c$ô c$ð c$ðLAð Að Að Að AÐ'?ñ Aô Að AðHi,ð i,ð i,ð i,ð i,Ð&>ñ i,ô i,ð i,ðXð ð ð ð Ð)Añ ô ð ð2A8ð A8ð A8ð A8ð A8ñ A8ô A8ð A8ðH_Vð _Vð _Vð _Vð _Vñ _Vô _Vð _VðDNð Nð Nð Nð NÐ/Ð1Bñ Nô Nð Nð Nð Ns$   ÁA Á	A)Á(A)Á-B ÂBÂB