
    //                        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 ddlm	Z ddlmZ ddlmZ ddlZ ej6                  ej8                  j:                  j<                        Z ej6                  ej8                  j@                  jB                        Z"d Z#d#dZ$d$dZ%	 d%dZ&d&dZ'd'dZ(d Z)	 	 	 	 	 d(dZ*	 	 	 d)dZ+d$dZ,d Z-d Z.d Z/d Z0d Z1d*d Z2d*d!Z3d" Z4y)+z'Helpers for parsing resource arguments.    )absolute_import)division)unicode_literals)base)	locations)
exceptions)concepts)deps)handlers)util)resource_args)
completers)concept_parsers)
propertiesNc                  .    t        j                  d      S )Nzcertificate template)namer	    ResourceParameterAttributeConfig     9lib/googlecloudsdk/command_lib/privateca/resource_args.py"CertificateTemplateAttributeConfigr   ,   s    		2	28N	OOr   c                 :    t        j                  | d|xs g       S )Nz%The parent CA Pool of the {resource}.r   	help_textfallthroughsr   )display_namer   s     r   CaPoolAttributeConfigr   1   s#    		2	27%2
 r   c                 8    t        j                  d| xs g       S )Ncertificate)r   r   r   r   s    r   CertAttributeConfigr"   :   s!     
	2	2|'9r
 r   c                 >    |xs g }t        j                  | d|      S )Nz4The issuing certificate authority of the {resource}.r   r   arg_namer   s     r   CertAuthorityAttributeConfigr&   B   s*     #,		2	2F
 r   c                 f    |xs t         g}t        j                  | dt        j                  |      S )NzThe location of the {resource}.)r   r   	completerr   )LOCATION_PROPERTY_FALLTHROUGHr	   r   privateca_completersLocationsCompleterr$   s     r   LocationAttributeConfigr,   M   s5    @"?!@,		2	21$77	
 r   c                 :    t        j                  | d|xs g       S )a  DO NOT USE THIS for most flags.

  This config is only useful when you want to provide an explicit project
  fallthrough. For most cases, prefer concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG.

  Args:
    arg_name: Name of the flag used to specify this attribute. Defaults to
      'project'.
    fallthroughs: List of deps.Fallthrough objects to provide project values.

  Returns:
    A concepts.ResourceParameterAttributeConfig for a project.
  z&The project containing the {resource}.r   r   r$   s     r   ProjectAttributeConfigr.   W   s%     
	2	28%2
 r   c                  >   t        j                  ddt        j                  d      t        j                  d      t        j
                  d      t        dt        j                  d      t        g      t        dt        j                  d      t        g      	      S )
zCreates a resource spec for a KMS CryptoKeyVersion.

  Defaults to the location and project of the CA, specified through flags or
  properties.

  Returns:
    A concepts.ResourceSpec for a CryptoKeyVersion.
  zAcloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersionszkey versionT)
kms_prefixzkms-locationlocationzkms-projectproject)resource_namecryptoKeyVersionsIdcryptoKeysId
keyRingsIdlocationsId
projectsId)r	   ResourceSpeckms_argsKeyVersionAttributeConfigKeyAttributeConfigKeyringAttributeConfigr,   r
   ArgFallthroughr)   r.   PROJECT_PROPERTY_FALLTHROUGHr   r   r   CreateKmsKeyVersionResourceSpecr@   l   s     
		I!"<<M..$?00DA)
z*,I
J (
y)+G
H
 r   c                     t        j                  dd| t        ||      t        |      t	        ||      t         j
                  d      S )Nz;privateca.projects.locations.caPools.certificateAuthoritiesv1r!   T)api_versionr3   certificateAuthoritiesId	caPoolsIdr7   r8   disable_auto_completers)r	   r9   r&   r   r,    DEFAULT_PROJECT_ATTRIBUTE_CONFIG)r   certificate_authority_attributelocation_attributelocation_fallthroughspool_id_fallthroughsca_id_fallthroughss         r   CreateCertAuthorityResourceSpecrM      sU     
		C ;
)8J  &3GH)
+@ ::"
 r   c           
          t        j                  dd| t        |      t        ||      t         j                  d      S )Nz$privateca.projects.locations.caPoolsrB   r!   T)rC   r3   rE   r7   r8   rF   )r	   r9   r   r,   rG   )r   rI   rK   rJ   s       r   CreateCaPoolResourceSpecrO      sE     
		, %3GH)
+@ ::"
 r   c           
          t        j                  dd| t        |xs g       t        d      t	        d      t         j
                  d      S )Nz1privateca.projects.locations.caPools.certificatesrB   r!   zissuer-poolzissuer-locationF)rC   r3   certificatesIdrE   r7   r8   rF   )r	   r9   r"   r   r,   rG   )r   id_fallthroughss     r   CreateCertResourceSpecrS      sH    			9 (o6KL%m4)*;<::#

 
