;iHdZ ddlmZn#e$r ddlmZYnwxYwddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl m Z dZdZd Zd ZdZd ZGd d e jZdS)aPluggable 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_accounti0uiii@wceZdZdZfdZejejdZ dZ e dZ e fdZe fdZdZd Zd Zd Zd Zfd ZxZS) CredentialsaExternal account credentials sourced from executables. **IMPORTANT**: This class does not validate the credential configuration. A security risk occurs when a credential configuration configured with malicious urls is used. When the credential configuration is accepted from an untrusted source, you should validate it before using. Refer https://cloud.google.com/docs/authentication/external/externally-sourced-credentials for more details.c|dd|_tt|j|||||d|t |t sd|_tj d| d|_|jstj d|j d|_ |j d |_ |j d |_ |j d |_d |_|j stj d |j s t |_ n4|j t"ks|j t$krtjd|j r4|j t(ks|j t*krtjddSdS)adInstantiates 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)audiencesubject_token_type token_urlcredential_sourceNz?Missing credential_source. The credential_source is not a dict. executablezInteractive timeout must be between 30 seconds and 30 minutes.)popr superr __init__ isinstancer_credential_source_executablerMalformedErrorget%_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 rrargskwargs __class__s IC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\google/auth/pluggable.pyrzCredentials.__init__Fs>T"::mU;;)k4  )  1/       +W55 15D .+Q .?-B-B<-P-P*1 +N 6:5W5[5[ 6 6 2=A<^9[9_9_ : : 6 $& 9 +M @ X1  = =  =3 4 4@344)*VWW W  H MCDDPCDD!-T  DDc||j t|jd5}tj|}dddn #1swxYwY ||}d|vr t j |S#t jt j f$rt j$rYnwxYw#t$rYnwxYwtj st jdtj}||d|d<|jr |jdz n |jdz }|jr t(jnd}|jr t(jn t.j}|jr t(jn t.j} t/j|j|||| |} | jd kr2t jd | j| j| jr,tj| j dnd}|s/|j(tjt|jd}||}|S) Nutf-8)encodingexpiration_time0Pluggable auth is only supported for python 3.7+0GOOGLE_EXTERNAL_ACCOUNT_REVOKE)timeoutstdinstdoutstderrenvrz9Executable exited with non-zero return code {}. Error: {})!_validate_running_moder openjsonload_parse_subject_tokenr RefreshErrorrr% Exceptionr is_python_3osenvironcopy_inject_env_variablesr rrsysr7r8 subprocessPIPESTDOUTrunrsplit returncodeformatloadsdecode) r(requestrresponse subject_tokenr: exe_timeout exe_stdin exe_stdout exe_stderrresults r,retrieve_subject_tokenz"Credentials.retrieve_subject_tokens ##%%%  9 E )BW6 #y55H666666666666666 )$($=$=h$G$GM)99(55:)( #1:3JK!.D    "#%% )B  joo ""3'''03 ,-  JD ID P PBTI  "&!1;CIIt #'#3HSZZ #'#3JSZZ9J   6 < < > >       ! !)KRR%v} AG W4:fm227;;<< >Q?$       ! !)`gg%v}  :fm227;;<< &&x00000r-c|jp|jS)a1Returns 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_idzCredentials.external_account_id&s)ET-EEr-c Ftt|j|fi|S)aCreates a Pluggable Credentials instance from parsed external account info. **IMPORTANT**: This method does not validate the credential configuration. A security risk occurs when a credential configuration configured with malicious urls is used. When the credential configuration is accepted from an untrusted source, you should validate it before using with this method. Refer https://cloud.google.com/docs/authentication/external/externally-sourced-credentials for more details. 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. )rr from_info)clsinfor*r+s r,rbzCredentials.from_info3s*21u[#&&0@@@@@r-c Ftt|j|fi|S)a8Creates an Pluggable Credentials instance from an external account json file. **IMPORTANT**: This method does not validate the credential configuration. A security risk occurs when a credential configuration configured with malicious urls is used. When the credential configuration is accepted from an untrusted source, you should validate it before using with this method. Refer https://cloud.google.com/docs/authentication/external/externally-sourced-credentials for more details. 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. )rr from_file)rcfilenamer*r+s r,rfzCredentials.from_fileNs*(1u[#&&0DDVDDDr-c|j|d<|j|d<|j|d<|jrdnd|d<|j |j|d<|j |j|d<dSdS) N GOOGLE_EXTERNAL_ACCOUNT_AUDIENCE"GOOGLE_EXTERNAL_ACCOUNT_TOKEN_TYPEGOOGLE_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,rFz!Credentials._inject_env_variablesds26. ./484L 01,0,D ()<@* <   9 E> 5    F Er-c|||dsPd|vsd|vrtjdtjd|d|dd|vr1|dt jkrtjdd|vrtjd |dd ks |dd kr|d S|dd kr|dStjd)Nsuccesscodemessagez;Error code and message fields are required in the response.zAExecutable returned unsuccessful response: code: {}, message: {}.r1z0The 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_tokenid_tokenz&urn:ietf:params:oauth:token-type:saml2 saml_responsez+Executable returned unsupported token type.)_validate_response_schemarrr@rNtimer(rRs r,r?z Credentials._parse_subject_tokenssF &&x000 " X%%()B)B /Q)SZZV$hy&9   ( (X6G-H49;;-V-V)B  x ' '+J  \ "&L L L %)TTTJ' ' l #'O O OO, ,)*WXX Xr-ch|||dstjddS)Nrsz)Revoke failed with unsuccessful response.)ryrr@r{s r,r\z%Credentials._validate_revoke_responsesB &&x000 " W)*UVV V W Wr-cd|vrtjd|dtkr-tjd|dd|vrtjddS)Nversionz5The executable response is missing the version field.z+Executable returned unsupported version {}.rsz5The executable response is missing the success field.)rr EXECUTABLE_SUPPORTED_MAX_VERSIONr@rNr{s r,ryz%Credentials._validate_response_schemas H $ $+G  I !A A A)=DDY'  H $ $+G  % $r-cHtjd}|dkrtjd|jr|jstjd|jr|jstjd|jr|j stj ddSdS)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.) rCrDrrrr r rInvalidOperationis_workforce_poolr%)r(env_allow_executabless r,r;z"Credentials._validate_running_modes "  7! !  !C ' '+z    D$R +h    Q -M    D$: )F     r-c`tt|}d|d<|S)Nrsource)rr _create_default_metrics_options)r(metrics_optionsr+s r,rz+Credentials._create_default_metrics_optionss. T22RRTT$0!r-)__name__ __module__ __qualname____doc__rrcopy_docstringrr rYr]propertyr` classmethodrbrfrFr?r\ryr;r __classcell__)r+s@r,r r ;sgttfffffPX-9::FF;:FP-1-1-1^ F FX FAAAA[A4EEEE[E* ? ? ?YYY<WWW "6r-r )rcollections.abcr ImportError collectionsr=rCrHrGrz google.authrrrrr"r#r$r&r'r r-r,rs*$$'''''''$$$########$  """"""(((((($% $-!(0%(2%4=14B1JJJJJ".JJJJJs