
                             S 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\R                  " \\5      r
 " S S	\R                  5      rS
 rS rS rS rS rS rS rS rS rSS jrS rS rg)z+General utilties for Cloud Source commands.    )apis)
exceptions)
properties)	resources
sourcerepov1c                       \ rS rSrSrSrg)InvalidTopicError   z4Raised when a topic cannot be found within the repo. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       -lib/googlecloudsdk/command_lib/source/util.pyr
   r
      s    <r   r
   c                     [         R                  R                  SU R                  =(       d2    [        R
                  R                  R                  R                  5       S9$ )Nzsourcerepo.projects)
projectsId)r   REGISTRYCreateprojectr   VALUEScore	GetOrFail)argss    r   CreateProjectResourcer   !   sL    				"	"K!2!2!7!7!?!?!I!I!K 
# 
M Mr   c                 @    [         R                  R                  SUU S9$ )Nzpubsub.projects.topics)r   topicsId)r   r   r   )
topic_nametopic_projects     r   CreateTopicResourcer#   '   s)    				"	" 
# 
 r   c                 z    [        U 5      nUR                  5       nU R                  n[        R	                  UUS S9$ )N)enablePrivateKeyChecknamepubsubConfigs)r   RelativeNameenable_pushblock	_MESSAGESProjectConfig)r   project_refproject_namer)   s       r   ParseProjectConfigWithPushblockr.   /   sG    %d++))+,**		 	 , 
! 
 r   c                    [        U 5      nU R                  (       a+  [        X R                  U R                  5      n[        X#USS9$ U R                  (       a
  [        X!SS9$ U R                  (       a  [        X USS9$ U$ )z8Parse and create a new Repo message with modified topic.reporesource_name
GetTopicName	add_topic_ParsePubsubConfigmessage_formatservice_account_AddTopicToResourceremove_topic_RemoveTopicFromResourceupdate_topic_UpdateTopicInResource)r   r0   r!   
new_configs       r    ParseSourceRepoWithModifiedTopicr?   ;   su    D!*	^^#J0C0C$($8$8:JF< <#JFKK!*DOO	+r   c                    [        U 5      nU R                  (       a+  [        X R                  U R                  5      n[        X#USS9$ U R                  (       a
  [        X!SS9$ U R                  (       a  [        X USS9$ U$ )zAParse and create a new ProjectConfig message with modified topic.r   r1   r3   )r   project_configr!   r>   s       r   #ParseProjectConfigWithModifiedTopicrB   K   s    D!*	^^#J0C0C$($8$8:JiI I#)= =!.	C C 
r   c                 ~   U R                   (       a4  U R                  R                   R                  5       nUR                  5       $ U R                  (       a4  U R                  R                  R                  5       nUR                  5       $ U R                  R                  R                  5       nUR                  5       $ )z<Get the topic name based on project and topic_project flags.)r5   CONCEPTSParser:   r<   r(   )r   	topic_refs     r   r4   r4   ]   s    	^^''--/I 
			!! **002I 
			!! **002I				!!r   c                 &   UR                   c  / nOUR                   R                  n[        R                  nUS:X  a  [        R                  nUR                  UR                  R                  XS95        U" UR                  UR                  US9S9$ )z;Add the PubsubConfig message to Repo/ProjectConfig message.r0   )keyvalueadditionalPropertiesr&   r'   )	r'   rK   r*   r+   RepoappendPubsubConfigsValueAdditionalPropertyr&   )r!   r>   resourcer2   config_additional_propertiesresource_msg_modules         r   r9   r9   i   s    ##% #+#9#9#N#N !//f#..%%,,?? @ ,- 
=='::; ; =
> >r   c                    UR                   c  [        SR                  X5      5      eUR                   R                  n[	        U5       H  u  pEUR
                  U :X  d  M  X4	   O   [        SR                  X5      5      e[        R                  nUS:X  a  [        R                  nU" UR                  UR                  US9S9$ )z5Remove the topic from the Repo/ProjectConfig message.9Invalid topic [{0}]: No topics are configured in the {1}.TInvalid topic [{0}]: You must specify a topic that is already configured in the {1}.r0   rJ   rL   )r'   r
   formatrK   	enumeraterH   r*   r+   rM   r&   rO   )r!   rQ   r2   rR   iconfigrS   s          r   r;   r;   ~   s    #
 **0&*KM M "*!7!7!L!L9:iazzZ
&
) ;
  K#VJ>@ @ "//f#..	=='::; ; =
> >r   c                    UR                   c  [        SR                  X5      5      eUR                   R                  n[	        U5       H4  u  pVUR
                  U :X  d  M  [        UR                  U5      XE   l          O   [        SR                  X5      5      e[        R                  nUS:X  a  [        R                  nU" UR                  UR                  US9S9$ )zDUpdate the topic in the configuration and return a new repo message.rU   rV   r0   rJ   rL   )r'   r
   rW   rK   rX   rH   _UpdateConfigWithArgsrI   r*   r+   rM   r&   rO   )r!   r   rQ   r2   rR   rY   rZ   rS   s           r   r=   r=      s     #
 **0&*KM M "*!7!7!L!L9:iazzZ.C
,,/"%+	 ;  K#VJ>@ @ "//f#..	=='::; ; =
> >r   Nc                     [         R                  R                  nUS:X  a  UR                  nOUR                  n[         R                  UUU S9$ )z&Parse and create PubsubConfig message.protobuf)messageFormatserviceAccountEmailtopic)r*   PubsubConfigMessageFormatValueValuesEnumPROTOBUFJSON)r!   r7   r8   message_format_enumsparsed_message_formats        r   r6   r6      sW    "//LLz!099 155			)) 
  
 r   c                 p    [        U S5      n[        R                  R                  nXR                  :X  a  gg)Nr_   r^   json)getattrr*   rb   rc   rd   )pubsub_configmessage_format_typerf   s      r   _GetMessageFormatStringrm      s3    ?"//LL999	r   c                     UR                   =(       d    [        U 5      nUR                  =(       d    [        U S5      nU R                  n[        XBU5      $ )Nr`   )r7   rm   r8   rj   ra   r6   )rk   r   r7   r8   r!   s        r   r\   r\      sN    &&P*A-*P.(( KGM4I-K/""*	J	HHr   )NN)r   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r   	_API_NAME_API_VERSIONGetMessagesModuler*   Errorr
   r   r#   r.   r?   rB   r4   r9   r;   r=   r6   rm   r\   r   r   r   <module>ru      s    2 - * * )	""9l;	=
(( =M	 $	">*>4>8Ir   