
    [                     2   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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r " S S\5      r\	R.                  " \	R0                  R2                  5       " S S\	R4                  5      5       rg)z5Replicate a certificate template to multiple regions.    )absolute_import)division)unicode_literals)
exceptions)base)	locations)request_utils)arg_parsers)
operations)resource_args)logNc                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )ReplicationError!   zSRepresents an error that occurred while replicating a resource to a given location.c                 l   > SR                  X5      U l        [        [        U ]  U R                  5        g )Nz(Failed to replicate to location [{}]: {})format_messagesuperr   __init__)selflocationmessage	__class__s      ,lib/surface/privateca/templates/replicate.pyr   ReplicationError.__init__$   s,    >EEDM	
D*4==9    c                     U R                   $ Nr   )r   s    r   __str__ReplicationError.__str__)   s    ==r   r   )	__name__
__module____qualname____firstlineno____doc__r   r    __static_attributes____classcell__)r   s   @r   r   r   !   s    [:
 r   r   c                   >    \ rS rSrSrSSS.r\S 5       rS rS r	Sr
g	)
	Replicate-   z7Replicate a certificate template to multiple locations.a	        To replicate a certificate templates to all supported locations, run:

        $ {command} my-template --location=us-west1 --all-locations

      To replicate a certificate template to 'us-west2' and 'us-east1', run:

        $ {command} my-template --location=us-west1 --target-locations=us-west2,us-east1

      To overwrite existing templates with the same resource ID in the target
      locations, use the --overwrite flag:

        $ {command} my-template --location=us-west1 --target-locations=us-west2,us-east1 --overwrite

      To continue replicating templates in other locations in the event of a
      failure in one or more locations, use the --continue-on-error flag:

        $ {command} my-template --location=us-west1 --all-locations --continue-on-error)DESCRIPTIONEXAMPLESc                    [         R                  " U S5        [        R                  " SSSS9R	                  U 5      n[        R
                  " SSSSS9R	                  U5        [        R
                  " S	S
[        R                  " S S9SS9R	                  U5        [        R
                  " SSSSSS9R	                  U 5        [        R
                  " SSSSSS9R	                  U 5        g )Nzto replicateTz<Specify where the certificate template should be replicated.)mutexrequiredhelpz--all-locationsstore_constz3Replicate this template to all supported locations.)actionconstr1   z--target-locationsz/Replicate this template to the given locations.c                 J    [         R                  " U 5      R                  5       $ r   )six	text_typestrip)xs    r   <lambda> Replicate.Args.<locals>.<lambda>^   s    3==#3#9#9#;r   )element_typeLOCATION)r1   typemetavarz--overwritezCOverwrite any existing templates with the same name, if they exist.F)r1   r3   r4   defaultz--continue-on-errorzContinue replicating the template to other locations even if an error is encountered. If this is set, an error in one location will be logged but will not prevent replication to other locations.)r   +AddCertificateTemplatePositionalResourceArgr   ArgumentGroupAddToParserArgumentr
   ArgList)parsertarget_locations_groups     r   ArgsReplicate.ArgsI   s    ==  "//K k&	  	MMB	D EPK"E$MM>  ;=
 (K(>?MM #{6*MM8  #{6*r   c           
         SR                  X5      nSR                  Xc5      n U R                  R                  R                  U R                  R                  UUU[        R                  " 5       S95      $ ! [        R                   a~  nU(       d  [        USR                  U5      5      eU R                  R                  R                  U R                  R                  UUS[        R                  " 5       S95      s SnA$ SnAf[        R                   a%  n[        U[        R                  " U5      5      eSnAff = f)a  Returns an LRO for a Create or Update operation for the given template.

Args:
  project: str, the project ID or number for the new template.
  location: str, the location for the new template.
  template_id: str, the resource ID for the new template.
  template: object, the body of the new template.
  overwrite: bool, whether to overwrite existing templates with the same ID.

Raises:
  ReplicationError, if the template could not be replicated to this
  location.
zprojects/{}/locations/{}z{}/certificateTemplates/{})parentcertificateTemplateIdcertificateTemplate	requestIdzNCertificate template [{}] already exists and the --overwrite flag was not set.zPpredefined_values,identity_constraints,passthrough_extensions,description,labels)namerM   
updateMaskrN   N)r   client'projects_locations_certificateTemplatesCreatemessages;PrivatecaProjectsLocationsCertificateTemplatesCreateRequestr	   GenerateRequestIdapi_exceptionsHttpConflictErrorr   Patch:PrivatecaProjectsLocationsCertificateTemplatesPatchRequest	HttpErrorr6   r7   )	r   projectr   template_idtemplate	overwriterK   resource_namees	            r   _CreateOrUpdateTemplate!Replicate._CreateOrUpdateTemplater   s#    (..wAF077LM9[[@@GG
--FF$/"*%779	 G ;< < ++ <!6-02 	2
 [[@@FF
--EE "* l%779 F ;< < ## 9Xs}}Q'7889s+   AA6 6D?
A3D=D?D? D::D?c           	         [         R                  " SS9U l        [         R                  " SS9U l        UR
                  R                  R                  5       nU R                  R                  R                  U R                  R                  UR                  5       S95      nSUl        SnUR                  nUR                  (       a7  [        R                   " S5       Vs/ s H  nXbR"                  :w  d  M  UPM     nnU H  nUR%                  5       nXbR"                  :X  a'  [&        R(                  " SR+                  U5      5        MI   U R-                  UR.                  XbR1                  5       X1R2                  5      n[4        R6                  " USR+                  U5      SS9  US-  nM     [&        R@                  RC                  S
R+                  UR                  5       U[E        U5      5      5        g	s  snf ! [8         aI  nUR:                  (       a1  [&        R(                  " [<        R>                  " U5      5         S	nAGMF  UeS	nAff = f)zRuns the command.v1)api_version)rO    r   z7Skipping location [{}] since it is the source location.zReplicating template to [{}]   Nz3Replicated template [{}] to {} out of {} locations.)#privateca_baseGetClientInstancerQ   GetMessagesModulerT   CONCEPTScertificate_templateParserR   Get8PrivatecaProjectsLocationsCertificateTemplatesGetRequestRelativeNamerO   target_locationsall_locationsr   GetSupportedLocationslocationsIdr8   r   warningr   rb   
projectsIdNamer_   r   Awaitr   continue_on_errorr6   r7   statusPrintlen)	r   argstemplate_refr^   success_countrr   r   	operationra   s	            r   RunReplicate.Run   s    22tDDK"44FDM==55;;=L{{BBFFNN**, 	O 	./H
 HMM,,#,#B#B4#H#Hx111 #H   %!h	--	-ELL	 	001H1H19;L;L;N19>>K	 	*11(;	 	! %. JJ=DD%%'<L8M	OP7*  !!
++cmmA&
'
	s+   G56G5
AG::
I;III)rQ   rT   N)r"   r#   r$   r%   r&   detailed_helpstaticmethodrH   rb   r   r'    r   r   r*   r*   -   s9    ? D[	-0 &+ &+P*9X-Pr   r*   )r&   
__future__r   r   r   apitools.base.pyr   rW    googlecloudsdk.api_lib.privatecar   ri   r   r	   googlecloudsdk.callioper
   $googlecloudsdk.command_lib.privatecar   r   googlecloudsdk.corer   r6   	Exceptionr   ReleaseTracksReleaseTrackGASilentCommandr*   r   r   r   <module>r      s{    < &  ' 9 C 6 : / ( ; > # 
	y 	 D%%(()]P"" ]P *]Pr   