
    ,                         S 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\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.    )absolute_import)division)unicode_literals)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   ParseProjectConfigWithPushblockr1   2   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    r3   r$   
new_configs       r    ParseSourceRepoWithModifiedTopicrB   >   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   r4   r6   )r    project_configr$   rA   s       r   #ParseProjectConfigWithModifiedTopicrE   N   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.)r8   CONCEPTSParser=   r?   r+   )r    	topic_refs     r   r7   r7   `   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.r3   )keyvalueadditionalPropertiesr)   r*   )	r*   rN   r-   r.   RepoappendPubsubConfigsValueAdditionalPropertyr)   )r$   rA   resourcer5   config_additional_propertiesresource_msg_modules         r   r<   r<   l   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}.r3   rM   rO   )r*   r   formatrN   	enumeraterK   r-   r.   rP   r)   rR   )r$   rT   r5   rU   iconfigrV   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.rX   rY   r3   rM   rO   )r*   r   rZ   rN   r[   rK   _UpdateConfigWithArgsrL   r-   r.   rP   r)   rR   )r$   r    rT   r5   rU   r\   r]   rV   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$   r:   r;   message_format_enumsparsed_message_formats        r   r9   r9      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)Nrb   ra   json)getattrr-   re   rf   rg   )pubsub_configmessage_format_typeri   s      r   _GetMessageFormatStringrp      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      $ )Nrc   )r:   rp   r;   rm   rd   r9   )rn   r    r:   r;   r$   s        r   r_   r_      sN    &&P*A-*P.(( KGM4I-K/""*	J	HHr   )NN)r   
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r	   	_API_NAME_API_VERSIONGetMessagesModuler-   Errorr   r!   r&   r1   rB   rE   r7   r<   r>   r@   r9   rp   r_   r   r   r   <module>ry      s    2 &  ' , * * )	""9l;	=
(( =M	 $	">*>4>8Ir   