
    %                        S r SSKrSSK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KJr  \R,                  r\	R.                  R0                  S\	R.                  R2                  S\	R.                  R4                  S0r " S S\R8                  5      r\	R.                  R0                  4S jr\	R.                  R0                  4S jrS r S r!S r"S r#S r$S r%S r&S r'S r(S r)S r*S r+S r,S S jr-g)!z/A library that is used to support our commands.    N)parse)apis)arg_parsers)base)	arg_utils)
exceptions)
properties)	resources)requests)http_clientv1c                       \ rS rSrSrSrg)HttpRequestFailError)   z2Indicates that the http request fails in some way. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       *lib/googlecloudsdk/api_lib/biglake/util.pyr   r   )   s    :r   r   c                 Z    [         R                  U 5      n[        R                  " SU5      $ Nbiglake)VERSION_MAPgetr   GetMessagesModulerelease_trackapi_versions     r   r   r   0   #    .+				;	77r   c                 Z    [         R                  U 5      n[        R                  " SU5      $ r   )r   r   r   GetClientInstancer    s     r   r%   r%   5   r#   r   c                     [         R                  R                  U S[        R                  R
                  R                  R                  0SS9$ )z&Get a resource reference to a catalog.
projectsIdz;biglake.iceberg.v1.restcatalog.extensions.projects.catalogs)params
collection)r
   REGISTRYParser	   VALUEScoreproject	GetOrFail)catalogs    r   GetCatalogRefr1   :   sK    				!	!

))..66@@ O 
" 
 r   c                 x    S[         R                  R                  R                  R	                  5        SU  SU 3$ )znGet the namespace name in the format of projects/{project-id}/catalogs/{catalog-id}/namespaces/{namespace-id}.	projects/
/catalogs//namespaces/r	   r,   r-   r.   r/   )
catalog_idnamespace_ids     r   GetNamespaceNamer9   E   s:    Z&&++33==?@
:,Vbcobp	qqr   c                 r    S[         R                  R                  R                  R	                  5        SU  3$ )zRGet the catalog name in the format of projects/{project-id}/catalogs/{catalog-id}.r3   r4   r6   )r7   s    r   GetCatalogNamer;   J   s1    Z&&++33==?@
:,	WWr   c                 ~    S[         R                  R                  R                  R	                  5        SU  SU SU 3$ )a$  Get the table name.

The name is in the format of
projects/{project-id}/catalogs/{catalog-id}/namespaces/{namespace-id}/tables/{table-id}.

Args:
  catalog_id: The ID of the catalog.
  namespace_id: The ID of the namespace.
  table_id: The ID of the table.

Returns:
  The table name string.
r3   r4   r5   z/tables/r6   )r7   r8   table_ids      r   GetTableNamer>   O   sS     Z&&++33==?@
:,Vbcobppx  zB  yC  
D  Dr   c                  l    S[         R                  R                  R                  R	                  5        3$ )z;Get the parent name in the format of projects/{project-id}.r3   r6   r   r   r   GetParentNamer@   `   s+    Z&&++33==?@	AAr   c           
      ~    [        U 5      nUR                  R                  n[        R                  " SUS/SSSSS.S9$ )	N--catalog-typer   Tz(Catalog type to create the catalog with.)z
gcs-bucketz+A catalog backed by a Cloud Storage bucket.r   zBigLake Iceberg catalog. Catalog type which allows namespaces and tables within a catalog to be mapped to locations beyond the catalog's designated default.)CATALOG_TYPE_GCS_BUCKETCATALOG_TYPE_BIGLAKE)hidden_choicesrequiredhelp_strcustom_mappingsr   IcebergCatalogCatalogTypeValueValuesEnumr   ChoiceEnumMapperr!   messagescatalog_type_enums      r   GetCatalogTypeEnumMapperrQ   e   sQ    }-(--HH		#	#[9&#
 r   c           	      z    [        U 5      nUR                  R                  n[        R                  " SUSSSSS0S9$ )NrB   TFzhCatalog type to update the catalog with. Currently only updating to a BigLake catalog type is supported.rE   rC   )hiddenrG   rH   rI   rJ   rN   s      r   GetUpdateCatalogTypeEnumMapperrT      sQ    }-(--HH		#	#1 ! #	
 r   c           	      z    [        U 5      nUR                  R                  n[        R                  " SUSSSSS.S9$ )Nz--credential-modeend-userz+Credential mode to create the catalog with.)rV   z/Use end user credentials to access the catalog.)zvended-credentialsz-Use vended credentials to access the catalog.)CREDENTIAL_MODE_END_USER"CREDENTIAL_MODE_VENDED_CREDENTIALS)defaultrH   rI   )r   rK   CredentialModeValueValuesEnumr   rM   )r!   rO   credential_mode_enums      r   GetCredentialModeEnumMapperr\      sL    }-(!00NN		#	#<'1	
 r   c                 ^    U R                  S5      (       d  [        R                  " S5      eU $ )Nzgs://zALocation must be a Google Cloud Storage URI starting with `gs://`)
