File: //opt/cppython/lib/python3.8/site-packages/google/auth/__pycache__/_default_async.cpython-38.pyc
U
KD�g7- � @ s~ d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddd�Zddd �Z dd
d�Z
dd
� Zddd�Zddd�Z
dS )zgApplication default credentials.
Implements application default credentials and project ID detection.
� N)�_default)�environment_vars)�
exceptionsc C s� t j�| �st�d�| ���t�| d��P}zt� |�}W n: t
k
rr } zt�d�| �|�}||�W 5 d}~X Y nX W 5 Q R X |�d�}|tj
k�rddlm} z|jj||d�}W n> t
k
r� } z d �| �} t�| |�}||�W 5 d}~X Y nX |�r|�|�}|j�st�|� |dfS |tjk�r�dd
lm}
z|
jj||d��|�}W n@ t
k
�r� } z d�| �} t�| |�}||�W 5 d}~X Y nX ||�d�fS t�d
j| |tjd���dS )aF Loads Google credentials from a file.
The credentials file must be a service account key or stored authorized
user credentials.
Args:
filename (str): The full path to the credentials file.
scopes (Optional[Sequence[str]]): The list of scopes for the credentials. If
specified, the credentials will automatically be scoped if
necessary
quota_project_id (Optional[str]): The project ID used for
quota and billing.
Returns:
Tuple[google.auth.credentials.Credentials, Optional[str]]: Loaded
credentials and the project ID. Authorized user credentials do not
have the project ID information.
Raises:
google.auth.exceptions.DefaultCredentialsError: if the file is in the
wrong format or is missing.
zFile {} was not found.�rz!File {} is not a valid json file.N�typer )�_credentials_async)�scopesz2Failed to load authorized user credentials from {})�_service_account_asyncz2Failed to load service account credentials from {}�
project_idzZThe file {file} does not have a valid type. Type is {type}, expected one of {valid_types}.)�filer Zvalid_types)�os�path�existsr �DefaultCredentialsError�format�io�open�json�load�
ValueError�getr Z_AUTHORIZED_USER_TYPEZ
google.oauth2r �CredentialsZfrom_authorized_user_info�with_quota_project�quota_project_idZ#_warn_about_problematic_credentialsZ_SERVICE_ACCOUNT_TYPEr Zfrom_service_account_infoZ_VALID_TYPES)�filenamer r Zfile_obj�infoZ
caught_exc�new_excZcredential_type�credentials�msgZservice_account� r �G/opt/cppython/lib/python3.8/site-packages/google/auth/_default_async.py�load_credentials_from_file sf � �"
�
��
��r! c C sH ddl m} |�� }tj�|�s$dS t|| d�\}}|s@|�� }||fS )z7Gets the credentials and project ID from the Cloud SDK.r ��
_cloud_sdk�NN�r )�google.authr# �(get_application_default_credentials_pathr r
�isfiler! Zget_project_id)r r# Zcredentials_filenamer r
r r r �_get_gcloud_sdk_credentialsm s �
r) c C sl ddl m} |�� }tj�tj�}|dk r<||kr<t| d�S |dk rdt tjtj | d�\}}||fS dS dS )zRGets credentials from the GOOGLE_APPLICATION_CREDENTIALS environment
variable.r r"