
    'wf#                     b   d dl Z d dlZd dlZd dlZd dlZd dl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Zd dlmZ d dlmZ d dlmZ d dlmZ  ej.                  d      Zej2                  j5                  ej2                  j7                  d      d      Zd	d
dZded   ed   dddiZ G d d      Zy)    N)Request)service_account)Credentials)InstalledAppFlowzgcsfs.credentials~z.gcs_tokenszH586241054156-9kst7ltfj66svc342pcn43vp6ta3idin.apps.googleusercontent.comxto0LIFYX35mmHF9T1R2QBqT)	client_idclient_secret	installedr	   r
   z)https://accounts.google.com/o/oauth2/authz*https://accounts.google.com/o/oauth2/token)r	   r
   auth_uri	token_uric                   x    e Zd ZddZed        Zed        Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd ZddZy)GoogleCredentialsNc                     d|z   | _         || _        || _        i | _        d | _        d | _        t        j                         | _        || _	        | j                  |       |rt        j                  dt               y y )Nz+https://www.googleapis.com/auth/devstorage.methodzWThe `check_credentials` argument is deprecated and will be removed in a future release.)scopeprojectaccessheadscredentialsr   	threadingLocklocktokenconnectwarningswarnDeprecationWarning)selfr   r   r   check_credentialss        e/home/panchajanya/Development/work/volatility3/venv/lib/python3.12/site-packages/gcsfs/credentials.py__init__zGoogleCredentials.__init__(   so    BVK

NN$	
E"MMi"     c                     	 t        t        d      5 }t        j                  |      }ddd       t
        _        y# 1 sw Y   xY w# t        $ r i }Y |t
        _        yw xY w)zGet "browser" tokens from discrbN)opentfilepickleload	Exceptionr   tokens)clsfr,   s      r"   load_tokenszGoogleCredentials.load_tokens:   s\    	eT" (aQ( $* 	( ( 	F#) 	s%   A <A AA A! A!c                     	 t        t        d      5 } t        j                  t        j
                  | d       d d d        y # 1 sw Y   y xY w# t        $ r+}t        j                  dt        |      z          Y d }~y d }~ww xY w)Nwb   zSaving token cache failed: )
r'   r(   r)   dumpr   r,   r+   r   r   str)r.   es     r"   _save_tokenszGoogleCredentials._save_tokensD   sj    	BeT" <a-44a;< < < 	BMM7#a&@AA	Bs3   A &AA A
A 
A 	B!A<<Bc                    t        j                  | j                  g      \  }}t        j                  d      }| j
                  r4| j
                  |k7  r%t        |j                  | j
                  |            || _        || _        y )Nscopesa          User-provided project '{}' does not match the google default project '{}'. Either

          1. Accept the google-default project by not passing a `project` to GCSFileSystem
          2. Configure the default project to match the user-provided project (gcloud config set project)
          3. Use an authorization method other than 'google_default' by providing 'token=...'
        )	gauthdefaultr   textwrapdedentr   
ValueErrorformatr   )r    r   r   msgs       r"   _connect_google_defaultz)GoogleCredentials._connect_google_defaultL   sk    $}}TZZLAWoo
 <<DLLG3SZZg>??&r$   c                 L   t         j                  j                         | _        	 t	        j
                         5 }t        |      }| j                  j                  |       d d d        y # 1 sw Y   y xY w# t         j                  j                  $ r}t        d      |d }~ww xY w)NzInvalid gcloud credentials)r:   compute_enginer   r   requestsSessionr   refresh
exceptionsRefreshErrorr>   )r    sessionreqerrors       r"   _connect_cloudz GoogleCredentials._connect_cloud\   s     //;;=	F!!# .wg&  ((-. . . ,, 	F9:E	Fs4   A5 'A) A5 )A2.A5 2A5 5B#BB#c                     t        | j                        dk(  rt        d      | j                  | j                  }}||f| j                  v r| j                  ||f   }|| _        y y )Nr   zNo cached tokens)lenr,   r>   r   r   r   )r    r   r   r   s       r"   _connect_cachez GoogleCredentials._connect_cachee   sa    t{{q /00,,V+++w&78K*D ,r$   c                     	 t         j                  j                  || j                  g      }|S #  t        d|d   |d   |d   d      }Y |S xY w)zy
        Convert old dict-style token.

        Does not preserve access token itself, assumes refresh required.
        r8   Nrefresh_tokenr
   r	   z#https://oauth2.googleapis.com/token)rQ   r
   r	   r   )r   r   from_service_account_infor   )r    r   s     r"   _dict_to_credentialsz&GoogleCredentials._dict_to_credentialso   sm    	#//IItzzl J E 	
  #O4#O4,?E s	   ,0 Ac                 Z   t        |t              r=t        j                  j	                  |      r	 | j                  |       yt        |      }t        |t              r| j                  |      }n<t        |t        j                  j                  j                        r|}nt        d      || _        | j                  j                   r&| j                  j#                  | j$                         yy#  t        |      5 }t        j                  |      }ddd       n# 1 sw Y   nxY wY xY w)a  
        Connect using a concrete token

        Parameters
        ----------
        token: str, dict or Credentials
            If a str and a valid file name, try to load as a Service file, or next as a JSON;
            if not a valid file name, assume it's a valid raw (non-renewable/session) token, and pass to Credentials. If
            dict, try to interpret as credentials; if Credentials, use directly.
        NzToken format not understood)
