
    J                        S 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  \R                  " 5       rS\S\4S	 jrS
\S\R                   R"                  4S jrS
\S\R&                  R"                  4S jrS\\   4S jrS rS rg)z(Utilities for Dataplex Entries commands.    N)List)util)messages)arg_parsersdatetime_strreturnc                 \    [         R                  R                  U 5      R                  5       $ )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           
         [         R                  " 5       nU" U 5      n[        U[        5      (       d  [         R                  " SU  S35      e/ nUR                  5        H_  u  pEUR                  [        R                  R                  R                  U[        R                  " U[        R                  5      S95        Ma     [        R                  R                  US9$ )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).
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   c           
         [         R                  " 5       nU" U 5      n[        U[        5      (       d  [         R                  " SU  S35      e/ nUR                  5        H  u  pESU;   a  [         R                  " SU S35      eUR                  [        R                  R                  R                  U[        R                  " U[        R                  5      S95        M     [        R                  R                  US9$ )aE  Parse aspects from a YAML or JSON file for EntryLinks.

Perform a basic validation that aspects are provided in a correct format.
Aspect keys for EntryLinks cannot contain paths.

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

Returns:
  A list of aspects parsed to a proto message (AspectsValue).
r   z. It must contain a map with a key in the format `PROJECT_ID.LOCATION.ASPECT_TYPE_ID`. Values in the map represent Aspect's content, which must conform to a template defined for a given `PROJECT_ID.LOCATION.ASPECT_TYPE_ID`.@zAspect key "z" is invalid for an EntryLink. Aspect keys for EntryLinks must be in PROJECT_ID.LOCATION.ASPECT_TYPE_ID format and cannot contain a path.r   r   )r   r   r   r   r   r   r   r   GoogleCloudDataplexV1EntryLinkr    r!   r"   r#   r$   r%   s         r   ParseEntryLinkAspectsr/   I   s    '')&|$+	K	&	&

'
'
  /E 	E  ''--/j
j)) %( ( 
 NN77DDWW;;(DD 	X 	
 0 
	8	8	E	E" 
F 
 r   	ancestorsc                 8    U c  / $ [        [        S U 5      5      $ )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                 t    [         R                  " [        R                  " U 5      [        R
                  5      $ )N)r"   r#   jsonloadsr   (GoogleCloudDataplexV1EntrySourceAncestor)ancestors    r   <lambda>+ParseEntrySourceAncestors.<locals>.<lambda>   s$    =DDjj"GGr   )listmap)r0   s    r   ParseEntrySourceAncestorsr;   w   s.     I		 
 r   c                    U c  g/ nU  H  n[         R                  " [        R                  " [        R
                  " U5      5      [        R                  5      nUR                  (       d  [        R                  " S5      eUR                  [        R                  R                  R                  UR                  US95        M     U$ )zParse access groups from a list of JSON strings.

Args:
  access_groups: A list of JSON strings representing Access Group(s).

Returns:
  A list of AdditionalProperty objects.
Nz%Access group must have an "id" field.r   )r"   r#   dataplex_utilSnakeToCamelDictr3   r4   r   +GoogleCloudDataplexV1DataProductAccessGroupidr   r   r    GoogleCloudDataplexV1DataProductAccessGroupsValuer!   )access_groupsr   access_groupaccess_group_msgs       r   ParseAccessGroupsrF      s     
%#l$@@&&tzz,'?@DD
 ))
1  
LL99KK^^ ##+; 	_ 	
 $  
,r   c                    U c  g/ nU  H  n[         R                  " U5      nUR                  SS5      nU(       d  [        R                  " S5      e[
        R                  " [        R                  " U5      [        R                  5      nUR                  [        R                  R                  R                  XES95        M     U$ )zParse access group configs from a list of JSON strings.

Args:
  access_group_configs: A list of JSON strings representing Access Group
    Config(s).

Returns:
  A list of AdditionalProperty objects.
Nr@   z,Access group config must have an "id" field.r   )r3   r4   popr   r   r"   r#   r=   r>   r   /GoogleCloudDataplexV1DataAssetAccessGroupConfigr   GoogleCloudDataplexV1DataAssetAccessGroupConfigsValuer!   )access_group_configsadditional_propertiesaccess_group_configconfig_dictgroup_idaccess_group_config_msgs         r   ParseAccessGroupConfigsrR      s     !1**01KtT*H))
8  ,GG&&{3HH
   77OObb 	c 	
 2( 
r   )__doc__r3   typingr   googlecloudsdk.api_lib.dataplexr   r=   googlecloudsdk.api_lib.utilr   r"   googlecloudsdk.callioper   GetMessageModuler   strr   r   r    r+   r.   r/   r;   rF   rR    r   r   <module>r[      s    /   A A / 113 >c >c >
%%00==%P++44AA+\c 0@"r   