
    gC                         d 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	Z	ddl
mZ ddl
mZ ddl
mZ dZdZd	Zd
ZdZdZ G d dej(                        Zy# e$ r	 ddlmZ Y Uw xY w)a  Pluggable Credentials.
Pluggable Credentials are initialized using external_account arguments which
are typically loaded from third-party executables. Unlike other
credentials that can be initialized with a list of explicit arguments, secrets
or credentials, external account clients use the environment and hints/guidelines
provided by the external_account JSON file to retrieve credentials and exchange
them for Google access tokens.

Example credential_source for pluggable credential:
{
    "executable": {
        "command": "/path/to/get/credentials.sh --arg1=value1 --arg2=value2",
        "timeout_millis": 5000,
        "output_file": "/path/to/generated/cached/credentials"
    }
}
    )MappingN)_helpers)
exceptions)external_account   i0u  i  i i@w c                        e Zd ZdZ fdZ ej                  ej                        d        Z	d Z
ed        Ze fd       Ze fd       Zd Zd	 Zd
 Zd Zd Z fdZ xZS )Credentialsz6External account credentials sourced from executables.c                    |j                  dd      | _        t        t        |   |||||d| t        |t              sd| _        t        j                  d      |j                  d      | _        | j                  st        j                  d      | j                  j                  d      | _        | j                  j                  d	      | _        | j                  j                  d
      | _        | j                  j                  d      | _        d| _        | j                  st        j                  d      | j                  st         | _        n;| j                  t"        k  s| j                  t$        kD  rt        j&                  d      | j                  r<| j                  t(        k  s| j                  t*        kD  rt        j&                  d      yy)ad  Instantiates an external account credentials object from a executables.

        Args:
            audience (str): The STS audience field.
            subject_token_type (str): The subject token type.
            token_url (str): The STS endpoint URL.
            credential_source (Mapping): The credential source dictionary used to
                provide instructions on how to retrieve external credential to be
                exchanged for Google access tokens.

                Example credential_source for pluggable credential:

                    {
                        "executable": {
                            "command": "/path/to/get/credentials.sh --arg1=value1 --arg2=value2",
                            "timeout_millis": 5000,
                            "output_file": "/path/to/generated/cached/credentials"
                        }
                    }
            args (List): Optional positional arguments passed into the underlying :meth:`~external_account.Credentials.__init__` method.
            kwargs (Mapping): Optional keyword arguments passed into the underlying :meth:`~external_account.Credentials.__init__` method.

        Raises:
            google.auth.exceptions.RefreshError: If an error is encountered during
                access token retrieval logic.
            google.auth.exceptions.InvalidValue: For invalid parameters.
            google.auth.exceptions.MalformedError: For invalid parameters.

        .. note:: Typically one of the helper constructors
            :meth:`from_file` or
            :meth:`from_info` are used instead of calling the constructor directly.
        interactiveF)audiencesubject_token_type	token_urlcredential_sourceNz?Missing credential_source. The credential_source is not a dict.
executablez<Missing credential_source. An 'executable' must be provided.commandtimeout_millisinteractive_timeout_millisoutput_file z;Missing command field. Executable command must be provided.z*Timeout must be between 5 and 120 seconds.z>Interactive timeout must be between 30 seconds and 30 minutes.)popr   superr	   __init__
isinstancer   _credential_source_executabler   MalformedErrorget%_credential_source_executable_command,_credential_source_executable_timeout_millis8_credential_source_executable_interactive_timeout_millis)_credential_source_executable_output_file_tokeninfo_username!EXECUTABLE_TIMEOUT_MILLIS_DEFAULT%EXECUTABLE_TIMEOUT_MILLIS_LOWER_BOUND%EXECUTABLE_TIMEOUT_MILLIS_UPPER_BOUNDInvalidValue1EXECUTABLE_INTERACTIVE_TIMEOUT_MILLIS_LOWER_BOUND1EXECUTABLE_INTERACTIVE_TIMEOUT_MILLIS_UPPER_BOUND)selfr   r   r   r   argskwargs	__class__s          r/var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/google/auth/pluggable.pyr   zCredentials.__init__>   s   T "::mU;k4)
 	 1/		
 	
 +W515D.++Q  .?-B-B<-P*11++N  6:5W5W5[5[6
2 =A<^<^<b<b=
9 IMHjHjHnHn(I
E :>9[9[9_9_:
6
 $& 99++M  @@1 = ==34@@34 ))*VWWHHMMCDPPCD !--T D	 I    c                    | j                          | j                  _	 t        | j                  d      5 }t        j                  |      }d d d        	 | j                        }d|vrt        j                  	 |S t        j                         st        j                  d      t        j                  j                         }| j!                  |       d|d<   | j"                  r| j$                  dz  n| j&                  dz  }| j"                  rt(        j*                  nd }| j"                  rt(        j,                  nt.        j0                  }| j"                  rt(        j,                  nt.        j2                  }	t/        j4                  | j6                  j9                         ||||	|      }
