
                             S r SSKJr  SSKJr  SSKJ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 rS r SS jrS rSS jrS rS rS rg)z%Client for interaction with Dataplex.    )absolute_import)division)unicode_literalsN)storage_api)storage_util)apis)waiter)
exceptions)	resources)yamlc                  0    [         R                  " SS5      $ Ndataplexv1)r   GetClientInstance     +lib/googlecloudsdk/api_lib/dataplex/util.pyr   r   !       			
D	11r   c                  0    [         R                  " SS5      $ r   )r   GetMessagesModuler   r   r   GetMessageModuler   %   r   r   c                    [         R                  R                  U R                  SS9n[        R
                  " U[        5       R                  5      n[        R                  " UUSR                  UR                  5       5      UUS9$ )z=Waits for the given google.longrunning.Operation to complete.z&dataplex.projects.locations.operations)
collectionzWaiting for [{0}] to finish)sleep_mspre_start_sleep_ms)r   REGISTRYParsenamer	   CloudOperationPollerr   projects_locations_operationsWaitForformatRelativeName)	operationresourcer   r   operation_refpollers         r   WaitForOperationr)   )   s     $$**nn!I + - &&!#AA& 
#**=+E+E+GH+
 r   c                     [        USS 5      (       a\  U R                  [        UR                  R	                  5       5       VVs/ s H  u  p#U R                  R                  X#S9PM      snnS9$ g s  snnf )Nlabels)keyvalue)additionalProperties)getattrLabelsValuesortedr+   itemsAdditionalProperty)dataplex_resourceargsr,   r-   s       r   CreateLabelsr6   <   s    T8T""((
 %T[[%6%6%89	
 :
 ))<< =  :	
 )   

s   %A0
c                    U R                  S5      (       d  [        R                  " U 5      $ U=(       d    [        R                  " 5       n[
        R                  R                  U 5      n UR                  U5      n[        R                  " USS9n[        R                  " UR                  5       5      $ ! [         a+  n[        R                  " SR!                  U 5      5      UeSnAff = f)ad  Reads an object's content from GCS.

Args:
  object_url: Can be a local file path or the URL of the object to be read
    from gcs bucket (must have "gs://" prefix).
  storage_client: Storage api client used to read files from gcs.

Returns:
  A str for the content of the file.

Raises:
  ObjectReadError:
    If the read of GCS object is not successful.
zgs://zutf-8)encodingzSUnable to read file {0} due to incorrect file path or insufficient read permissionsN)
startswithr   	load_pathr   StorageClientr   ObjectReferenceFromUrl
ReadObjectioTextIOWrapperloadread	Exceptionr
   BadFileExceptionr#   )
object_urlstorage_clientclient
object_refbytes_iowrapperes          r   r>   r>   I   s     
		w	'	'>>*%%8[668&++33J?*  ,Hx':G99W\\^$$	 

%
%	"F:. s   +A	B5 5
C*?&C%%C*c                 b    SR                  S [        U R                  S5      5       5       5      $ )z)Converts snake case string to camel case. c              3   V   #    U  H  u  pUS :  a  UR                  5       OUv   M!     g7f)r   N)
capitalize).0indwords      r   	<genexpr>SnakeToCamel.<locals>.<genexpr>i   s+      4)# 7doo,4s   ')_)join	enumeratesplit)arg_strs    r   SnakeToCamelrZ   g   s.    	  s!34 
 r   c           
      ^   [        U [        5      (       a9  U  Vs/ s H+  n[        U[        [        45      (       a  [        U5      OUPM-     sn$ U R	                  5        VVs0 s H7  u  p#[        U5      [        U[        [        45      (       a  [        U5      OU_M9     snn$ s  snf s  snnf )zQReccursive method to convert all nested snake case dictionary keys to camel case.)
isinstancelistdictSnakeToCamelDictr2   rZ   )arg_typelist_valr,   r-   s       r   r_   r_   o   s    $
 !	 !H ht-- 	"	 !	  !(	
 )*# 3%/d|%D%D
5
!%P )	
 
s   2B$">B)c                    [        5       nU  H  nSU;  a%  [        R                  " SR                  U5      5      eUR	                  SS5      n[        U5      S:  d2  [        US   R                  5       5      S:X  d  [        US   5      S:X  a%  [        R                  " SR                  U5      5      eUS   XS   '   M     U$ )zxReturns Dataplex task execution spec args as a map of key,value pairs from an input list of strings of format key=value.=zCExecution spec argument '{}' should be of the type argKey=argValue.      r   zEExecution spec argument '{}' should be of the format argKey=argValue.)r^   argparseArgumentTypeErrorr#   rX   lenstrip)args_map_as_listexecution_args_map	arg_entryarg_entry_splits       r   FetchExecutionSpecArgsrn      s    v#i
)&&
O6)   ooc1-OOq q!'')*a/q!"a'&&$fY/  .=Q-?q)*! $" 
r   )i  i  )N)__doc__
__future__r   r   r   rf   r?   googlecloudsdk.api_lib.storager   r   googlecloudsdk.api_lib.utilr   r	   googlecloudsdk.callioper
   googlecloudsdk.corer   r   r   r   r)   r6   r>   rZ   r_   rn   r   r   r   <module>ru      s\    , &  '  	 6 7 , . . ) $22
 <@&
<"r   