Ë
    U¼SfH.  ã                   ó4  — d Z ddlZddlmZ ddlZddlZddlZ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  ej                  e«      Z ej$                  ej&                  d«      Zes ej$                  ej*                  d«      Zd	j-                  e«      Zd
j-                   ej$                  ej0                  d«      «      ZdZdZeeiZ	  e ej$                  dd«      «      ZdZ dZ!d„ Z"d„ Z#edfd„Z$edddddfd„Z%d„ Z&d„ Z'dd„Z(dd„Z)y# e$ r dZY Œ2w xY w)z‘Provides helper methods for talking to the Compute Engine metadata server.

See https://cloud.google.com/compute/docs/metadata for more details.
é    N)Úurljoin)Ú_helpers)Úenvironment_vars)Ú
exceptions)Úmetricszmetadata.google.internalzhttp://{}/computeMetadata/v1/z	http://{}z169.254.169.254zmetadata-flavorÚGoogleÚGCE_METADATA_TIMEOUTé   z/sys/class/dmi/id/product_namec                 óV   — t        | «      ryt        j                  dk(  ryt        «       S )a  Checks to see if the code runs on Google Compute Engine

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.

    Returns:
        bool: True if the code runs on Google Compute Engine, False otherwise.
    TÚntF)ÚpingÚosÚnameÚdetect_gce_residency_linux©Úrequests    úcC:\Users\user\Documents\project_loop\venv\Lib\site-packages\google/auth/compute_engine/_metadata.pyÚ	is_on_gcer   B   s'   € ô ˆG„}Øä	‡w�w�$‚àô &Ó'Ð'ó    c                  óÒ   — 	 t        t        d«      5 } | j                  «       j                  «       }ddd«       j                  t        «      S # 1 sw Y   ŒxY w# t        $ r Y yw xY w)z Detect Google Compute Engine residency by smbios check on Linux

    Returns:
        bool: True if the GCE product name file is detected, False otherwise.
    ÚrNF)ÚopenÚ_GCE_PRODUCT_NAME_FILEÚreadÚstripÚ	ExceptionÚ
startswithÚ_GOOGLE)Úfile_objÚcontents     r   r   r   W   sc   € ðÜÔ(¨#Ó.ð 	.°(Ø—m‘m“o×+Ñ+Ó-ˆG÷	.ð ×ÑœgÓ&Ð&÷	.ð 	.ûô ò Ùðús'   ‚A ’A±A ÁAÁA Á	A&Á%A&c                 óÂ  — d}t         j                  «       }t        j                  «       |t        j                  <   ||k  rX	  | t
        d||¬«      }|j                  j                  t        «      }|j                  t        j                  k(  xr	 |t        k(  S y# t        j                  $ r*}t        j!                  d|dz   ||«       |dz  }Y d}~nd}~ww xY w||k  rŒŸŒH)a½  Checks to see if the metadata server is available.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        timeout (int): How long to wait for the metadata server to respond.
        retry_count (int): How many times to attempt connecting to metadata
            server using above timeout.

    Returns:
        bool: True if the metadata server is reachable, False otherwise.
    r   ÚGET)ÚurlÚmethodÚheadersÚtimeoutúJCompute Engine Metadata server unavailable on attempt %s of %s. Reason: %sé   NF)Ú_METADATA_HEADERSÚcopyr   Úmds_pingÚAPI_CLIENT_HEADERÚ_METADATA_IP_ROOTr%   ÚgetÚ_METADATA_FLAVOR_HEADERÚstatusÚhttp_clientÚOKÚ_METADATA_FLAVOR_VALUEr   ÚTransportErrorÚ_LOGGERÚwarning)r   r&   Úretry_countÚretriesr%   ÚresponseÚmetadata_flavorÚes           r   r   r   g   sÝ   € ð& €GÜ×$Ñ$Ó&€GÜ)0×)9Ñ)9Ó);€GŒG×%Ñ%Ñ&à
�KÒ
ð	ÙÜ%¨e¸WÈgôˆHð '×.Ñ.×2Ñ2Ô3JÓKˆOà—‘¤;§>¡>Ñ1ò >Ø#Ô'=Ñ=ðð øô ×(Ñ(ò 	Ü�O‰Oð/à˜!‘ØØôð �q‰L�Gûð	úð �KÓ
øs   ÁAB ÂCÂ- CÃCFé   c                 óÈ  — t        ||«      }|€i n|}	t        j                  «       }
|r|
j                  |«       |rd|	d<   t	        j
                  ||	«      }d}||k  r	  | |d|