|
j:                  d	k7  r9t        j                  d
j=                  |
j:                  |
j,                              |
j,                  r.t        j>                  |
j,                  jA                  d            nd }|s6| j                  *t        j                  t        | j                  d            }| j                  |      }|S # 1 sw Y   2xY w# t        j                  t        j                  f$ r  t        j                  $ r Y Ew xY w# t        $ r Y Uw xY w)Nutf-8)encodingexpiration_time0Pluggable auth is only supported for python 3.7+0GOOGLE_EXTERNAL_ACCOUNT_REVOKE  )timeoutstdinstdoutstderrenvr   z9Executable exited with non-zero return code {}. Error: {})!_validate_running_moder    openjsonload_parse_subject_tokenr   RefreshErrorr   r%   	Exceptionr   is_python_3osenvironcopy_inject_env_variablesr   r   r   sysr7   r8   
subprocessPIPESTDOUTrunr   split
returncodeformatloadsdecode)r(   requestr   responsesubject_tokenr:   exe_timeout	exe_stdin
exe_stdout
exe_stderrresults              r,   retrieve_subject_tokenz"Credentials.retrieve_subject_token   sv   ##% 99E)BBW 6 #yy5H6)$($=$=h$GM)9(555 : )(##%))B 
 jjoo""3'03,-
  IIDPBBTI 	
 "&!1!1CIIt	#'#3#3SZZ
#'#3#3SZZ9J9J
66<<>
 !))KRR%%v}}  AG4::fmm227;<SWDJJVyyTCCgVH 11(;A6 6 #11:3J3JK !..   s:   K I;K %J ;J K 6KK	KKc                    | j                   st        j                  d      | j                          t	        j
                         st        j                  d      t        j                  j                         }| j                  |       d|d<   t        j                  | j                  j                         | j                  dz  t        j                   t        j"                  |      }|j$                  dk7  r9t        j                  dj'                  |j$                  |j(                              t+        j,                  |j(                  j/                  d	            }| j1                  |       y
)aG  Revokes the subject token using the credential_source object.

        Args:
            request (google.auth.transport.Request): A callable used to make
                HTTP requests.
        Raises:
            google.auth.exceptions.RefreshError: If the executable revocation
                not properly executed.

        z.Revoke is only enabled under interactive mode.r2   1r4   r5   )r6   r8   r9   r:   r   zNAuth revoke failed on executable. Exit with non-zero return code {}. Error: {}r/   N)r   r   r%   r;   r   rB   r@   rC   rD   rE   rF   rH   rK   r   rL   r   rI   rJ   rM   rN   r8   r=   rO   rP   _validate_revoke_response)r(   rQ   r:   rX   rR   s        r,   revokezCredentials.revoke   s1    ))@  	##%##%))B 
 jjoo""3'03,- 66<<>QQ??$$
 !))`gg%%v}}  ::fmm227;<&&x0r-   c                 6    | j                   xs | j                  S )a1  Returns the external account identifier.

        When service account impersonation is used the identifier is the service
        account email.

        Without service account impersonation, this returns None, unless it is
        being used by the Google Cloud CLI which populates this field.
        )service_account_emailr!   )r(   s    r,   external_account_idzCredentials.external_account_id  s     ))ET-E-EEr-   c                 ,    t        t        | 
  |fi |S )a'  Creates a Pluggable Credentials instance from parsed external account info.

        Args:
            info (Mapping[str, str]): The Pluggable external account info in Google
                format.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.pluggable.Credentials: The constructed
                credentials.

        Raises:
            google.auth.exceptions.InvalidValue: For invalid parameters.
            google.auth.exceptions.MalformedError: For invalid parameters.
        )r   r	   	from_info)clsinfor*   r+   s      r,   rb   zCredentials.from_info+  s    " [#0@@@r-   c                 ,    t        t        | 
  |fi |S )aj  Creates an Pluggable Credentials instance from an external account json file.

        Args:
            filename (str): The path to the Pluggable external account json file.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.pluggable.Credentials: The constructed
                credentials.
        )r   r	   	from_file)rc   filenamer*   r+   s      r,   rf   zCredentials.from_file>  s     [#0DVDDr-   c                     | j                   |d<   | j                  |d<   | j                  |d<   | j                  rdnd|d<   | j                  | j
                  |d<   | j                  | j                  |d<   y y )	N GOOGLE_EXTERNAL_ACCOUNT_AUDIENCE"GOOGLE_EXTERNAL_ACCOUNT_TOKEN_TYPEGOOGLE_EXTERNAL_ACCOUNT_IDr[   r3   #GOOGLE_EXTERNAL_ACCOUNT_INTERACTIVE*GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL#GOOGLE_EXTERNAL_ACCOUNT_OUTPUT_FILE)	_audience_subject_token_typer`   r   "_service_account_impersonation_urlr_   r    )r(   r:   s     r,   rF   z!Credentials._inject_env_variablesL  s    26.../484L4L01,0,D,D()<@<L<LSRU1222> ** < 99E >> 5 Fr-   c                    | j                  |       |d   sHd|vsd|vrt        j                  d      t        j                  dj	                  |d   |d               d|v r/|d   t        j
                         k  rt        j                  d      d|vrt        j                  d	      |d   d