startswithr   ArgumentTypeError)values    r   GcsBucketLinkValidatorra      s0    			'	"	"

'
'K  
,r   c                 0    U R                  SS[        SS9  g )Nz--default-locationTzqCan only be used with BigLake catalogs. The default storage location for the catalog, e.g., `gs://my-bucket/...`.)rS   typehelp)add_argumentra   parsers    r   AddDefaultLocationArgrh      s$    !K  r   c                 V    U R                  SS[        R                  " [        S9SSS9  g )Nz--additional-locationsT)element_typeLOCATIONzCan only be used with BigLake catalogs. Additional Google Cloud Storage buckets and locations (e.g., `gs://my-other-bucket/...`) that are permitted for use by resources within a catalog.)rS   rc   metavarrd   )re   r   ArgListra   rf   s    r   AddAdditionalLocationsArgrn      s2    ,BC)  r   c                 n   U R                   S:X  a,  U R                  S5      (       d  [        R                  " S5      eU R                   S:w  a,  U R                  S5      (       a  [        R                  " S5      eU R                   S:w  a-  U R                  S5      (       a  [        R                  " S5      egg)a'  Checks for valid combinations of arguments.

Ensures that `--default-location` and `--additional-locations`
are only used when `--catalog-type` is 'BigLake'.

Args:
  args: The parsed command-line arguments.

Raises:
  arg_parsers.ArgumentTypeError: If an invalid argument combination is found.
r   default_locationzB--default-location must be specified when catalog type is BigLake.z:--default-location is only supported for BigLake catalogs.additional_locationsz>--additional-locations is only supported for BigLake catalogs.N)catalog_typeIsSpecifiedr   r_   )argss    r   CheckValidArgCombinationsru      s     
)#D,<,<- - 
'
'L  I%$*:*:+ + 
'
'D  I%$*:*:+ + 
'
'H +%r   c                     / nU(       aK  SU;   aE  US    H<  nSR                  U5      nUR                  [        R                  " U  SU 3S95        M>     UR	                  SS5      nUR	                  S/ 5      nX%U4$ )z8Processes the response from the list namespaces request.
namespaces.r5   )nameznext-page-tokenNunreachable)joinappendtypesSimpleNamespacer   )parent_nameresponserw   ns_partsns_id
page_tokenrz   s          r   ProcessNamespaceListResponser      s    *,(*\*hhx e


!],ug6 + ||-t4*]B/+		,,r   c                 $   [         R                  " SS5      R                  S5      nU SU  S3nU(       a  USU 3-  nU(       a  US[        U5       3-  nSS	0n[        R
                  " 5       R                  S
XES9n[        UR                  5      [        R                  :w  a  [        SUR                  -   5      e [        U [        R                  " UR                  5      5      $ ! [          a  n[        SUR                  -   5      UeSnAff = f)a  Lists namespaces in a catalog.

Args:
    parent_name: name of the catalog in format
      projects/{project}/catalogs/{catalog}.
    page_size: The maximum number of namespaces to return.
    page_token: A page token, received from a previous `ListNamespaces` call.

Returns:
    A json object that contains namespaces.

Raises:
    HttpRequestFailError: if error happens with http request, or parsing
        the http response.
r   r   /z/iceberg/v1/restcatalog/v1/z/namespaces?alt=jsonz
&pageSize=z&pageToken=zContent-Typezapplication/jsonGET)headerszHTTP request failed. Response: z=No JSON object could be decoded from the HTTP response body: N)r   GetEffectiveApiEndpointstrip
quote_plusr   
GetSessionrequestintstatus_codehttplibOKr   textr   jsonloads
ValueError)r   	page_sizer   endpointurlr   r   es           r   ListNamespacesr      s     )))T:@@E(	
-k]:NO  Z	{##C[J/011C/0'  "**5#*G(		'**,
)HMM9 'TZZ5NOO	 
G
--	 s   =)C' '
D1D

D)NN).r   r   r}   urllibr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   core_exceptionsr	   r
   googlecloudsdk.core.credentialsr   	six.movesr   r   r   ReleaseTrackALPHABETAGAr   Errorr   r   r%   r1   r9   r;   r>   r@   rQ   rT   r\   ra   rh   rn   ru   r   r   r   r   r   <module>r      s     6    , / ( : = * ) 4 , 
TD$?00  %)$5$5$;$; 8
 %)$5$5$;$; 8
r
X
D"B
42*	@- $r   