
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
lmZ ddlmZ ddlmZ d Zd Z	 ddZd ZddZd Zd Zd Zy)z%Client for interaction with Dataplex.    )absolute_import)division)unicode_literalsN)storage_api)storage_util)apis)waiter)
exceptions)	resources)yamlc                  .    t        j                  dd      S Ndataplexv1)r   GetClientInstance     +lib/googlecloudsdk/api_lib/dataplex/util.pyr   r   !       			
D	11r   c                  .    t        j                  dd      S r   )r   GetMessagesModuler   r   r   GetMessageModuler   %   r   r   c                    t         j                  j                  | j                  d      }t	        j
                  |t               j                        }t	        j                  ||dj                  |j                               ||      S )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           
          t        |dd       ra| j                  t        |j                  j	                               D cg c]"  \  }}| j                  j                  ||      $ c}}      S y c c}}w )Nlabels)keyvalue)additionalProperties)getattrLabelsValuesortedr+   itemsAdditionalProperty)dataplex_resourceargsr,   r-   s       r   CreateLabelsr6   <   s    T8T"((
 %T[[%6%6%89	
 :
U ))<<u =  :	
 )   

s   'A0
c                    | j                  d      st        j                  |       S |xs t        j                         }t
        j                  j                  |       }	 |j                  |      }t        j                  |d      }t        j                  |j                               S # t        $ r*}t        j                  dj!                  |             |d}~ww xY w)ax  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
B* *	C3%CCc                 b    dj                  d t        | j                  d            D              S )z)Converts snake case string to camel case. c              3   P   K   | ]  \  }}|d kD  r|j                         n|   yw)r   N)
capitalize).0indwords      r   	<genexpr>zSnakeToCamel.<locals>.<genexpr>i   s.      4)#t 7doo,4s   $&_)join	enumeratesplit)arg_strs    r   SnakeToCamelrY   g   s.    	  s!34 
 r   c           
      6   t        | t              r1| D cg c]%  }t        |t        t        f      rt        |      n|' c}S | j	                         D ci c]2  \  }}t        |      t        |t        t        f      rt        |      n|4 c}}S c c}w c c}}w )zQReccursive method to convert all nested snake case dictionary keys to camel case.)
isinstancelistdictSnakeToCamelDictr2   rY   )arg_typelist_valr,   r-   s       r   r^   r^   o   s    $
 !	 !H ht- 	"	 !	  !(	
 )*#u 3%/d|%D
5
!%P )	
 
s   *B7Bc                 v   t               }| D ]  }d|vr$t        j                  dj                  |            |j	                  dd      }t        |      dk  s0t        |d   j                               dk(  st        |d         dk(  r$t        j                  dj                  |            |d   ||d   <    |S )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#   rW   lenstrip)args_map_as_listexecution_args_map	arg_entryarg_entry_splits       r   FetchExecutionSpecArgsrm      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   re   r?   googlecloudsdk.api_lib.storager   r   googlecloudsdk.api_lib.utilr   r	   googlecloudsdk.callioper
   googlecloudsdk.corer   r   r   r   r)   r6   r>   rY   r^   rm   r   r   r   <module>rt      s\    , &  '  	 6 7 , . . ) $22
 <@&
<"r   