
    Bf#                     n   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j                            ej                            d          d          Zd	d
dZded         ed         dddiZ G d d          ZdS )    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                       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dS )GoogleCredentialsNc                    d|z   | _         || _        || _        i | _        d | _        d | _        t          j                    | _        || _	        | 
                    |           |rt          j        dt                     d S d S )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        `/home/panchajanya/Development/work/volatility3/lib/python3.11/site-packages/gcsfs/credentials.py__init__zGoogleCredentials.__init__(   s    BVK

N$$	
E""" 	Mi"    	 	    c                     	 t          t          d          5 }t          j        |          }ddd           n# 1 swxY w Y   n# t          $ r i }Y nw xY w|t
          _        dS )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( ( ( ( ( ( ( ( ( ( ( ( ( ( ( 	 	 	FFF	#)   s-   A 8A <A < A AAc                     	 t          t          d          5 } t          j        t          j        | d           d d d            d S # 1 swxY w Y   d S # t          $ r/}t          j        dt          |          z              Y d }~d S 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   s    	BeT"" <a-4a;;;< < < < < < < < < < < < < < < < < < 	B 	B 	BM7#a&&@AAAAAAAAA	Bs9   A !AA A		A A	A 
B$BBc                     t          j        | j        g          \  }}t          j        d          }| j        r3| j        |k    r(t          |                    | j        |                    || _        || _        d S )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   s    $}TZLAAAWo
 
 < 	@DLG33SZZg>>???&r$   c                 P   t           j                                        | _        	 t	          j                    5 }t          |          }| j                            |           d d d            d S # 1 swxY w Y   d S # 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 	F 	F9::E	Fs:   A< *A/"A< /A33A< 6A37A< <B%B  B%c                     t          | j                  dk    rt          d          | j        | j        }}||f| j        v r| j        ||f         }|| _        d S d S )Nr   zNo cached tokens)lenr,   r>   r   r   r   )r    r   r   r   s       r"   _connect_cachez GoogleCredentials._connect_cachee   sl    t{q  /000,V+++w&78K*D ,+r$   c                     	 t           j                            || j        g          }n-#  t          d|d         |d         |d         d          }Y nxY w|S )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   sx    	#/IItzl J  EE	
  #O4#O4,?  EEE s	   '* (Ac                 j   t          |t                    rt          j                            |          rZ	 |                     |           dS #  t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   Y nxY wt          |          }t          |t                    r|                     |          }n6t          |t          j        j        j	                  r|}nt          d          || _        | j        j        r!| j                            | j                   dS dS )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   sg    eS!! 	+w~~e$$ +	0))%000F0 e 0 $	$0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 $E**eT"" 	<33E::KKv{6BCC 	<KK:;;;&! 	/""4:.....	/ 	/s/   A BA?3B?B	BB	Bc                    | j         d S | j         j        rd S t          j                    5 }t	          |          }| j        5  | j         j        r	 d d d            d d d            d S t                              d           | j                             |           | 	                    | j
                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NzGCS refresh)r   r^   rD   rE   r   r   loggerdebugrF   r_   r   )r    rI   rJ   s      r"   maybe_refreshzGoogleCredentials.maybe_refresh   s   #F! 	F 	'7'""C ' '#) ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	'
 ]+++ ((---

4:&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'sB   CCC(AC6CC	C	C	
CC!Cc                 t    |                                   | j        | j                            |           dS dS )z2Insert credential headers in-place to a dictionaryN)re   r   r_   )r    outs     r"   r_   zGoogleCredentials.apply   sB    '""3''''' ('r$   c                 b    t           j                            || j        g          }|| _        d S )Nr8   )r   r   from_service_account_filer   r   )r    fnr   s      r"   rY   z"GoogleCredentials._connect_service   s9    %1KK
| L 
 
 'r$   c                     d | _         d S N)r   )r    s    r"   _connect_anonzGoogleCredentials._connect_anon   s    r$   c                     t          j        t          | j        g          }|                                }|| j        | j        | j        f<   |                                  || _	        d S rl   )
r   from_client_configclient_configr   run_local_serverr,   r   r   r6   r   )r    flowr   s      r"   _connect_browserz"GoogleCredentials._connect_browser   s^    2=4:,OO++--3>T\4;/0&r$   c                    |dvr|                      |           dS |dD ]}	 |                     |           t                              d|            dS # t          j        j        j        t          f$ r0}t                              d|z  |           d| _	        Y d}~d}~ww xY wt          d           |                     d	|z                          || _        dS )
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 J,LLL---LL!;TBBBEE.>
K , , , LL<tCa !   
 (,D$$$$$$, ##HIII7D!!+"677999 DKKKs   1A B'7&B""B'rl   )__name__
__module____qualname__r#   classmethodr/   staticmethodr6   rA   rL   rO   rS   ra   re   r_   rY   rm   rs   r    r$   r"   r   r   '   s          $ * * [* B B \B' ' ' F F 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 2 2 2 2 2 ) ) ) ) ) ) 1 1 1 1 1 1 6 6 6 6 6 6		.	/	/
RW'',,m<<"/ 
 ,#O4?A	 S! S! S! S! S! S! S! S! S! S!r$   