
    )                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	mZ ddl
mZ ddl
mZ dd	l
mZ dd
l
mZ ddlmZ ddlmZ  ej(                  ej*                  j,                         G d dej.                               Zy)z"Update a new certificate template.    )absolute_import)division)unicode_literals)base)request_utils)
exceptions)flags)
operations)resource_args)labels_util)logc                   6    e Zd ZdZdddZd Zed        Zd Zy)CreatezUpdate a certificate template.a          To update a template named "dns-restricted" with new default x509 extensions:

          $ {command} dns-restricted --location=us-west1 --predefined-values-file=x509_parameters.yaml

        To update a template named "dns-restricted" to allow requestors to specify subject:

          $ {command} dns-restricted --location=us-west1 --copy-subject

        To update a template named "dns-restricted" with allowed extension
        'base-key-usage' to allow requestors to specify additional x509 extension 'extended-key-usage':

          $ {command} dns-restricted --location=us-west1 --copy-known-extensions=base-key-usage,extended-key-usage

        To update a template named "mtls-restricted" with allowed OID
        '1.1' to allow requestors to specify alternative OIDS '2.2,3.3':

          $ {command} mtls-restricted --location=us-west1 --copy-extensions-by-oid=2.2,3.3
       )DESCRIPTIONEXAMPLESc                    t        j                  d      }|j                         }g }|j                  d      s"|j                  d      s|j                  d      rt	        j
                  |      |_        |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      r+t	        j                  |      |_	        |j                  d	       |j                  d
      r"|j                  |_
        |j                  d
       |j                  d      xs |j                  d      }|j                  d      xs |j                  d      }|s|r@t	        j                  |      |_        |r|j                  d       |r|j                  d       t        j                  j                  |      }|j!                  |j"                  j$                  |      }	|	j&                  r"|	j(                  |_        |j                  d       |st+        j,                  d      ||fS )aR  Creates a Certificate template object and update mask from Certificate template update flags.

    Requires that args has 'description', 'copy-sans', 'copy-subject',
    'predefined-values-file', 'copy-known-extensions', 'copy-extensions-by-oid',
    and update labels flags registered.

    Args:
      args: The parser that contains the flag values.
      current_labels: The current set of labels for the Certificate Template.

    Returns:
      A tuple with the Certificate template object to update with and the list
      of
      strings representing the update mask, respectively.
    v1	copy_sanscopy_subjectidentity_cel_expressionz8identity_constraints.allow_subject_alt_names_passthroughz.identity_constraints.allow_subject_passthroughz#identity_constraints.cel_expressionpredefined_values_filepredefined_valuesdescriptioncopy_known_extensionsdrop_known_extensionscopy_extensions_by_oiddrop_oid_extensionsz'passthrough_extensions.known_extensionsz,passthrough_extensions.additional_extensionslabelsz8No updates found for the requested certificate template.)privateca_baseGetMessagesModuleCertificateTemplateIsSpecifiedr	   ParseIdentityConstraintsidentityConstraintsappendParsePredefinedValuespredefinedValuesr   ParseExtensionConstraintspassthroughExtensionsr   DiffFromUpdateArgsApplyCaPoolLabelsValueneeds_updater   privateca_exceptionsNoUpdateException)
selfargscurrent_labelsmessagestemplate_to_updateupdate_maskknown_exts_flagsoid_exts_flagslabels_difflabels_updates
             )lib/surface/privateca/templates/update.py"_UpdateCertificateTemplateFromArgsz)Create._UpdateCertificateTemplateFromArgs;   sE     //5H!557K 	%N+56/4/M/M
0, 
		+	&F	
 
		.	)KL			3	4@A01,1,G,G,M),-&'+'7'7$''' 3			1	2  %%  1			/	0  > 
)
)$
/ . 
DE	IJ""11$7K%%##^M !!"/"6"6" 22
D  {**    c                 (   t        j                  | d       t        j                  dd      j	                  |        t        j                  |        t        j                  | d       t        j                  |        t        j                  |        y )Nz	to updatez--descriptionz0A text description for the Certificate Template.)helpF)require_passthrough_flags)r   +AddCertificateTemplatePositionalResourceArgr   ArgumentAddToParserr	   AddPredefinedValuesFileFlagAddIdentityConstraintsFlags%AddExtensionConstraintsFlagsForUpdater   AddUpdateLabelsFlags)parsers    r<   ArgszCreate.Args   sm    == 	MMPk&	%%f-	%%fN	//7$$V,r>   c           	      T   t        j                  d      }t        j                  d      }|j                  j                  j                         }|j                         }|j                  j                  |j                  |            }| j                  ||j                        \  }}t        j                  ||j                  j                  |j                  j                   d       |j                  j#                  |j%                  ||dj'                  |      t)        j*                                     }	t-        j.                  |	dd      }
t-        j0                  |
|j2                        }t4        j6                  j9                  d	j;                  |j<                               y )
Nr   )nameT)existing_copy_subjexisting_copy_sans
for_update,)rL   certificateTemplate
updateMask	requestIdzUpdating Certificate Template.)api_versionz"Updated Certificate Template [{}].)r   GetClientInstancer    CONCEPTScertificate_templateParseRelativeName'projects_locations_certificateTemplatesGet8PrivatecaProjectsLocationsCertificateTemplatesGetRequestr=   r   r	   ValidateIdentityConstraintsr$   allowSubjectPassthroughallowSubjectAltNamesPassthroughPatch:PrivatecaProjectsLocationsCertificateTemplatesPatchRequestjoinr   GenerateRequestIdr
   AwaitGetMessageFromResponser!   r   statusPrintformatrL   )r2   r3   clientr5   cert_template_reftemplate_namecurrent_cert_templatecert_template_to_updater7   	operationcert_template_responsecert_templates               r<   Runz
Create.Run   s{   --d3F//5H::@@B%224M"JJNNII 	J 	
 	//'..	
 )[ 
%%0DD\\0DDdd	 >>DDKK 7xx,#557	 	L 	
I (--3 55 < <M JJ,33M4F4FGr>   N)	__name__
__module____qualname____doc__detailed_helpr=   staticmethodrJ   rq    r>   r<   r   r       s6    ' :-.N+` 
- 
-.r>   r   N)ru   
__future__r   r   r    googlecloudsdk.api_lib.privatecar   r   r   googlecloudsdk.calliope$googlecloudsdk.command_lib.privatecar   r0   r	   r
   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   ReleaseTracksReleaseTrackGACreateCommandr   rx   r>   r<   <module>r      sk    ) &  ' C : ( S 6 ; > < # D%%(()eT e *er>   