
    ;                     r   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rSSKJr  SSKJr  S rS rS rS rS rS rS r    S!S jr\R4                  R6                  4S jrS
\R4                  R6                  SS
S
4S jrS rS"S jrS r S r!S r"S"S jr#S r$S r%S  r&g
)#zLibrary for obtaining API clients and messages.

This should only be called by api_lib.util.apis, core.resources, gcloud meta
commands, and module tests.
    )absolute_import)division)unicode_literals)	apis_util)resource)
properties)	transport)apis_mapN)urljoin)urlparsec                 D    [         R                  R                  X 5      U 4$ N)r   _API_NAME_ALIASESget)api_names    0lib/googlecloudsdk/api_lib/util/apis_internal.py_GetApiNameAndAliasr   #   s    

%
%
)
)(
=x	HH    c                     [        U 5      u  p[        R                  R                  U 0 5      n[        R
                  " U5       H  u  p4UR                  (       d  M  Us  $    g r   )r   r
   MAPr   six	iteritemsdefault_version)r   _api_versverapi_defs        r   _GetDefaultVersionr   (   sO    #H-+(\\h+(mmH-lcj . 
r   c                  P    [        [        R                  R                  5       5      $ )z6Returns list of avaiblable apis, ignoring the version.)sortedr
   r   keys r   r   _GetApiNamesr#   1   s    	!!#	$$r   c                     [        U 5      u  p[        R                  R                  U S5      nUc  [        R
                  " U 5      e[        UR                  5       5      $ )zReturn available versions for given api.

Args:
  api_name: str, The API name (or the command surface name, if different).

Raises:
  apis_util.UnknownAPIError: If api_name does not exist in the APIs map.

Returns:
  list, of version names.
N)r   r
   r   r   r   UnknownAPIErrorlistr!   )r   r   version_maps      r   _GetVersionsr(   6   sQ     $H-+(  40+

#
#H
--	k 	!!r   c                    [        U 5      u  pU [        R                  ;  a  [        R                  " U 5      e[
        R                  R                  R                  5       nUR                  SR                  X5      5      nU(       d  UR                  US5      nU=(       d    Un[        R                  U    nUb  X;  a  [        R                  " X5      eXQ   nU$ )a  Returns the APIDef for the specified API and version.

Args:
  api_name: str, The API name (or the command surface name, if different).
  api_version: str, The version of the API.

Raises:
  apis_util.UnknownAPIError: If api_name does not exist in the APIs map.
  apis_util.UnknownVersionError: If api_version does not exist for given
    api_name in the APIs map.

Returns:
  APIDef, The APIDef for the specified API and version.
z{}/{}N)r   r
   r   r   r%   r   VALUESapi_client_overrides	AllValuesr   formatUnknownVersionError)r   api_versionapi_name_aliasversion_overridesversion_overrideapi_versionsr   s          r   	GetApiDefr4   I   s     1:(X\\!

#
#H
-- ''<<FFH '**7>>, 	(,,^TB /K+h',K;

'
'
>>'G	.r   c                 .    [        X5      n[        U5      $ )a  Returns the client class for the API specified in the args.

Args:
  api_name: str, The API name (or the command surface name, if different).
  api_version: str, The version of the API.

Returns:
  base_api.BaseApiClient, Client class for the specified API.
)r4   _GetClientClassFromDefr   r/   r   s      r   _GetClientClassr8   o   s     h,'		((r   c                     U R                   R                  nUR                  SS5      u  p#[        X#/S9n[	        XC5      $ )zReturns the apitools client class for the API definition specified in args.

Args:
  api_def: apis_map.APIDef, The definition of the API.

Returns:
  base_api.BaseApiClient, Client class for the specified API.
.   fromlist)apitoolsclient_full_classpathrsplit
__import__getattr)r   r?   module_pathclient_class_name
module_objs        r   r6   r6   }   sC     "**@@#8#?#?Q#G ++0CD*		//r   Fc                    U(       a  Ub   eO0Uc-  SSK Jn  UR                  [        R                  U(       a  UOSS9n[        X5      nU" [        XU5      SUS9nUb  XHl        [        R                  R                  R                  R                  5       n	U	(       a#  UR                  SU	5        Sn
S	UR                  U
'   U$ )
a1  Returns an instance of the API client specified in the args.

Args:
  api_name: str, The API name (or the command surface name, if different).
  api_version: str, The version of the API.
  no_http: bool, True to not create an http object for this client.
  http_client: bring your own http client to use. Incompatible with
    no_http=True.
  check_response_func: error handling callback to give to apitools.
  http_timeout_sec: int, seconds of http timeout to set, defaults if None.

Returns:
  base_api.BaseApiClient, An instance of the specified API client.
r   )
transportsunset)response_encodingtimeoutF)urlget_credentialshttpkeyzX-Google-Project-Overrideapikey)googlecloudsdk.core.credentialsrG   GetApitoolsTransportr	   ENCODINGr8   _GetEffectiveApiEndpointcheck_response_funcr   r*   coreapi_keyGetAddGlobalParamadditional_http_headers)r   r/   no_httphttp_clientrT   http_timeout_secrG   client_classclient_instancerV   headers              r   _GetClientInstancer`      s    ,  ;11#,,$4 ' 2 CK !7, 
"8,
G/ $*='""**..0'""5'2(F6>O++F3	r   c                 j   [        X5      nU[        R                  R                  :X  a  UR                  R
                  nOKU[        R                  R                  :X  a  UR                  R                  nOUR                  R                  nUR                  SS5      u  pV[        XV/S9n[        Xv5      $ )a  Returns the GAPIC client class for the API def specified by the args.

Args:
  api_name: str, The API name (or the command surface name, if different).
  api_version: str, The version of the API.
  transport_choice: apis_util.GapicTransport, The transport to be used by the
    client.
r:   r;   r<   )r4   r   GapicTransportGRPC_ASYNCIOgapicasync_client_full_classpathRESTrest_client_full_classpathr?   r@   rA   rB   )r   r/   transport_choicer   r?   rC   rD   rE   s           r   _GetGapicClientClassri      s     h,'11>>>#MMEE933888#MMDD#MM??#8#?#?Q#G ++0CD*		//r   c           	      R   ^ ^ UU 4S jn[        T XS9n	U	" UU[        T U5      UUUS9$ )a  Returns an instance of the GAPIC API client specified in the args.

For apitools API clients, the API endpoint override is something like
http://compute.googleapis.com/v1/. For GAPIC API clients, the DEFAULT_ENDPOINT
is something like compute.googleapis.com. To use the same endpoint override
property for both, we use the netloc of the API endpoint override.

Args:
  api_name: str, The API name (or the command surface name, if different).
  api_version: str, The version of the API.
  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.
  transport_choice: apis_util.GapicTransport, The transport to be used by the
    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:
  An instance of the specified GAPIC API client.
c                 "  >  [         R                  R                  R                  T5      R	                  5       nU(       a  [        U5      R                  n T(       a  T" U 5      n Ub  U $ [        U 5      $ ! [         R
                   a    S n NSf = fr   )	r   r*   api_endpoint_overridesPropertyrW   NoSuchPropertyErrorr   netlocUniversifyAddress)addressendpoint_overrideaddress_override_funcr   s     r   AddressOverride0_GetGapicClientInstance.<locals>.AddressOverride   s    $++BBKK
CE 
 *+22g%g.g$nW%% )) s   7A5 5BB)rh   )rs   mtls_enabledattempt_direct_pathredact_request_body_reasoncustom_interceptors)ri   _MtlsEnabled)
r   r/   credentialsrs   rh   rw   rx   ry   rt   r]   s
   `  `      r   _GetGapicClientInstancer|      sC    F&$ &@, 
++6-!;-
 r   c                     [         R                  R                  R                  nUR	                  5       nU b-  UR
                  U:w  a  U R                  UR
                  US5      n U $ )z2Update a URL based on the current universe domain.r;   )r   r*   rU   universe_domainrW   defaultreplace)rq   universe_domain_propertyr~   s      r   rp   rp     s]    '..33CC,002/&&/9oo6>>-q2G	.r   c                     [        X5      nUR                  (       a  U=(       d    [        X5      nOU=(       d    [        X5      nUR                  =(       d    UR
                  $ )zReturns mtls endpoint.)r4   r>   r8   ri   mtls_endpoint_overrideMTLS_BASE_URL)r   r/   r]   r   s       r   _GetMtlsEndpointr   !  sK    h,'I?8#ILN#7#NL		'	'	E<+E+EEr   c                    [         R                  R                  R                  R	                  5       (       a  g[         R                  R                  R
                  R	                  5       (       d  g[        X5      nUR                  $ )a  Checks if the API of the given version should use mTLS.

If context_aware/always_use_mtls_endpoint is True, then mTLS will always be
used.

If context_aware/use_client_certificate is True, then mTLS will be used only
if the API version is in the mTLS allowlist.

gcloud maintains a client-side allowlist for the mTLS feature
(go/gcloud-rollout-mtls).

Args:
  api_name: str, The API name.
  api_version: str, The version of the API.

Returns:
  True if the given service and version is in the mTLS allowlist.
TF)r   r*   context_awarealways_use_mtls_endpointGetBooluse_client_certificater4   enable_mtlsr7   s      r   rz   rz   +  sb    & $$==EEGG				(	(	?	?	G	G	I	Ih,'			r   c                     [        U5      n[        U 5      nUR                  S:X  d  UR                  S:w  a  U $ [        SR                  UR                  UR
                  5      UR                  5      $ )zFConstructs a normalized endpoint URI depending on the client base_url./z{}://{})r   pathr   r-   schemero   )rr   base_urlurl_baseurl_endpoint_overrides       r   _BuildEndpointOverrider   H  sn    h("#45]]c2773>	,33,3356>mm
E Er   c                 $   [        X5      R                  (       a  [        X5      nO[        X5      n[	        US5      (       a  UR
                  nO [        X5      R
                  n[        U5      $ ! [         a    SR                  X5      n N(f = f)zReturns base url for given api.BASE_URLzhttps://{}.googleapis.com/{})
r4   r>   r8   ri   hasattrr   _GetResourceModuleAttributeErrorr-   rp   )r   r/   r]   client_base_urls       r   _GetBaseUrlFromApir   S  s    x%.."89L'>L\:&&"++O*8AJJo
 
?	++	  6==
os   A1 1BBc                     [         R                  R                  R                  U 5      R	                  5       n[        X5      nUR                  (       a  U=(       d    [        X5      nOU=(       d    [        X5      n[        X5      nU(       a  [        X55      nU$ [        X5      (       a  [        [        XU5      5      nU$ UnU$ ! [         R
                   a    Sn Nf = f)z)Returns effective endpoint for given api.N)r   r*   rl   rm   rW   rn   r4   r>   r8   ri   r   r   rz   rp   r   )r   r/   r]   rr   r   r   rq   s          r   rS   rS   f  s    "))@@II#% 
 h,'I?8#ILN#7#NL&x=/$%6HG 
. H**=G 
. G	.% 
	'	' s   7C C! C!c                 V    [        X5      n[        UR                  R                  S/S9$ )a  Returns the messages module for the API specified in the args.

Args:
  api_name: str, The API name (or the command surface name, if different).
  api_version: str, The version of the API.

Returns:
  Module containing the definitions of messages for the specified API.
	somethingr<   )r4   rA   r>   messages_full_modulepathr7   s      r   _GetMessagesModuler     s2     h,' 
//;-
I Ir   c                     [        X5      nUR                  (       a%  [        UR                  R                  S-   S-   S/S9$ [        UR                  R                  S-   S-   S/S9$ )z/Imports and returns given api resources module.r:   	resourcesr   r<   )r4   r>   rA   
class_pathrd   r7   s      r   r   r     sm     h,' ##c)K7;-  
mm${2k]
 r   c              #   6  #     [        X5      nUR                   Hi  n[        R                  " U UUR                  UR
                  UR                  UR                  UR                  UR                  UR                  5	      v   Mk     g! [         a     gf = f7f)z)Yields all collections for for given api.N)r   Collectionsresource_utilCollectionInfor   DOCS_URLcollection_namer   
flat_pathsparamsenable_uri_parsingImportError)r   r/   resources_module
collections       r   _GetApiCollectionsr     s     )(@ '22
((



#
#

#
#

$
$
//







'
'
 
 3 
 		s(   BB	 A:B	
BBBB)FNNNr   )'__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   r   googlecloudsdk.corer   r	   %googlecloudsdk.generated_clients.apisr
   r   six.moves.urllib.parser   r   r   r   r#   r(   r4   r8   r6   r`   rb   GRPCri   r|   rp   r   rz   r   r   rS   r   r   r   r"   r   r   <module>r      s    '  ' 1 A * ) : 
 * +I
%
"&#L)0"  %#'+/(,-d +4*B*B*G*G08 --22#?DF:E,&4I" r   