
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSK	Jr  SS	KJr  SS
KJr   " S S\
R                  5      r  SS jr  S SS jjr  SS jr     SS jr   SS jrg)z1Helper Classes for using gapic clients in gcloud.    )absolute_import)annotations)division)unicode_literals)external_account)
exceptions)requests)creds)storec                      \ rS rSrSrSrg)MissingStoredCredentialsError   z?Indicates stored credentials do not exist or are not available. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       %lib/googlecloudsdk/core/gapic_util.pyr   r      s    Gr   r   c                   ^^ [         R                  " USS9m[        R                  " T5      (       d  [	        S5      eU (       a  [        R
                  " T5      Tl        TR                  mUU4S jnUTl        T$ )a  Returns a credential object for use by gapic client libraries.

Currently, we set _quota_project on the credentials, unlike for http requests,
which add quota project through request wrapping to implement
go/gcloud-quota-model-v2.

Additionally, we wrap the refresh method and plug in our own
google.auth.transport.Request object that uses our transport.

Args:
  enable_resource_quota: bool, By default, we are going to tell APIs to use
      the quota of the project being operated on. For some APIs we want to use
      gcloud's quota, so you can explicitly disable that behavior by passing
      False here.
  allow_account_impersonation: bool, True to allow use of impersonated service
      account credentials for calls made with this client. If False, the
      active user credentials will always be used.

Returns:
  A google auth credentials.Credentials object.

Raises:
  MissingStoredCredentialsError: If a google-auth credential cannot be loaded.
T)allow_account_impersonationuse_google_authzUnable to load credentialsc                   > A [        T[        R                  5      (       a  TR                  (       a  g T" [        R
                  " 5       5      $ )N)
isinstancegoogle_auth_external_accountCredentialsvalidr	   GoogleAuthRequest)requestcredentialsoriginal_refreshs    r   WrappedRefresh+GetGapicCredentials.<locals>.WrappedRefreshJ   sA     $002 26A6G6GH66899r   )r   LoadIfEnabledr
   IsGoogleAuthCredentialsr   GetQuotaProject_quota_project_idrefresh)enable_resource_quotar   r$   r"   r#   s      @@r   GetGapicCredentialsr,   !   ss    6 ##"=+ 
	&	&{	3	3
'(D
EE$)$9$9+$FK!
 !((: '+	r   Nc                .    SSK Jn  UR                  XX#S9$ )a  Initializes a BidiRpc instances.

Args:
    client: GAPIC Wrapper client to use.
    start_rpc (grpc.StreamStreamMultiCallable): The gRPC method used to start
      the RPC.
    initial_request: The initial request to yield. This is useful if an
      initial request is needed to start the stream.
    metadata: The metadata headers to use for the RPC. It is a list of tuples.
      The first string in the tuple is the header name and the second is the
      header value.

Returns:
  A bidiRPC instance.
r   gapic_util_internal)initial_requestmetadata)googlecloudsdk.corer/   BidiRpc)client	start_rpcr0   r1   r/   s        r   MakeBidiRpcr6   X   s$    , 6		$	$ 
% 
 r   c                    U R                  S5      nU(       a  U R                  OU R                  nU(       a  U" U5      nU " U" XQS9S9$ )a  Instantiates a gapic REST client with gcloud defaults and configuration.

Args:
  client_class: a gapic client class.
  credentials: google.auth.credentials.Credentials, the credentials to use.
  address_override_func: function, function to call to override the client
    host. It takes a single argument which is the original host.
  mtls_enabled: bool, True if mTLS is enabled for this client. _

Returns:
  A gapic API client.
rest)hostr"   	transport)get_transport_classDEFAULT_MTLS_ENDPOINTDEFAULT_ENDPOINT)client_classr"   address_override_funcmtls_enabledtransport_classaddresss         r   MakeRestClientrD   u   sM      !44V</2>L..LDaDa'#G,G	WF
H Hr   c                @    SSK Jn  U " UR                  U UUUUUUS9S9$ )a  Instantiates a gapic API client with gcloud defaults and configuration.

grpc cannot be packaged like our other Python dependencies, due to platform
differences and must be installed by the user. googlecloudsdk.core.gapic
depends on grpc and must be imported lazily here so that this module can be
imported safely anywhere.

Args:
  client_class: a gapic client class.
  credentials: google.auth.credentials.Credentials, the credentials to use.
  address_override_func: function, function to call to override the client
    host. It takes a single argument which is the original host.
  mtls_enabled: bool, True if mTLS is enabled for this client.
  attempt_direct_path: bool, True if we want to attempt direct path gRPC where
    possible
  redact_request_body_reason: str, the reason why the request body must be
    redacted if --log-http is used. If None, the body is not redacted.
  custom_interceptors: list[grpc interceptor], a list of custom
    interceptors to add to the channel.

Returns:
  A gapic API client.
r   r.   )custom_interceptorsr:   )r2   r/   MakeTransport)r?   r"   r@   rA   attempt_direct_pathredact_request_body_reasonrF   r/   s           r   
MakeClientrJ      s=    B 6	#11





$1 2 

 
r   c           	     @    SSK Jn  U " UR                  U UUUU5      S9$ )a  Instantiates a gapic API client with gcloud defaults and configuration.

grpc cannot be packaged like our other Python dependencies, due to platform
differences and must be installed by the user. googlecloudsdk.core.gapic
depends on grpc and must be imported lazily here so that this module can be
imported safely anywhere.

Args:
  client_class: a gapic client class.
  credentials: google.auth.credentials.Credentials, the credentials to use.
  address_override_func: function, function to call to override the client
    host. It takes a single argument which is the original host.
  mtls_enabled: bool, True if mTLS is enabled for this client.
  attempt_direct_path: bool, True if we want to attempt direct path gRPC where
    possible

Returns:
  A gapic API client.
r   r.   r:   )r2   r/   MakeAsyncTransport)r?   r"   r@   rA   rH   r/   s         r   MakeAsyncClientrM      s1    6 6	#66





 r   )TT)NN)r1   zlist[tuple[str, str]] | None)NF)NFFNN)NFF)r   
__future__r   r   r   r   google.authr   r   r2   r   r	   googlecloudsdk.core.credentialsr
   r   Errorr   r,   r6   rD   rJ   rM   r   r   r   <module>rR      s    8 & "  ' H * ( 1 1HJ$4$4 H /3484t -1	 +	> *. %H6 #-f %r   