r   c           	      v    t        j                  dd| t               t               t         j                  d      S )Nz1privateca.projects.locations.certificateTemplatesrB   T)rC   r3   certificateTemplatesIdr7   r8   rF   )r	   r9   r   r,   rG   )r   s    r   %CreateCertificateTemplateResourceSpecrV      s6    			9 ?A)+::"	
 	r   c                     d}t         j                  j                  |t        |      dj	                  |      d      j                  |        y)a  Add a positional resource argument for a GA Certificate Authority.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  CERTIFICATE_AUTHORITYzThe certificate authority {}.TrequiredN)r   ConceptParserForResourcerM   formatAddToParserparserverbr%   s      r   %AddCertAuthorityPositionalResourceArgrb      sJ     %(++%h/%,,T2	 , 
 Kr   c                     d}t         j                  j                  |t        |      dj	                  |      d      j                  |        y)zAdd a positional resource argument for a CA Pool.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  CA_POOLzThe ca pool {}.TrY   N)r   r[   r\   rO   r]   r^   r_   s      r   AddCaPoolPositionalResourceArgre      sJ     (++x(t$	 , 
 Kr   c                     d}t         j                  j                  |t        |      dj	                  |      d      j                  |        y)zAdd a positional resource argument for a GA Certificate.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  CERTIFICATEzThe certificate {}.TrY   N)r   r[   r\   rS   r]   r^   r_   s      r   AddCertPositionalResourceArgrh      sJ     (++X&""4(	 , 
 Kr   c                     d}t         j                  j                  |t        |      dj	                  |      d      j                  |        y)a  Add a positional resource argument for a certificate template.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  CERTIFICATE_TEMPLATEzThe template {}.TrY   N)r   r[   r\   rV   r]   r^   r_   s      r   +AddCertificateTemplatePositionalResourceArgrk     sJ     $(+++H5%	 , 
 Kr   c           
          t        j                  |      }| j                  |vr=t        j                  |dj                  dj                  t        |                        y)zHRaises an exception if the given resource is in an unsupported location.)versionzDResource is in an unsupported location. Supported locations are: {}.z, N)r   GetSupportedLocationsr7   r   InvalidArgumentExceptionr]   joinsorted)resource_refr%   rm   supported_locationss       r   ValidateResourceLocationrt     sY    !77H%88

-
-N			&!456	7  9r   c                 &   t        j                  |      j                  j                  }| |j                  k(  r$|j
                  | k7  rt        j                  d      | |j                  k(  r%|j
                  | k7  rt        j                  d      yy)zRaises an exception if the Certificate Authority type is not expected_type.

  Args:
    expected_type: The expected type.
    ca: The ca object to check.
    version: The version of the API to check against.
  )rC   zgCannot perform subordinates command on Root CA. Please use the `privateca roots` command group instead.znCannot perform roots command on Subordinate CA. Please use the `privateca subordinates` command group instead.N)	r   GetMessagesModuleCertificateAuthorityTypeValueValuesEnumSUBORDINATEtypeprivateca_exceptions$InvalidCertificateAuthorityTypeErrorSELF_SIGNED)expected_typecarm   ca_type_enums       r   CheckExpectedCATyper   '  s     '',,  l...277m3K

C
C	4  000RWW5M

C
C	;  6N0r   c                    t        | j                  |      sy| j                  j                  |      }|j                  j	                         D cg c]  }t        j                  |       }}|D cg c]  }| j                  |      s| c}sy	 |j                          d|_	        |j                  |        yc c}w c c}w # t        j                  $ r.}t        j                  |t        j                   |            d}~ww xY w)zJRaises a ParseError if the given resource_arg_name is partially specified.NF)hasattrCONCEPTSArgNameToConceptInfoattribute_to_args_mapvaluesr   NamespaceFormatIsSpecified
ClearCacheallow_emptyParser	   InitializationErrorr   
ParseErrorsix	text_type)argsresource_arg_nameconcept_infoargassociated_argses         r   %ValidateResourceIsCompleteIfSpecifiedr   >  s    	 1	2
334EF, 33::<<# 3<   )	B#D,<,<S,A#	B
C $Lt 
C 
	%	% C


/q1A
BBCs*   B:1B?B?(C D)D  D)poolN)N)certificate_authorityN)r1   N)r2   N)r   r1   NNN)r1   NN)rB   )5__doc__
__future__r   r   r    googlecloudsdk.api_lib.privatecar   r   googlecloudsdk.callioper    googlecloudsdk.calliope.conceptsr	   r
   r   r   googlecloudsdk.command_lib.kmsr   r:   $googlecloudsdk.command_lib.privatecar   r*   r{   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   r   PropertyFallthroughVALUES	privatecar1   r)   corer2   r?   r   r   r"   r&   r,   r.   r@   rM   rO   rS   rV   rb   re   rh   rk   rt   r   r   r   r   r   <module>r      s   . &  ' 1 6 . 5 1 5 1 D S S D * 
 !9 8 8((!   8t77""  
P
 48*8 %<!8 "	*$$$*.Cr   