
                         l   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSK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
  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r\R                  " SSSSSSSSS.5      r\" S/5      r \R                  " SSS.5      r!\RD                  " S5      r#\RD                  " S5      r$\RD                  " S5      r%S r&S!r'S"r(S#r)/ S$Qr*/ S%Qr+S& r,SS' jr-SS( jr.S) r/S* r0S+ r1S, r2S- r3S. r4SS/ jr5S0 r6 SS1 jr7S2 r8S3 r9SS4 jr:S5 r;S6 r<S7 r=S8 r>S9 r? SS: jr@SS; jrAS< rBS= rCS> rDS? rES@ rFSA rGSB rHSC rISD rJSE rKSF rLSG rMSH rNSI rOSJ rP SSK jrQSL rRSM rSSN rTSO rUSP rVSQ rWSR rXSS rYST rZSU r[SVSWSXSYSZS[S\S]S^S_.	r\\R                  " S`SVSa\R                  " Sb5      R                  R                  \\Sc9raSdSeSf.rb\R                  " SgSdSh\R                  " Sb5      R                  R                  \bSc9reSiSjSk.rf\R                  " SlSiSm\R                  " Sb5      R                  R                  \fSc9riSnSoSpSqSrSsStSuSv.rj\R                  " SwSx\R                  " Sb5      R                  R                  \jSy9rmSz rnS{ roS| rpS} rqS~ rrSS jrsS rtS ruS rvS rwS rxS ryg)z(Helpers for parsing flags and arguments.    )absolute_import)division)unicode_literalsN)base)messages)arg_parsers)
exceptions)preset_profiles)
text_utils)	arg_utils)
console_io)timescriticalpermittedIpRangesexcludedIpRangespermittedEmailAddressesexcludedEmailAddressespermittedUrisexcludedUrispermittedDnsNamesexcludedDnsNames)name_permitted_ipname_excluded_ipname_permitted_emailname_excluded_emailname_permitted_uriname_excluded_uriname_permitted_dnsname_excluded_dnsname-constraintsaiaIssuingCertificateUrlscrlAccessUrls)custom_aia_urlscustom_cdp_urlsz^[^@]+@[^@]+$z^([^.]+\.)*[^.]+$z^([0-9a-f][0-9a-f])+$aD  
If this is enabled, the following will happen:
1) The CA certificates will be written to a known location within the CA distribution point.
2) The AIA extension in all issued certificates will point to the CA cert URL in that distribition point.

Note that the same bucket may be used for the CRLs if --publish-crl is set.
a  
If this is enabled, the following will happen:
1) The CA certificates will be written to a known location within the CA distribution point.
2) The AIA extension in all issued certificates will point to the CA cert URL in that distribution point.

If this gets disabled, the AIA extension will not be written to any future certificates issued
by this CA. However, an existing bucket will not be deleted, and the CA certificates will not
be removed from that bucket.

Note that the same bucket may be used for the CRLs if --publish-crl is set.
a  
If this gets enabled, the following will happen:
1) CRLs will be written to a known location within the CA distribution point.
2) The CDP extension in all future issued certificates will point to the CRL URL in that distribution point.

Note that the same bucket may be used for the CA cert if --publish-ca-cert is set.

CRL publication is not supported for CAs in the DevOps tier.
a  
If this gets enabled, the following will happen:
1) CRLs will be written to a known location within the CA distribution point.
2) The CDP extension in all future issued certificates will point to the CRL URL in that distribution point.

If this gets disabled, the CDP extension will not be written to any future certificates issued
by CAs in this pool, and new CRLs will not be published to that bucket (which affects existing certs).
However, an existing bucket will not be deleted, and any existing CRLs will not be removed
from that bucket.

Note that the same bucket may be used for the CA cert if --publish-ca-cert is set.