¬«      }n$t        j                  d	j                  |«      «      ‚t	        j                  |j                  «      }|j                  t        j                  k(  r|ry|j                  t        j                   k(  r=t	        j"                  |j$                  d
   «      dk(  r	 t'        j(                  |«      S |S t        j                  dj                  ||j                  |j                  «      |«      ‚# t        j                  $ r*}t        j                  d|dz   ||«       |dz  }Y d}~nd}~ww xY w||k  r�ŒL�ŒA# t*        $ r,}t        j                  dj                  |«      «      }||‚d}~ww xY w)aî  Fetch a resource from the metadata server.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        path (str): The resource to retrieve. For example,
            ``'instance/service-accounts/default'``.
        root (str): The full path to the metadata server root.
        params (Optional[Mapping[str, str]]): A mapping of query parameter
            keys to values.
        recursive (bool): Whether to do a recursive query of metadata. See
            https://cloud.google.com/compute/docs/metadata#aggcontents for more
            details.
        retry_count (int): How many times to attempt connecting to metadata
            server using above timeout.
        headers (Optional[Mapping[str, str]]): Headers for the request.
        return_none_for_not_found_error (Optional[bool]): If True, returns None
            for 404 error instead of throwing an exception.

    Returns:
        Union[Mapping, str]: If the metadata server returns JSON, a mapping of
            the decoded JSON is return. Otherwise, the response content is
            returned as a string.

    Raises:
        google.auth.exceptions.TransportError: if an error occurred while
            retrieving metadata.
    NÚtrueÚ	recursiver   r"   )r#   r$   r%   r'   r(   zqFailed to retrieve {} from the Google Compute Engine metadata service. Compute Engine Metadata server unavailablezcontent-typezapplication/jsonzMReceived invalid JSON from the Google Compute Engine metadata service: {:.20}z^Failed to retrieve {} from the Google Compute Engine metadata service. Status: {} Response:
{})r   r)   r*   Úupdater   Úupdate_queryr   r4   r5   r6   ÚformatÚ
from_bytesÚdatar0   r1   Ú	NOT_FOUNDr2   Úparse_content_typer%   ÚjsonÚloadsÚ
ValueError)r   ÚpathÚrootÚparamsr?   r7   r%   Úreturn_none_for_not_found_errorÚbase_urlÚquery_paramsÚheaders_to_user#   r8   r9   r;   r    Ú
caught_excÚnew_excs                     r   r.   r.   —   sÙ  € ôL �t˜TÓ"€HØ˜‘2¨V€Lä&×+Ñ+Ó-€NÙØ×Ñ˜gÔ&áØ$*ˆ�[Ñ!ä
×
Ñ
 ¨,Ó
