File: //opt/gsutil/third_party/apitools/apitools/base/py/__pycache__/credentials_lib.cpython-39.pyc
a
�z�g�u � @ s� d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddlm
Z
ddlmZ ddlZddlmZ ddlmZ ddlmZ dd lmZ zddlZd
ZW nP e�y Z z6ej�dd�Ze�d
�s�e�d�s�e�dZW Y dZ[n
dZ[0 0 zddlmZ W n e�yB ddlmZ Y n0 zddlm Z d
Z!W nJ e�y� dZ!zddlm"Z" W n e�y� ddlm"Z" Y n0 Y n0 zddl#Z#e#j$Z$W n e�y� dZ$Y n0 g d�Z%e�&� a'dd� Z(g Z)d6dd�Z*d7dd�Z+d8dd�Z,dd� Z-d9dd�Z.G d d!� d!ej/�Z0G d"d#� d#ej1j2�Z3d:d$d%�Z4d;d&d'�Z5G d(d)� d)e6�Z7d<d*d+�Z8d,d-� Z9e*d=d.d/��Z:e*d0d1� �Z;e*d2d3� �Z<e*d>d4d5��Z=dS )?z,Common credentials classes and constructors.� )�print_functionN)�service_account)�tools)�http_client)�urllib)�
exceptions)�utilT�SERVER_SOFTWARE� ZDevelopmentzGoogle App EngineF)�gce)�multiprocess_file_storage)�multistore_file)�CredentialsFromFile�GaeAssertionCredentials�GceAssertionCredentials�GetCredentials�GetUserinfo�!ServiceAccountCredentialsFromFilec C s | a d S �N)�cache_file_lock)�lock� r �D/opt/gsutil/third_party/apitools/apitools/base/py/credentials_lib.py�SetCredentialsCacheFileLock_ s r c C s0 |du rt t�}nt|t t��}t�|| � | S )aP Register a new method for fetching credentials.
This new method should be a function with signature:
client_info, **kwds -> Credentials or None
This method can be used as a decorator, unless position needs to
be supplied.
Note that method must *always* accept arbitrary keyword arguments.
Args:
method: New credential-fetching method.
position: (default: None) Where in the list of methods to
add this; if None, we append. In all but rare cases,
this should be either 0 or None.
Returns:
method, for use as a decorator.
N)�len�_CREDENTIALS_METHODS�min�insert)�method�positionr r r �_RegisterCredentialsMethodj s
r c
K s� t �|�}||d�t|��|p$d| d�}
tD ]$}||
fi | ��}|dur.| S q.|pbtj�d�}t||
|d�}|dur~|S t �
d��dS )zDAttempt to get credentials, using an oauth dance as the last resort.� z%s-generated/0.1)� client_id�
client_secret�scope�
user_agentNz~/.apitools.token)�oauth2client_argsz"Could not create valid credentials)r �NormalizeScopes�join�sortedr �os�path�
expanduserr r �CredentialsError)
�package_name�scopesr"