o
    ~j6hh                     @   s   d Z ddlZzddlZddlZdZW n ey   dZY nw zddlZW n ey/   dZY nw zddlZddl	ZdZ
W n eyG   dZ
Y nw dddZdddZd	d
 Zdd Zdd Zdd Zdd Zdd ZdS )z=Helpers for authentication using oauth2client or google-auth.    NTFc                 C   s&   t rtjj| ||d\}}|S td)z'Returns credentials loaded from a file.scopesquota_project_idzAclient_options.credentials_file is only supported in google-auth.)HAS_GOOGLE_AUTHgoogleauthload_credentials_from_fileEnvironmentError)filenamer   r   credentials_ r   d/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/googleapiclient/_auth.pycredentials_from_file)   s   
r   c                 C   sL   t rtjj| |d\}}|S tr"| dus|durtdtjj	 S td)z(Returns Application Default Credentials.r   Nzwclient_options.scopes and client_options.quota_project_id are not supported in oauth2client.Please install google-auth.zZNo authentication library is available. Please install either google-auth or oauth2client.)
r   r   r   defaultHAS_OAUTH2CLIENTr	   oauth2clientclientGoogleCredentialsget_application_default)r   r   r   r   r   r   r   default_credentials6   s   
r   c                 C   sV   t rt| tjjjrtjj| |S z|  r| |W S | W S  t	y*   |  Y S w )a  Scopes the credentials if necessary.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to scope.
        scopes (Sequence[str]): The list of scopes.

    Returns:
        Union[google.auth.credentials.Credentials,
            oauth2client.client.Credentials]: The scoped credentials.
    )
r   
isinstancer   r   r   Credentialswith_scopes_if_requiredcreate_scoped_requiredcreate_scopedAttributeError)r   r   r   r   r   with_scopesK   s   r   c                 C   sL   ddl m} tr t| tjjjr tdu rt	dtj
| | dS | | S )aa  Returns an http client that is authorized with the given credentials.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to use.

    Returns:
        Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An
            authorized http client.
    r   )
build_httpNzCredentials from google.auth specified, but google-api-python-client is unable to use these credentials unless google-auth-httplib2 is installed. Please install google-auth-httplib2.http)googleapiclient.httpr   r   r   r   r   r   r   google_auth_httplib2
ValueErrorAuthorizedHttp	authorize)r   r   r   r   r   authorized_httpd   s   r&   c                 C   s:   t  }trt| tjjjrt	|}| 
|S | 
|S N)httplib2Httpr   r   r   r   r   r   r"   Requestrefresh)r   refresh_httprequestr   r   r   refresh_credentials   s
   


r.   c                 C   s   t | st|  | |S r'   )is_validr.   apply)r   headersr   r   r   apply_credentials   s   
r2   c                 C   s,   t rt| tjjjr| jS | jd uo| j S r'   )	r   r   r   r   r   r   validaccess_tokenaccess_token_expired)r   r   r   r   r/      s
   
r/   c                 C   sB   | d u rd S t | jdr| jjS t | drt| jtjs| jS d S )Nr   )hasattrr-   r   r   r(   r   r   r   r   r   get_credentials_from_http   s   r7   )NN)__doc__r(   google.authr   google.auth.credentialsr   ImportErrorr"   r   oauth2client.clientr   r   r   r   r&   r.   r2   r/   r7   r   r   r   r   <module>   s:   


