
    ~                         d Z ddlmZ ddlmZ ddlm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  e
j                          Zd
edefdZdedej(                  j*                  fdZdee   fdZy)z(Utilities for Dataplex Entries commands.    )absolute_import)division)unicode_literalsN)List)util)messages)arg_parsersdatetime_strreturnc                 \    t         j                  j                  |       j                         S )zWParses datetime string, validates it and outputs the new datetime string in ISO format.)r	   DatetimeParse	isoformat)r
   s    2lib/googlecloudsdk/command_lib/dataplex/parsers.pyIsoDateTimer      s"    				#	#L	1	;	;	==    aspects_filec           
         t        j                         } ||       }t        |t              st        j                  d|  d      g }|j                         D ]a  \  }}|j                  t        j                  j                  j                  |t        j                  |t        j                                     c t        j                  j                  |      S )a  Parse aspects from a YAML or JSON file.

  Perform a basic validation that aspects are provided in a correct format.

  Args:
    aspects_file: The path to the YAML/JSON file containing aspects.

  Returns:
    A list of aspects parsed to a proto message (AspectsValue).
  zInvalid aspects file: z. It must contain a map with a key in the format `ASPECT_TYPE@PATH` (or just `ASPECT_TYPE` if attached to the root path). Values in the map represent Aspect's content, which must conform to a template defined for a given `ASPECT_TYPE`.)keyvalue)additionalProperties)r	   YAMLFileContents
isinstancedictArgumentTypeErroritemsappenddataplex_messageGoogleCloudDataplexV1EntryAspectsValueAdditionalPropertymessages_utilDictToMessageWithErrorCheckGoogleCloudDataplexV1Aspect)r   parserraw_aspectsaspects
aspect_keyaspects         r   ParseAspectsr*   $   s     '')&|$+	K	&

'
'
  / 	  ''--/j&NN33@@SS;;(DD 	T 	
 0 
	4	4	A	A" 
B 
 r   	ancestorsc                 6    | g S t        t        d |             S )zParse ancestors from a string.

  Args:
    ancestors: A list of strings containing the JSON representation of the
      Ancestors.

  Returns:
    A list of ancestors parsed to a proto message
    (GoogleCloudDataplexV1EntrySourceAncestor).
  c                 p    t        j                  t        j                  |       t        j
                        S )N)r"   r#   jsonloadsr   (GoogleCloudDataplexV1EntrySourceAncestor)ancestors    r   <lambda>z+ParseEntrySourceAncestors.<locals>.<lambda>[   s$    =DDjj"GGr   )listmap)r+   s    r   ParseEntrySourceAncestorsr5   L   s.     I		 
 r   )__doc__
__future__r   r   r   r.   typingr   googlecloudsdk.api_lib.dataplexr   dataplex_utilgooglecloudsdk.api_lib.utilr   r"   googlecloudsdk.callioper	   GetMessageModuler   strr   r   r    r*   r5    r   r   <module>r@      sx    / &  '   A A /1=113 >c >c >
%%00==%Pc r   