o
    ýÞh\  ã                   @   s†   d 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ZdZdZ	dZ
d	Zd
ZdZdZdd„ Zdd„ Zdd„ Zdd„ Zddd„ZdS )z9Helpers for reading the Google Cloud SDK's configuration.é    N)Ú_helpers)Úenvironment_vars)Ú
exceptionsÚgcloudÚAPPDATAz$application_default_credentials.jsonz
gcloud.cmd)ÚconfigÚgetÚproject)Úauthzprint-access-tokenzH764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.apps.googleusercontent.comc                  C   sŒ   zt jtj W S  ty   Y nw t jdkr"t j t j d¡dt	¡S zt j t jt
 t	¡W S  tyE   t j dd¡} t j | dt	¡ Y S w )z�Returns the absolute path the the Cloud SDK's configuration directory.

    Returns:
        str: The Cloud SDK config path.
    Úntú~z.configÚSystemDrivezC:ú\)ÚosÚenvironr   ÚCLOUD_SDK_CONFIG_DIRÚKeyErrorÚnameÚpathÚjoinÚ
expanduserÚ_CONFIG_DIRECTORYÚ_WINDOWS_CONFIG_ROOT_ENV_VARr   )Údrive© r   úV/var/www/html/premium_crap/venv/lib/python3.10/site-packages/google/auth/_cloud_sdk.pyÚget_config_path-   s   ÿ

ÿür   c                  C   s   t ƒ } tj | t¡S )z°Gets the path to the application default credentials file.

    The path may or may not exist.

    Returns:
        str: The full path to application default credentials.
    )r   r   r   r   Ú_CREDENTIALS_FILENAME)Úconfig_pathr   r   r   Ú(get_application_default_credentials_pathI   s   r   c                 C   s@   t tjdƒ�}tj| |d�}W d  ƒ |S 1 sw   Y  |S )zJ Return subprocess.check_output with the given command and ignores stderr.Úw©ÚstderrN)Úopenr   ÚdevnullÚ
subprocessÚcheck_output)Úcommandr$   Úoutputr   r   r   Ú_run_subprocess_ignore_stderrU   s   
ÿþr)   c               
   C   s^   t jdkrt} nt} zt| ft ƒ}t |¡ ¡ }|r|W S dW S  t	j
ttfy.   Y dS w )zaGets the project ID from the Cloud SDK.

    Returns:
        Optional[str]: The project ID.
    r   N)r   r   Ú_CLOUD_SDK_WINDOWS_COMMANDÚ_CLOUD_SDK_POSIX_COMMANDr)   Ú%_CLOUD_SDK_CONFIG_GET_PROJECT_COMMANDr   Ú
from_bytesÚstripr%   ÚCalledProcessErrorÚOSErrorÚIOError)r'   r	   r   r   r   Úget_project_id\   s   
ÿÿr2   c              
   C   sŒ   t jdkrt}nt}z"| r|ft d|  f }n|ft }tj|tjd�}| d¡ 	¡ W S  tj
ttfyE } z	t d|¡}||‚d}~ww )a“  Load user access token with the ``gcloud auth print-access-token`` command.

    Args:
        account (Optional[str]): Account to get the access token for. If not
            specified, the current active account will be used.

    Returns:
        str: The user access token.

    Raises:
        google.auth.exceptions.UserAccessTokenError: if failed to get access
            token from gcloud.
    r   z
--account=r!   zutf-8zFailed to obtain access tokenN)r   r   r*   r+   Ú$_CLOUD_SDK_USER_ACCESS_TOKEN_COMMANDr%   r&   ÚSTDOUTÚdecoder.   r/   r0   r1   r   ÚUserAccessTokenError)Úaccountr'   Úaccess_tokenÚ
caught_excÚnew_excr   r   r   Úget_auth_access_tokenu   s*   
ÿþÿ
ÿ€ür;   )N)Ú__doc__r   r%   Úgoogle.authr   r   r   r   r   r   r+   r*   r,   r3   ÚCLOUD_SDK_CLIENT_IDr   r   r)   r2   r;   r   r   r   r   Ú<module>   s(   ÿ