isinstancer4   ospathexists_connect_servicer'   jsonr*   r   dictrS   googleauthr   r>   validapplyr   )r    r   datar   s       r"   _connect_tokenz GoogleCredentials._connect_token   s     eS!ww~~e$	0))%0 $E*eT"33E:Kv{{66BBCK:;;&!!""4::. "0 e 0 $		$0 0 0s#   C0 0D*=D	D*D%	!D*c                    | j                   y | j                   j                  ry t        j                         5 }t	        |      }| j
                  5  | j                   j                  r	 d d d        d d d        y t        j                  d       | j                   j                  |       | j                  | j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NzGCS refresh)r   r^   rD   rE   r   r   loggerdebugrF   r_   r   )r    rI   rJ   s      r"   maybe_refreshzGoogleCredentials.maybe_refresh   s    #!! 	'7'"C '##))'	' 	'
 ]+  ((-

4::&'	' 	'' '	' 	's0   C"C)C":ACC"C	C""C+c                 t    | j                          | j                  | j                  j                  |       yy)z2Insert credential headers in-place to a dictionaryN)re   r   r_   )r    outs     r"   r_   zGoogleCredentials.apply   s3    '""3' (r$   c                 j    t         j                  j                  || j                  g      }|| _        y )Nr8   )r   r   from_service_account_filer   r   )r    fnr   s      r"   rY   z"GoogleCredentials._connect_service   s3    %11KK

| L 
 'r$   c                     d | _         y N)r   )r    s    r"   _connect_anonzGoogleCredentials._connect_anon   s
    r$   c                     t        j                  t        | j                  g      }|j	                         }|| j
                  | j                  | j                  f<   | j                          || _	        y rl   )
r   from_client_configclient_configr   run_local_serverr,   r   r   r6   r   )r    flowr   s      r"   _connect_browserz"GoogleCredentials._connect_browser   sW    22=4::,O++-3>T\\4;;/0&r$   c                    |dvr| j                  |       y|<dD ],  }	 | j                  |       t        j                  d|        y t        d       | j                  d	|z                 || _        y# t        j
                  j                  j                  t        f$ r+}t        j                  d|z  |       d| _	        Y d}~d}~ww xY w)
ap  
        Establish session token. A new token will be requested if the current
        one is within 100s of expiry.

        Parameters
        ----------
        method: str (google_default|cache|cloud|token|anon|browser) or None
            Type of authorisation to implement - calls `_connect_*` methods.
            If None, will try sequence of methods.
        )google_defaultcachecloudr   anonbrowserNN)ru   rv   rw   rx   r   zConnected with method %sz"Connection with method "%s" failed)exc_infoz#All connection methods have failed!	_connect_)ra   r   rc   rd   r\   r]   rG   GoogleAuthErrorr>   r   RuntimeError__getattribute__r   )r    r   methr5   s       r"   r   zGoogleCredentials.connect   s      
 
 '^D J,LLL-LL!;TB	J" ##HII7D!!+"679 DK ..>>
K , LL<tCa ! 
 (,D$$,s   (A66-C#!C		Crl   )__name__
__module____qualname__r#   classmethodr/   staticmethodr6   rA   rL   rO   rS   ra   re   r_   rY   rm   rs   r    r$   r"   r   r   '   sj    $ * * B B' F+0!/F'(' '*!r$   r   ) rZ   loggingrV   r)   r<   r   r   google.authr]   r:   google.auth.compute_enginer\   google.auth.credentialsgoogle.auth.exceptionsrD   google.auth.transport.requestsr   google.oauth2r   google.oauth2.credentialsr   google_auth_oauthlib.flowr   	getLoggerrc   rW   join
expanduserr(   
not_secretrp   r   r   r$   r"   <module>r      s      	      !    2 ) 1 6			.	/
RWW'',m<"/
 ,#O4?A	S! S!r$   