k(  s|d   dk(  r|d   S |d   dk(  r|d   S t        j                  d      )Nsuccesscodemessagez;Error code and message fields are required in the response.zAExecutable returned unsuccessful response: code: {}, message: {}.r1   z0The token returned by the executable is expired.
token_typez8The executable response is missing the token_type field.z$urn:ietf:params:oauth:token-type:jwtz)urn:ietf:params:oauth:token-type:id_tokenid_tokenz&urn:ietf:params:oauth:token-type:saml2saml_responsez+Executable returned unsupported token type.)_validate_response_schemar   r   r@   rN   timer(   rR   s     r,   r?   z Credentials._parse_subject_token[  s   &&x0	"X%()B //Q  ))SZZV$hy&9 
 (X6G-H499;-V))B  x'++J  \"&LL%)TTJ''l#'OOO,,))*WXXr-   c                 Z    | j                  |       |d   st        j                  d      y )Nrs   z)Revoke failed with unsuccessful response.)ry   r   r@   r{   s     r,   r\   z%Credentials._validate_revoke_responsey  s/    &&x0	"))*UVV #r-   c                     d|vrt        j                  d      |d   t        kD  r't        j                  dj	                  |d               d|vrt        j                  d      y )Nversionz5The executable response is missing the version field.z+Executable returned unsupported version {}.rs   z5The executable response is missing the success field.)r   r    EXECUTABLE_SUPPORTED_MAX_VERSIONr@   rN   r{   s     r,   ry   z%Credentials._validate_response_schema~  s~    H$++G  I!AA))=DDY'  H$++G  %r-   c                    t         j                  j                  d      }|dk7  rt        j                  d      | j
                  r!| j                  st        j                  d      | j
                  r!| j                  st        j                  d      | j
                  r"| j                  st        j                  d      y y )N)GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLESr[   zhExecutables need to be explicitly allowed (set GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES to '1') to run.zVAn output_file must be specified in the credential configuration for interactive mode.z;Interactive mode cannot run without an interactive timeout.z4Interactive mode is only enabled for workforce pool.)rC   rD   r   r   r   r   r    r   InvalidOperationis_workforce_poolr%   )r(   env_allow_executabless     r,   r;   z"Credentials._validate_running_mode  s     "

7!
 !C'++z  D$R$R++h 
 QQ--M  D$:$:))F  %;r-   c                 6    t         t        |          }d|d<   |S )Nr   source)r   r	   _create_default_metrics_options)r(   metrics_optionsr+   s     r,   r   z+Credentials._create_default_metrics_options  s"    TRT$0!r-   )__name__
__module____qualname____doc__r   r   copy_docstringr   r	   rY   r]   propertyr`   classmethodrb   rf   rF   r?   r\   ry   r;   r   __classcell__)r+   s   @r,   r	   r	   ;   s    @fP X-99:F ;FP-1^ 
F 
F A A$ E E?Y<W
"6 r-   r	   )r   collections.abcr   ImportErrorcollectionsr=   rC   rH   rG   rz   google.authr   r   r   r   r"   r#   r$   r&   r'   r	    r-   r,   <module>r      s{   $$'  	  
    " ( $%  $- !(0 %(2 %4= 14B 1r".. r/  $#$s   A A A 