CRL publication is not supported for CAs in the DevOps tier.
)	digital_signaturecontent_commitmentkey_enciphermentdata_enciphermentkey_agreement	cert_signcrl_signencipher_onlydecipher_only)server_authclient_authcode_signingemail_protectiontime_stampingocsp_signingc                 P    [         R                  " SSSSS9R                  U 5        g)zAdds the encryption key flag.

Registers the flag for the Cloud KMS key (CMEK) used to encrypt certificates
in this pool.

Args:
  parser: The parser to add the flags to.
z--encryption-keyzThe full resource name of the Cloud KMS key to use for encrypting certificate data at rest. The key must be in the same region as the CA pool.FT)helprequiredhiddenNr   ArgumentAddToParserparsers    1lib/googlecloudsdk/command_lib/privateca/flags.pyAddEncryptionKeyFlagr>      s,     -- 	 K    c                 x    U(       a  [         O[        n[        R                  " SUSSSS9R	                  U 5        g )N--publish-crl
store_trueFTr5   actionr6   default)PUBLISH_CRL_UPDATE_HELPPUBLISH_CRL_CREATE_HELPr   r9   r:   r<   use_update_help_text	help_texts      r=   AddPublishCrlFlagrK      s=     
 " 
 -- Kr?   c                 x    U(       a  [         O[        n[        R                  " SUSSSS9R	                  U 5        g )Nz--publish-ca-certrB   FTrC   )PUBLISH_CA_CERT_UPDATE_HELPPUBLISH_CA_CERT_CREATE_HELPr   r9   r:   rH   s      r=   AddPublishCaCertFlagrO      s=     
 "& 
 -- Kr?   c                 J    [         R                  " U 5      R                  5       $ N)six	text_typestrip)vals    r=   	_StripValrV      s    	s		!	!	##r?   c           	          [         R                  " SSR                  SR                  [        R
                  " 5       5      5      SS9R                  U 5        g )N--use-preset-profilezThe name of an existing preset profile used to encapsulate X.509 parameter values. USE_PRESET_PROFILE must be one of: {}.

For more information, see https://cloud.google.com/certificate-authority-service/docs/certificate-profile.z, Fr5   r6   )r   r9   formatjoinr
   GetPresetProfileOptionsr:   r;   s    r=   AddUsePresetProfilesFlagr]      sD    --] 	tyy@@BCD	 Kr?   c                 P    [         R                  " SSSSS9R                  U 5        g )Nz--auto-enablez[If this flag is set, the Certificate Authority will be automatically enabled upon creation.rB   Fr5   rD   r6   r8   r;   s    r=   AddAutoEnableFlagr`      s*    --$  Kr?   c                    [         R                  " SS[        R                  " [        S9SS9R                  U 5        [         R                  " SS[        R                  " [        S9SS9R                  U 5        [         R                  " S	S
[        R                  " [        S9SS9R                  U 5        [         R                  " SS[        R                  " [        S9SS9R                  U 5        g)zAdds the Subject Alternative Name (san) flags.

This will add --ip-san, --email-san, --dns-san, and --uri-san to the parser.

Args:
  parser: The parser to add the flags to.
--email-sanz<One or more comma-separated email Subject Alternative Names.element_type	EMAIL_SANr5   typemetavar--ip-sanz9One or more comma-separated IP Subject Alternative Names.IP_SAN	--dns-sanz:One or more comma-separated DNS Subject Alternative Names.DNS_SANz	--uri-sanz:One or more comma-separated URI Subject Alternative Names.URI_SANNr   r9   r   ArgListrV   r:   r;   s    r=   _AddSubjectAlternativeNameFlagsrp      s     --II6	
 K--FI6	
 K--GI6	
 K--GI6	
 Kr?   c                 x    [         R                  " SSSS[        R                  " 5       S9R	                  U 5        g )N--subject-fileSUBJECT_FILEz>A yaml file containing the RDN sequence for the Subject field.T)rh   r5   r7   rg   r   r9   r   YAMLFileContentsr:   r;   s    r=   _AddSubjectFileFlagrv      s2    --K'') Kr?   c           
          [         R                  " SSS[        R                  " [        [        S9S9R                  U 5        g )N	--subjectSUBJECTzyX.501 name of the certificate subject. Example: --subject "C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com")key_type
value_typerh   r5   rg   )r   r9   r   ArgDictrV   r:   r;   s    r=   _AddSubjectFlagr~     s8    --L 	iH Kr?   c                 f    U R                  SUS9n[        U5        [        U5        [        U 5        g)zAdds subject flags to the parser including subject string and SAN flags.

Args:
  parser: The parser to add the flags to.
  subject_required: Whether the subject flag should be required.
T)mutexr6   N)	add_groupr~   rv   rp   )r<   subject_requiredsubject_groups      r=   AddSubjectFlagsr     s9     "" # - - m$!&)r?   c                 L    [         R                  " SSS9R                  U 5        g )N--subject-key-idzOptional field to specify subject key ID for certificate. DO NOT USE except to maintain a previously established identifier for a public key, whose SKI was not generated using method (1) described in RFC 5280 section 4.2.1.2.r5   r8   r;   s    r=   AddSubjectKeyIdFlagr     s"    --3 Kr?   c                 l    [         R                  " SSR                  X5      US9R                  U 5        g )Nz
--validityz@The validity of this {}, as an ISO8601 duration. Defaults to {}.r5   rE   )r   r9   rZ   r:   )r<   resource_namedefault_valuedefault_value_texts       r=   AddValidityFlagr   )  s/     --
L6-4 Kr?   c                 v    [         R                  " SS[        R                  " 5       SS9R	                  U 5        g )N--issuance-policystorez6A YAML file describing this CA Pool's issuance policy.rD   rg   r5   rt   r;   s    r=   AddCaPoolIssuancePolicyFlagr   6  s/    --'')C	
 Kr?   c                 B    [         R                  R                  U 5        g rQ   )_ENCODING_FORMAT_MAPPER
choice_argr:   r;   s    r=   AddEncodingFormatFlagr   ?  s    $$008r?   c                 F    [        X5        [        X5        [        U 5        g rQ   )rO   rK   r   )r<   rI   s     r=   AddPublishingOptionsFlagsr   C  s    v4F1r?   c                 N    [         R                  " SSSS9R                  U 5        g )Nz--bucketzThe name of an existing storage bucket to use for storing the CA certificates and CRLs for CAs in this pool. If omitted, a new bucket will be created and managed by the service on your behalf.FrY   r8   r;   s    r=   AddBucketFlagr   I  s(    --O  Kr?   c                 R    [         R                  " SSSSSS9R                  U 5        g )Nz--ignore-active-certificateszIf this flag is set, the Certificate Authority will be deleted even if the Certificate Authority has un-revoked or un-expired certificates after the grace period.rB   Fr5   rD   rE   r6   r8   r;   s    r=   AddIgnoreActiveCertificatesFlagr   U  s.    --$J 
 Kr?   c                 R    [         R                  " SSSSSS9R                  U 5        g )Nz--skip-grace-periodzIf this flag is set, the Certificate Authority will be deleted as soon as possible without a 30-day grace period where undeletion would have been allowed. If you proceed, there will be no way to recover this CA.rB   Fr   r8   r;   s    r=   AddSkipGracePeriodFlagr   c  s-    --'
  Kr?   c                 R    [         R                  " SSSSSS9R                  U 5        g )Nz--ignore-dependent-resourcesac  This field skips the integrity check that would normally prevent breaking a CA Pool if it is used by another cloud resource and allows the CA Pool to be in a state where it is not able to issue certificates. Doing so may result in unintended and unrecoverable effects on any dependent resource(s) since the CA Pool would not be able to issue certificates.rB   Fr   r8   r;   s    r=   AddIgnoreDependentResourcesFlagr   r  s-    --$)  Kr?   c           	         [         R                  " SSSSS9R                  U 5        [         R                  " SSS[        R                  " [
        S	9S
9R                  U 5        [         R                  " SSS[        R                  " [
        S	9S9R                  U 5        [         R                  " SSS[        R                  " [
        S	9S9R                  U 5        [         R                  " SSS[        R                  " [
        S	9S9R                  U 5        [         R                  " SSS[        R                  " [
        S	9S9R                  U 5        [         R                  " SSS[        R                  " [
        S	9S9R                  U 5        [         R                  " SSS[        R                  " [
        S	9S
9R                  U 5        [         R                  " SSS [        R                  " [
        S	9S9R                  U 5        g!)"zhAdds flags for inline name constraint x509 parameters.

Args:
  parser: The parser to add the flags to.
z--name-constraints-criticalzIndicates whether or not name constraints are marked as critical. Name constraints are considered critical unless explicitly set to false.TrB   )r5   rE   rD   z--name-permitted-dnsaa  One or more comma-separated  DNS names which are permitted to be issued certificates. Any DNS name that can be constructed by simply adding zero or more labels to the left-hand side of the name satisfies the name constraint. For example, `example.com`, `www.example.com`, `www.sub.example.com` would satisfy `example.com`, while `example1.com` does not.NAME_PERMITTED_DNSrc   r5   rh   rg   z--name-excluded-dnsNAME_EXCLUDED_DNSad  One or more comma-separated DNS names which are excluded from being issued certificates. Any DNS name that can be constructed by simply adding zero or more labels to the left-hand side of the name satisfies the name constraint. For example, `example.com`, `www.example.com`, `www.sub.example.com` would satisfy `example.com`, while `example1.com` does not.r|   z--name-permitted-ipNAME_PERMITTED_IPzOne or more comma-separated IP ranges which are permitted to be issued certificates. For IPv4 addresses, the ranges are expressed using CIDR notation as specified in RFC 4632. For IPv6 addresses, the ranges are expressed in similar encoding as IPv4z--name-excluded-ipNAME_EXCLUDED_IPzOne or more comma-separated IP ranges which are excluded from being issued certificates. For IPv4 addresses, the ranges are expressed using CIDR notation as specified in RFC 4632. For IPv6 addresses, the ranges are expressed in similar encoding as IPv4z--name-permitted-emailNAME_PERMITTED_EMAILa'  One or more comma-separated email addresses which are permitted to be issued certificates. The value can be a particular email address, a hostname to indicate all email addresses on that host or a domain with a leading period (e.g. `.example.com`) to indicate all email addresses in that domain.z--name-excluded-emailNAME_EXCLUDED_EMAILa"  One or more comma-separated emails which are excluded from being issued certificates. The value can be a particular email address, a hostname to indicate all email addresses on that host or a domain with a leading period (e.g. `.example.com`) to indicate all email addresses in that domain.z--name-permitted-urizOne or more comma-separated URIs which are permitted to be issued certificates. The value can be a hostname or a domain with a leading period (like `.example.com`)NAME_PERMITTED_URIz--name-excluded-uriNAME_EXCLUDED_URIzOne or more comma-separated URIs which are excluded from being issued certificates. The value can be a hostname or a domain with a leading period (like `.example.com`)N)r   r9   r:   r   ro   rV   r;   s    r=   AddNameConstraintParameterFlagsr     s    --# 	 K--: #I6 K--!: I6 K--!A
 I6
 K-- A
 I6
 K--$0 I6 K--#0 I6 K--1 #I6	 K--!3 I6	 Kr?   c           
         U(       a  SOSnU R                  5       n[        R                  " SSSR                  U5      [        R
                  " [        [        S9S9R                  U5        [        R                  " SS	S
R                  U5      [        R
                  " [        [        S9S9R                  U5        UR                  SS9n[        U5        UR                  SS9n[        R                  " SSUS9R                  U5        [        R                  " SSSS9R                  U5        U(       d(  [        R                  " SSSSSS9R                  U5        gg)a  Adds flags for providing inline x509 parameters.

Args:
  parser: The parser to add the flags to.
  is_ca_command: Whether the current command is on a CA. This influences the
    help text, and whether the --is-ca-cert flag is added.
  default_max_chain_length: optional, The default value for maxPathLength to
    use if an explicit value is not specified. If this is omitted or set to
    None, no default max path length will be added.
CAcertificatez--key-usages
KEY_USAGESzhThe list of key usages for this {}. This can only be provided if `--use-preset-profile` is not provided.)rd   choicesr|   z--extended-key-usagesEXTENDED_KEY_USAGESzqThe list of extended key usages for this {}. This can only be provided if `--use-preset-profile` is not provided.z(The x509 name constraints configurationsr   T)r   z--max-chain-lengthzMaximum depth of subordinate CAs allowed under this CA for a CA certificate. This can only be provided if neither `--use-preset-profile` nor `--unconstrained-chain-length` are provided.r   z--unconstrained-chain-lengthzIf set, allows an unbounded number of subordinate CAs under this newly issued CA certificate. This can only be provided if neither `--use-preset-profile` nor `--max-chain-length` are provided.rB   )r5   rD   z--is-ca-certzWhether this certificate is for a CertificateAuthority or not. Indicates the Certificate Authority field in the x509 basic constraints extension.F)r5   r6   rE   rD   N)r   r   r9   rZ   r   ro   rV   _VALID_KEY_USAGESr:   _VALID_EXTENDED_KEY_USAGESr   )r<   is_ca_commanddefault_max_chain_lengthr   groupname_constraints_groupchain_length_groups          r=   AddInlineX509ParametersFlagsr     sW    ($]-



%--55;VM5J *;
 K--#AAGB  *D K ??5 +  ""89T2--
 '	 K"#--$K  K"#	MM& 
 k% 
r?   c                     [         R                  " SSS9R                  U 5        [         R                  " SSSUS9R                  U 5        [         R                  " SS	SUS9R                  U 5        g
)zAdds flags for expressing identity constraints.

Args:
  parser: The argparse object to add the flags to.
  require_passthrough_flags: Whether the boolean --copy-* flags should be
    required.
z--identity-cel-expressionzA CEL expression that will be evaluated against the identity in the certificate before it is issued, and returns a boolean signifying whether the request should be allowed.r   z--copy-subjectzIf this is specified, the Subject from the certificate request will be copied into the signed certificate. Specify --no-copy-subject to drop any caller-specified subjects from the certificate request.rB   r_   z--copy-sanszIf this is specified, the Subject Alternative Name extension from the certificate request will be copied into the signed certificate. Specify --no-copy-sans to drop any caller-specified SANs in the certificate request.Nr8   )r<   require_passthrough_flagss     r=   AddIdentityConstraintsFlagsr   A  st     --!> K--!
 (
 K--!
 (
 Kr?   c           	          [         R                  " SSS[        R                  " [        S9S9R                  U 5        [         R                  " SSS[        R                  " [        S9S9R                  U 5        g	)
zzAdds flags for specifying user defined access URLs, such as CDP and AIA.

Args:
  parser: The parser to add the flags to.
z--custom-aia-urlszOne or more comma-separated URLs that will be added to the Authority Information Access extension in the issued certificate. These URLs are where the issuer CA certificate is located.CUSTOM_AIA_URLSrc   r   z--custom-cdp-urlszOne or more comma-separated URLs that will be added to the CRL Distribution Points (CDP) extension in the issued certificate. These URLs are where CRL information is located.CUSTOM_CDP_URLSNrn   r;   s    r=   AddUserDefinedAccessUrlsFlagsr   k  sk     --H  I6	 K-->  I6	 Kr?   c            	         [         R                  " S5      R                  R                  n [        R
                  " SU R                  4SU R                  4SU R                  4SU R                  4SU R                  4SU R                  445      $ )Nv1zbase-key-usagezextended-key-usagez
ca-optionsz
policy-idszaia-ocsp-serversr    )privateca_baseGetMessagesModuleCertificateExtensionConstraints'KnownExtensionsValueListEntryValuesEnumcollectionsOrderedDictBASE_KEY_USAGEEXTENDED_KEY_USAGE
CA_OPTIONS
POLICY_IDSAIA_OCSP_SERVERSNAME_CONSTRAINTS)	enum_types    r=   GetKnownExtensionMappingr     s    ..
##$K$K  
	 	 112Y99:Y))*Y))*95569556" 
 r?   c                     [         R                  " S5      R                  [        R                  " U 5      R                  5       R                  S5       Vs/ s H  n[        U5      PM     snS9$ s  snf )Nr   .)objectIdPath)r   r   ObjectIdrR   rS   rT   splitint)rU   parts     r=   _StrToObjectIdr     s]    		)	)$	/	8	8*---*<*B*B*D*J*J3*OP*O$CI*OP 
9 
 Ps   A/c           	         [         R                  " U5      R                  5       R                  5       n[	        5       nX#;   a  X2   $ [
        R                  " U SR                  SR                  UR                  5       5      5      5      e)Nzexpected one of [{}],)
rR   rS   rT   lowerr   r	   UnknownArgumentExceptionrZ   r[   keys)arg_namerU   trimmed_valknown_extensionss       r=   _StrToKnownExtensionr     sq    c"((*002+-/$((

-
-%%chh/?/D/D/F&GH r?   c           	         U R                  SSSS9nUR                  SSSS9n[        R                  " SS[        R                  " [
        S9S	S
9R                  U5        [        5       n[        R                  " SS[        R                  " UR                  5       [        S9SS
9R                  U5        [        R                  " SSSSS9R                  U5        g)ziAdds flags for expressing extension constraints.

Args:
  parser: The argparser to add the arguments to.
TFzConstraints on requested X.509 extensions. If unspecified, all extensions from certificate request will be ignored when signing the certificate.r   r6   r5   @Specify exact x509 extensions to copy by OID or known extension.--copy-extensions-by-oid|If this is set, then extensions with the given OIDs will be copied from the certificate request into the signed certificate.rc   	OBJECT_IDrf   --copy-known-extensionsrIf this is set, then the given extensions will be copied from the certificate request into the signed certificate.r   hidden_choicesKNOWN_EXTENSIONS--copy-all-requested-extensionszpIf this is set, all extensions specified in the certificate  request will be copied into the signed certificate.store_constr5   rD   constN
r   r   r9   r   ro   r   r:   r   r   _HIDDEN_KNOWN_EXTENSIONS)r<   extension_group
copy_groupr   s       r=   AddExtensionConstraintsFlagsr     s     $$	 % / ((M ) * -- F N; K
-/--F "'')1 ! K
--'A  K r?   c                 L    [         R                  " SSS9R                  U 5        g)ztAdds flag for specifying maximum lifetime in cert template.

Args:
  parser: The argparser to add the arguments to.
z--maximum-lifetimea  If this is set, then issued certificate's lifetime will be truncated to the value provided. If the issuing CaPool's IssuancePolicy specifies a maximum lifetime the minimum of the two durations will be the maximum lifetime for the issued certificate. Note that if the issuing CertificateAuthority expires before a Certificate's requested maximum_lifetime, the effective lifetime will be explicitly truncated to match it.r   Nr8   r;   s    r=   AddMaximumLifetimeFlagr     s$     --/ Kr?   c           	         SnU R                  SSUS9nUR                  SSSS9nUR                  SSSS9n[        R                  " SS[        R                  " [
        S	9S
S9R                  U5        [        R                  " SSSSS9R                  U5        UR                  SSSS9n[        5       n[        R                  " SS[        R                  " UR                  5       [        S9SS9R                  U5        [        R                  " SSSSS9R                  U5        [        R                  " SSSSS9R                  U5        g)zgAdds flags for updating extension constraints.

Args:
  parser: The argparser to add the arguments to.
z*Constraints on requested X.509 extensions.TFr   r   z0Constraints on unknown extensions by their OIDs.r   r   rc   r   rf   z--drop-oid-extensionszIf this is set, then all existing OID extensions will be removed from the template, prohibiting any extensions specified by OIDs to be specified by the requester.r   r   z Constraints on known extensions.r   r   r   r   z--drop-known-extensionszIf this is set, then all known extensions will be removed from the template, prohibiting any known x509 extensions to be specified by the requester.r   zIf this is set, all extensions, whether known or specified by OID, that are specified in the certificate request will be copied into the signed certificate.Nr   )r<   extension_group_helpr   r   	oid_groupknown_groupr   s          r=   %AddExtensionConstraintsFlagsForUpdater     s    F$$5'; % / ((M ) * ""= # ) -- F N; K	--3 	 K	$$5'I % + ./--F "'')1 ! K--+ 	 K--') 	 K r?   c                 v    [         R                  " SS[        R                  " 5       SS9R	                  U 5        g)zOAdds a flag for the predefined x509 extensions file for a Certificate Template.--predefined-values-filer   a8  A YAML file describing any predefined X.509 values set by this template. The provided extensions will be copied over to any certificate requests that use this template, taking precedent over any allowed extensions in the certificate request. The format of this file should be a YAML representation of the X509Parameters message, which is defined here: https://cloud.google.com/certificate-authority-service/docs/reference/rest/v1/X509Parameters. Some examples can be found here: https://cloud.google.com/certificate-authority-service/docs/creating-certificate-templater   Nrt   r;   s    r=   AddPredefinedValuesFileFlagr  G  s4     -- '')f Kr?   c                     U R                  S5      (       d  g[        R                  " S5      nUR                  U R                  S9$ )z)Parses the encryption-key flag from args.encryption_keyNr   )cloudKmsKey)IsSpecifiedr   r   EncryptionSpecr  argsr   s     r=   ParseEncryptionSpecr	  `  sA    			*	+	+--d3(		 	 T-@-@	 	AAr?   c                     [         R                  " S5      nUR                  U R                  U R                  U R                  S5      (       a  UR                  U R                  S9S9$ SS9$ )zGParses the identity flags into a CertificateIdentityConstraints object.r   identity_cel_expression)
expressionN)allowSubjectPassthroughallowSubjectAltNamesPassthroughcelExpression)r   r   CertificateIdentityConstraintscopy_subject	copy_sansr  Exprr  r  s     r=   ParseIdentityConstraintsr  j  sv    --d3(		0	0"//&*nn			3	4	4 MMT-I-IMJ 
1 
 
  
1 
 r?   c                    U R                  S5      (       a  g[        R                  " S5      n/ nU R                  S5      (       d<  U R                  S5      (       a&  U R                   Vs/ s H  n[        SU5      PM     nn/ nU R                  S5      (       d"  U R                  S5      (       a  U R                  nUR                  X$S	9$ s  snf )
a  Parse extension constraints flags into CertificateExtensionConstraints API message.

Assumes that the parser defined by args has the flags
copy_all_requested_extensions, copy_known_extesnions, and
copy-extensions-by-oid. Also supports drop_known_extensions and
drop_oid_extensions for clearing the extension lists.

Args:
  args: The argparse object to read flags from.

Returns:
  The CertificateExtensionConstraints API message.
copy_all_requested_extensionsNr   drop_known_extensionscopy_known_extensionsr   drop_oid_extensionscopy_extensions_by_oid)knownExtensionsadditionalExtensions)r  r   r   IsKnownAndSpecifiedr  r   r  r   )r  r   
known_extsextoidss        r=   ParseExtensionConstraintsr!  w  s     
566--d3(*		!	!"9	:	:t?O?O@ @
 ---C 	6<-  
 
$		!	!"7	8	8T=M=M> > &&D		1	1  
2 
 s   *Cc                     U R                  S5      (       d  g[        R                  " [        R                  " U R                  5      5      $ )zParses the maximum_lifetime flag from args.

Args:
  args: The argparse object to read flags from.

Returns:
  The JSON formatted duration of the maximum lifetime or none.
maximum_lifetimeN)r  r   FormatDurationForJsonParseDurationr#  r  s    r=   ParseMaximumLifetimer'    s;     
		,	-	-		$	$U%8%89N9N%O	PPr?   c                    U R                  S5      (       d  g [        R                  " U R                  [        R
                  " S5      R                  5      $ ! [        R                  [        4 a    [        R                  " SS5      ef = f)zOParses an X509Parameters proto message from the predefined values file in args.predefined_values_fileNr   r   z.Unrecognized field in the X509Parameters file.)r  messages_utilDictToMessageWithErrorCheckr)  r   r   X509ParametersDecodeErrorAttributeErrorr	   InvalidArgumentExceptionr&  s    r=   ParsePredefinedValuesr0    s    			2	3	344##((.==  
#
#^	4 

-
-"8    >A 2B
c                 N   U R                   nSSSSSSS.n0 nUR                  5        H  u  pEXB;   a  XSX$   '   M  XSU'   M      [        R                  " U[        R
                  " S5      R                  5      $ ! [        R                   a    [        R                  " S	S
5      ef = f)zParses a dictionary with subject attributes into a API Subject type.

Args:
  args: The argparse namespace that contains the flag values.

Returns:
  Subject: the Subject type represented in the api.

commonNamecountryCodeprovincelocalityorganizationorganizationalUnit)CNCSTLOOUr   rx   zUnrecognized subject attribute.)
subjectitemsr*  r+  r   r   Subjectr-  r	   r/  )r  subject_args
remap_argsmapped_argskeyrU   s         r=   ParseSubjectrF    s     , * +$$&hc
%(*/"#	 '44^55d;CC  
	"	" 

-
-6 s   4A8 8,B$c                    / / / / 4u  pp4U R                  S5      (       a#  [        [        [        U R                  5      5      nU R                  S5      (       a#  [        [        [
        U R                  5      5      nU R                  S5      (       a#  [        [        [        U R                  5      5      nU R                  S5      (       a  U R                  n[        R                  " S5      R                  UUUUS9$ )zValidates the san flags and creates a SubjectAltNames message from them.

Args:
  args: The parser that contains the flags.

Returns:
  The SubjectAltNames message with the flag data.
	email_sandns_sanip_sanuri_sanr   )emailAddressesdnsNamesipAddressesuris)r  listmapValidateEmailSanFlagrH  ValidateDnsSanFlagrI  ValidateIpSanFlagrJ  rK  r   r   SubjectAltNames)r  email_addresses	dns_namesip_addressesrO  s        r=   ParseSanFlagsrY    s     46r2r>0/l	k""33T^^DEO	i  S+T\\:;I	h-t{{;<L	i  <<D		)	)$	/	?	?$	 
@ 
 r?   c                 n   U R                   =(       d    U R                  S5      (       + =(       a    UnU R                  =(       d    U R                  S5      (       + =(       a    UnU(       a  SnOSnUS-  nU(       d9  U(       d1  [        R                  " USS9(       d  [
        R                  " S5      eg	g	g	)
a  Validates the template identity constraints flags.

Args:
  args: the parser for the flag. Expected to have copy_sans and copy_subject
    registered as flags
  existing_copy_subj: A pre-existing value for the subject value, if
    applicable.
  existing_copy_sans: A pre-existing value for the san value, if applicable.
  for_update: Whether the validation is for an update to a template.
r  r  zIThe resulting updated template will have no subject or SAN passthroughs. z2Neither copy-sans nor copy-subject was specified. z]This means that all certificate requests that use this template must use identity reflection.T)messagerE   zAborted by user.N)r  r  r  r   PromptContinueprivateca_exceptionsUserAbortException)r  existing_copy_subjexisting_copy_sans
for_updatecopy_san	copy_subjmissing_identity_conf_msgs          r=   ValidateIdentityConstraintsre    s     ^^ 


;
''>,>   


>
**A/A  	  	=  !
 ''+T 
1
12D
EE	  r?   c                    / nU R                   (       aV  U R                   R                  U R                   R                  U R                   R                  U R                   R                  /nU R
                  R                  (       dY  [        U Vs/ s H	  o"(       + PM     sn5      (       a3  U R
                  R                  (       d  [        R                  " SS5      egggs  snf )z!Validates a SubjectConfig object.rx   z^The certificate you are creating does not contain a common name or a subject alternative name.N)subjectAltNamerL  rM  rN  rO  r?  r3  allrdnSequencer	   r/  )subject_config	san_nameselems      r=   ValidateSubjectConfigrm  )  s    )""%%44%%..%%11%%**	I 
 
 
+
+
I.IDxI.
/
/$$00

-
-	%  1 0 ,.s   Cc                 z   [         R                  " S5      nUR                  UR                  5       UR	                  5       S9nU R                  S5      (       a  [        U 5      Ul        O&U R                  S5      (       a  [        U 5      Ul        [        U 5      (       a  [        U 5      Ul        [        U5        U$ )zParses subject flags into a subject config.

Args:
  args: The parser that contains all the flag values

Returns:
  A subject config representing the parsed flags.
r   )r?  rg  r?  subject_file)r   r   SubjectConfigrA  rU  r  rF  r?  ParseSubjectFileSanFlagsAreSpecifiedrY  rg  rm  )r  r   rj  s      r=   ParseSubjectFlagsrs  ?  s     --d3()) 1I1I1K * . 
i  )$/N''-d3N$$1$$7N!'	r?   c           	          [        S Vs/ s H)  nU[        U 5      ;   =(       a    U R                  U5      PM+     sn5      $ s  snf )z,Returns true if any san flags are specified.)rI  rH  rJ  rK  anyvarsr  r  flags     r=   rr  rr  Y  sK    	??$ d4j3T--d33? 
     0Ac                    U R                  S5      (       d  g [        R                  " U R                  [        R
                  " S5      R                  5      $ ! [        R                  [        4 a    [        R                  " SS5      ef = f)z5Parses an IssuancePolicy proto message from the args.issuance_policyNr   r   z*Unrecognized field in the Issuance Policy.)r  r*  r+  r|  r   r   IssuancePolicyr-  r.  r	   r/  r&  s    r=   ParseIssuancePolicyr~  a  s    			+	,	,
44((.==  
#
#^	4 

-
-I r1  c                      [         R                  " U R                  [        R                  " S5      R
                  5      $ ! [         R                  [        4 a    [        R                  " SS5      ef = f)zAParses an a Subject from a file to a proto message from the args.r   rr   z"Unrecognized field in the Subject.)
r*  r+  ro  r   r   rA  r-  r.  r	   r/  r&  s    r=   rq  rq  r  sl    44((.66  
#
#^	4 

-
-> s   >A 2A3c                 @    [         R                  U R                  5      $ rQ   )r   GetEnumForChoicepublishing_encoding_formatr&  s    r=   ParseEncodingFormatFlagr    s    	 	1	1
%%
 r?   c                    [         R                  " S5      nU R                  nU R                  n[	        U 5      nU R                  S5      =(       a,    [        U 5      UR                  R                  R                  :H  nU(       a6  U R                  S5      (       a  U(       a  [        R                  " SS5      eSnUR                  UUUS9$ )z8Parses the PublshingOptions proto message from the args.r   tierpublish_crlrA   z4CRL publication is not supported in the DevOps tier.F)publishCaCert
publishCrlencodingFormat)r   r   publish_ca_certr  r  r  ParseTierFlagCaPoolTierValueValuesEnumDEVOPSr  r	   r/  PublishingOptions)r  r   r  r  encoding_formatis_devops_tiers         r=   ParsePublishingOptionsr    s    --d3(((/  ++D1/++F3 DX__@@GGG  &&;//

@ 
 K		#	##$ 
$ 
 r?   c                 t    [         R                  " [        U 5      (       d  [        R                  " SS5      eU $ )Nrb   zInvalid email address.)rematch_EMAIL_SAN_REGEXr	   r/  sans    r=   rR  rR    s4    	"C	(	(

-
-/  
*r?   c                 t    [         R                  " [        U 5      (       d  [        R                  " SS5      eU $ )Nrk   zInvalid domain name value)r  r  _DNS_SAN_REGEXr	   r/  r  s    r=   rS  rS    s3    	.#	&	&

-
-0  
*r?   c                 ~     [         R                  " U 5        U $ ! [         a    [        R                  " SS5      ef = f)Nri   zInvalid IP address value.)	ipaddress
ip_address
ValueErrorr	   r/  r  s    r=   rT  rT    sF    
 
*	 
 

-
-/ s    "<unspecifiedzkey-compromisez certificate-authority-compromisezaffiliation-changed
supersededzcessation-of-operationzcertificate-holdzprivilege-withdrawnzattribute-authority-compromise)	REVOCATION_REASON_UNSPECIFIEDKEY_COMPROMISE CERTIFICATE_AUTHORITY_COMPROMISEAFFILIATION_CHANGED
SUPERSEDEDCESSATION_OF_OPERATIONCERTIFICATE_HOLDPRIVILEGE_WITHDRAWNATTRIBUTE_AUTHORITY_COMPROMISEz--reasonz(Revocation reason to include in the CRL.r   )r   rE   help_strmessage_enumcustom_mappingspemder)PEMDERz--publishing-encoding-formatz@The encoding format of the content published to storage buckets.
enterprisedevops)
ENTERPRISEr  z--tierz'The tier for the Certificate Authority.zrsa-pss-2048-sha256zrsa-pss-3072-sha256zrsa-pss-4096-sha256zrsa-pkcs1-2048-sha256zrsa-pkcs1-3072-sha256rsa-pkcs1-4096-sha256zec-p256-sha256zec-p384-sha384)RSA_PSS_2048_SHA256RSA_PSS_3072_SHA256RSA_PSS_4096_SHA256RSA_PKCS1_2048_SHA256RSA_PKCS1_3072_SHA256RSA_PKCS1_4096_SHA256EC_P256_SHA256EC_P384_SHA384z--key-algorithmzYThe crypto algorithm to use for creating a managed KMS key for the Certificate Authority.)r   r  r  r  c                 B    [         R                  R                  U 5        g)zjAdd a revocation reason enum flag to the parser.

Args:
  parser: The argparse parser to add the flag to.
N)_REVOCATION_REASON_MAPPERr   r:   r;   s    r=   AddRevocationReasonFlagr    s     &&226:r?   c                 ,    [         R                  U 5      $ )zReturn the apitools revocation reason enum value from the string choice.

Args:
  choice: The string value of the revocation reason.

Returns:
  The revocation enum value for the choice text.
)r  r  )choices    r=   ParseRevocationChoiceToEnumr    s     
#	3	3F	;;r?   c                 j    [         R                  " [         R                  " U R                  5      5      $ )zParses the validity from args.)r   r$  r%  validityr&  s    r=   ParseValidityFlagr     s"    		$	$U%8%8%G	HHr?   c                 B    [         R                  R                  U 5        g rQ   )_TIER_MAPPERr   r:   r;   s    r=   AddTierFlagr  %  s    %%f-r?   c                 @    [         R                  U R                  5      $ rQ   )r  r  r  r&  s    r=   r  r  )  s    		&	&tyy	11r?   c                     [         R                  R                  U 5        [         R                  R                  X5        g rQ   )_KEY_ALGORITHM_MAPPERr   r:   
SetDefault)parser_grouprE   s     r=   AddKeyAlgorithmFlagr  -  s*    ""..|<""--lDr?   c                 4   [         R                  " S5      nU R                  S5      (       aA  U R                  R                  R                  5       nUR                  UR                  5       S9$ UR                  [        R                  U R                  5      S9$ )zHParses a specified KMS key version or algorithm to get a KeyVersionSpec.r   kms_key_version)cloudKmsKeyVersion)	algorithm)r   r   r  CONCEPTSr  ParseKeyVersionSpecRelativeNamer  r  key_algorithm)r  r   kms_key_version_refs      r=   ParseKeySpecr  2  s    --d3(	'((--77==?"".;;= #   
	 	 %66t7I7IJ 
! 
 r?   c                     0 n[         R                  5        H*  u  p4U R                  U5      (       d  M  [        X5      X$'   M,     U(       d  gU R                  U[
        '   [        R                  " X!R                  S9$ )zParses the name constraints in x509Parameters.

Args:
  args: The parsed argument values
  messages: PrivateCA's messages modules

Returns:
  A NameConstraints message object
Nmessage_type)	_NAME_CONSTRAINT_MAPPINGSr@  r  getattrname_constraints_critical_NAME_CONSTRAINT_CRITICALr*  r+  NameConstraints)r  r   name_constraint_dictconstraint_arg
constraints        r=   ParseNameConstraintsr  @  s|     $=$C$C$E n//)0)F& %F 
 $$ 01 
	2	2)A)A
 r?   c                     U R                  S5      (       d  gU R                  n[        R                  " [        U5      (       d  [
        R                  " SS5      eUR                  US9$ )zParses the subject key id for input into CertificateConfig.

Args:
  args: The parsed argument values
  messages: PrivateCA's messages modules

Returns:
  A CertificateConfigKeyId message object
subject_key_idNr   z;Subject key id must be an even length lowercase hex string.)keyId)r  r  r  r  _SKID_REGEXr	   r/  CertificateConfigKeyId)r  r   skids      r=   ParseSubjectKeyIdr  Z  sd     
		*	+	+			$	+t	$	$

-
-E  
	(	(t	(	44r?   c           	      b   U R                  S5      n/ SQ[        [        R                  5       5      -   n[	        U Vs/ s H  o@R                  U5      PM     sn5      nU(       a  U(       a  [
        R                  " SS5      eU(       a   [        R                  " U R                  5      $ U R                  (       a  SU l        U R                  =(       d    / nU=(       d$    U R                  S5      =(       a    U R                  nU(       a  UR                  SS/5        0 nU H  n	[        R                   " U	5      n	S	X'   M     0 n
U R"                  =(       d    /  H  n[        R                   " U5      nS	X'   M     [$        R&                  " S
5      nUR)                  UR+                  [,        R.                  " XR0                  5      [,        R.                  " XR2                  5      S9UR5                  UU(       a"  U R                  b  [7        U R                  5      OSS9[9        X5      S9$ s  snf )zParses the X509 parameters flags into an API X509Parameters.

Args:
  args: The parsed argument values.
  is_ca_command: Whether the current command is on a CA. If so, certSign and
    crlSign key usages are added.

Returns:
  An X509Parameters object.
use_preset_profile)
key_usagesextended_key_usagesmax_chain_length
is_ca_certunconstrained_chain_lengthrX   z--use-preset-profile may not be specified if one or more of --key-usages, --extended-key-usages, --unconstrained_chain_length or --max-chain-length are specified.Nr  r*   r+   Tr   )baseKeyUsageextendedKeyUsage)isCamaxIssuerPathLength)keyUsage	caOptionsnameConstraints)r  rP  r  r   rv  r	   r/  r
   GetPresetX509Parametersr  r  r  r  r  extendr   SnakeCaseToCamelCaser  r   r   r,  KeyUsager*  r+  KeyUsageOptionsExtendedKeyUsageOptions	CaOptionsr   r  )r  r   preset_profile_setinline_argsry  has_inline_valuesbase_key_usagesis_cakey_usage_dict	key_usageextended_key_usage_dictextended_key_usager   s                r=   ParseX509Parametersr  p  s    //0DE $))+,-+ 2=>+$%+> -

-
-	,  2243J3JKK	$$ DOO)r/
 
|,@  K45."i//	:I $N #  44::#889KL26/ ; --d3(		 	   $@@66 )DD%'G'G	 !  "" t,,8 "$"7"78 #  +4:! 
! 
 A ?s   H,c           	          [        S Vs/ s H)  nU[        U 5      ;   =(       a    U R                  U5      PM+     sn5      $ s  snf )z4Returns true if any x509 config flags are specified.)r  r  r  r  r  r  ru  rx  s     r=   X509ConfigFlagsAreSpecifiedr    sQ    	
$ d4j3T--d33
 

 
 
rz  c                     0 n[         R                  5        H*  u  p4U R                  U5      (       d  M  [        X5      X$'   M,     U(       d  g[        R
                  " X!R                  S9$ )zParses the user defined access URLs into a UserDefinedAccessUrls message.

Args:
  args: The parsed argument values
  messages: PrivateCA's messages modules

Returns:
  A UserDefinedAccessUrls message object
Nr  )"_USER_DEFINED_ACCESS_URLS_MAPPINGSr@  r  r  r*  r+  UserDefinedAccessUrls)r  r   user_defined_access_urlsurl_arg	url_fields        r=   ParseUserDefinedAccessUrlsr    sd      >DDFg((,3D,B) G 
"		2	2-K-K
 r?   )F)P10Yz10 yearsrQ   )T)FFF)r  )z__doc__
__future__r   r   r   r   r  r  
frozendict googlecloudsdk.api_lib.privatecar   r   googlecloudsdk.api_lib.utilr   r*  googlecloudsdk.callioper   r	   $googlecloudsdk.command_lib.privatecar]  r
   r   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   rR   r  r  	frozensetr   r  compiler  r  r  rN   rM   rG   rF   r   r   r>   rK   rO   rV   r]   r`   rp   rv   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r!  r'  r0  rF  rY  re  rm  rs  rr  r~  rq  r  r  rR  rS  rT  _REVOCATION_MAPPINGChoiceEnumMapperr   RevokeCertificateRequestReasonValueValuesEnumr  _ENCODING_FORMAT_MAPPINGr  EncodingFormatValueValuesEnumr   _TIER_MAPPINGr  r  r  _KEY_ALGORITHM_MAPPINGr  AlgorithmValueValuesEnumr  r  r  r  r  r  r  r  r  r  r  r  r   r?   r=   <module>r,     s   / &  '   	  C A / ( . S @ ; : 2 * 
& &11,*53)'-+	3 	  %&8%9: %/%:%:2&< & "
 ::o. 01jj12 
   
  *$
	D	* 	 EO
9 	"k^ 59M`'T8	5!p*P!f2B
#LQ$!H: JO(FV,4" : &3&(J06*0&F
  &6671144'   
 $44+O1155,  
 ))611f  ! 100444&&	  "22	%  11n--*
 ;	<I
.2E
45,IXr?   