7€Cà€GØ
�KÒ
ð	Ù 3¨u¸nÔMˆHØô ×'Ñ'ðKßKQÉ6ÐRUË;ó
ð 	
ô
 ×!Ñ! (§-¡-Ó0€Gà‡�œ+×/Ñ/Ò/Ñ4SØà‡�œ+Ÿ.™.Ò(ä×'Ñ'¨×(8Ñ(8¸Ñ(HÓIØ!ò"ð.Ü—z‘z 'Ó*Ð*ð ˆNä
×
#Ñ
#ð	5ß5;±VØ�—‘ (§-¡-ó6
ð 	óð øôI ×(Ñ(ò 	Ü�O‰Oð/à˜!‘ØØôð �q‰L�Gûð	úð �KÔ
úô@ ò .Ü$×3Ñ3ð/ß/5©v°g«ó�ð  :Ð-ûð.ús0   ÁE# ÄF, Å#F Å6 FÆF Æ,	G!Æ5'GÇG!c                 ó   — t        | d«      S )aO  Get the Google Cloud Project ID from the metadata server.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.

    Returns:
        str: The project ID

    Raises:
        google.auth.exceptions.TransportError: if an error occurred while
            retrieving metadata.
    zproject/project-id©r.   r   s    r   Úget_project_idrU   ü   s   € ô ˆwÐ,Ó-Ð-r   c                 ó(   — t        | dd¬«      }|sy|S )aÒ  Get the universe domain value from the metadata server.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.

    Returns:
        str: The universe domain value. If the universe domain endpoint is not
        not found, return the default value, which is googleapis.com

    Raises:
        google.auth.exceptions.TransportError: if an error other than
            404 occurs while retrieving metadata.
    zuniverse/universe_domainT)rM   zgoogleapis.comrT   )r   Úuniverse_domains     r   Úget_universe_domainrX     s$   € ô ØÐ+ÈTô€Oñ ØØÐr   c                 óD   — dj                  |«      }t        | |ddi¬«      S )aÉ  Get information about a service account from the metadata server.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        service_account (str): The string 'default' or a service account email
            address. The determines which service account for which to acquire
            information.

    Returns:
        Mapping: The service account's information, for example::

            {
                'email': '...',
                'scopes': ['scope', ...],
                'aliases': ['default', '...']
            }

    Raises:
        google.auth.exceptions.TransportError: if an error occurred while
            retrieving metadata.
    zinstance/service-accounts/{0}/r?   r>   )rL   )rB   r.   )r   Úservice_accountrJ   s      r   Úget_service_account_infor[   $  s*   € ð. ,×2Ñ2°?ÓC€Dô ˆw˜ k°6Ð%:Ô;Ð;r   c                 óH  — |r&t        |t        «      sdj                  |«      }d|i}nd}t        j                  t        j
                  «       i}dj                  |«      }t        | |||¬«      }t        j                  «       t        j                  |d   ¬«      z   }|d   |fS )	aŸ  Get the OAuth 2.0 access token for a service account.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        service_account (str): The string 'default' or a service account email
            address. The determines which service account for which to acquire
            an access token.
        scopes (Optional[Union[str, List[str]]]): Optional string or list of
            strings with auth scopes.
    Returns:
        Tuple[str, datetime]: The access token and its expiration.

    Raises:
        google.auth.exceptions.TransportError: if an error occurred while
            retrieving metadata.
    ú,ÚscopesNz#instance/service-accounts/{0}/token)rL   r%   Ú
expires_in)ÚsecondsÚaccess_token)Ú
isinstanceÚstrÚjoinr   r,   Útoken_request_access_token_mdsrB   r.   r   ÚutcnowÚdatetimeÚ	timedelta)r   rZ   r^   rL   Úmetrics_headerrJ   Ú
token_jsonÚtoken_expirys           r   Úget_service_account_tokenrl   A  s¥   € ñ$ Ü˜&¤#Ô&Ø—X‘X˜fÓ%ˆFØ˜FÐ#‰àˆô 	×!Ñ!¤7×#IÑ#IÓ#Kð€Nð 1×7Ñ7¸ÓH€DÜ�W˜d¨6¸>ÔJ€JÜ—?‘?Ó$¤x×'9Ñ'9Ø˜<Ñ(ô(ñ €Lð �nÑ% |Ð3Ð3r   )Údefault)rm   N)*Ú__doc__rg   Úhttp.clientÚclientr1   rG   Úloggingr   Úurllib.parser   Úgoogle.authr   r   r   r   Ú	getLoggerÚ__name__r5   ÚgetenvÚGCE_METADATA_HOSTÚ_GCE_METADATA_HOSTÚGCE_METADATA_ROOTrB   Ú_METADATA_ROOTÚGCE_METADATA_IPr-   r/   r3   r)   ÚintÚ_METADATA_DEFAULT_TIMEOUTrI   r   r   r   r   r   r.   rU   rX   r[   rl   © r   r   ú<module>r      sY  ðñó
 Ý !Û Û Û 	Ý  å  Ý (Ý "Ý à
ˆ'×
Ñ
˜HÓ
%€ð �R—Y‘YÐ/×AÑAÀ4ÓHÐ ÙØ"˜Ÿ™Ø×*Ñ*Ð,FóÐð 1×7Ñ7Ð8JÓK€ð  ×&Ñ&Ø€B‡I�IÐ×.Ñ.Ð0AÓBóÐ ð ,Ð Ø!Ð Ø,Ð.DÐEÐ ð"Ù # I B§I¡IÐ.DÀaÓ$HÓ IÐð
 €Ø9Ð ò(ò*'ð  4Àó -ðf 
ØØØØØ$)óbòJ.ò"ó.<ô:"4øðO ò "Ø !Òð"ús   ÃD ÄDÄD