
                         D   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mZ  ej2                  ej4                  j6                         G d dej8                               Zy)zRevoke a certificate.    )absolute_import)division)unicode_literals)base)certificate_utils)request_utils)
exceptions)flags)resource_args)concept_parsers)presentation_specs)log)	resources)
console_io)timesc                   6    e Zd ZdZed        Zed        Zd Zy)Revokeag  Revoke a certificate.

  Revokes the given certificate for the given reason.

  ## EXAMPLES

  To revoke the 'frontend-server-tls' certificate due to key compromise:

    $ {command} \
      --certificate=frontend-server-tls \
      --issuer-pool=my-pool --issuer-location=us-west1 \
      --reason=key_compromise

  To revoke the a certificate with the serial number
  '7dc1d9186372de2e1f4824abb1c4c9e5e43cbb40' due to a newer one being issued:

    $ {command} \
      --serial-number=7dc1d9186372de2e1f4824abb1c4c9e5e43cbb40 \
      --issuer-pool=my-pool --issuer-location=us-west1 \
      --reason=superseded
  c                    | j                  ddd      }t        j                  dd      j                  |       t	        j
                  t        j                  dt        j                  d      d	d
d
d
d|      t        j                  dt        j                  dd      dd      g      j                  |        t        j                  |        y )NTzThe certificate identifier.)mutexrequiredhelp--serial-numberz%The serial number of the certificate.)r   --certificatecertificatezThe certificate to revoke. )zissuer-poolissuer-locationproject)flag_name_overridesgroup--issuer-poolzIssuing CA poolr   z1The issuing CA pool of the certificate to revoke.F)r   )	add_groupr   ArgumentAddToParserr   ConceptParserr   ResourcePresentationSpecr   CreateCertResourceSpecCreateCaPoolResourceSpecr
   AddRevocationReasonFlag)parserid_groups     ,lib/surface/privateca/certificates/revoke.pyArgszRevoke.Args<   s    T(E   H 	MM Gk(!!3300?(!#%!
 
	
 	3322!#4 @	
# ( {6	!!&)    c                    | j                   j                  j                         }|r|S | j                  d      st	        j
                  dd      | j                   j                  j                         }|st	        j
                  dd      d}| j                  d      rNt        j                  j                  | j                  ||j                  |j                  |j                  d      S | j                  d	      rKt        j                  || j                        }t        j                  j                  |j                  |
      S t	        j                   ddgd      )zHGets the certificate resource to be revoked based on the specified args.issuer_poolr    zZThe issuing CA pool is required if a full resource name is not provided for --certificate.zyThe issuer flag is not fully specified. Please add the --issuer-location flag or specify the issuer's full resource name.z1privateca.projects.locations.caPools.certificatesr   )
projectsIdlocationsId	caPoolsId)
collectionparamsserial_number)r3   r   r   zPTo revoke a Certificate, please provide either its resource ID or serial number.)CONCEPTSr   ParseIsSpecifiedr	   RequiredArgumentExceptionr/   r   REGISTRYr0   r1   r2   r   GetCertificateBySerialNumr5   nameOneOfArgumentsRequiredException)argscert_ref
issuer_refcert_collection_namer   s        r+   ParseCertificateResourcezRevoke.ParseCertificateResource\   s`    }}((..0HoM*00
-  **002J00
  O&%%


)&11'33%// &   (%??
d((k %%


'; &   
4
4	+, r-   c           
      0   t         j                  |      }t        j                  dj	                  |j                               d      s t        j                  j                  d       y t        j                  |j                        }t        j                  d      }t        j                  d      }|j                  j                  |j!                  |j                         |j#                  |t%        j&                                           }t)        j*                  |j,                  j.                        }t        j                  j                  d	j	                  |j0                  t)        j2                  |t(        j4                  
                   y )Nz(You are about to revoke Certificate [{}]T)messagedefaultzAborted by user.v1)api_version)reason	requestId)r<   revokeCertificateRequestzRevoked certificate [{}] at {}.)tzinfo)r   rB   r   PromptContinueformatRelativeNamer   statusPrintr
   ParseRevocationChoiceToEnumrH   privateca_baseGetClientInstanceGetMessagesModule'projects_locations_caPools_certificates:PrivatecaProjectsLocationsCaPoolsCertificatesRevokeRequestRevokeCertificateRequestr   GenerateRequestIdr   ParseDateTimerevocationDetailsrevocationTimer<   FormatDateTimeLOCAL)selfr>   r?   rH   clientmessagesr   revoke_times           r+   Runz
Revoke.Run   sC   ..t4H$$:AA!!#
 	 
jj)*..t{{;F--$?F//DAH@@GGKK&&(%-%F%F)H)H)J &G & 	L 	
K %%%%44K JJ)00  U[[A	
r-   N)__name__
__module____qualname____doc__staticmethodr,   rB   rb    r-   r+   r   r   $   s5    , * *> 7 7r"r-   r   N)rf   
__future__r   r   r    googlecloudsdk.api_lib.privatecar   rR   r   r   googlecloudsdk.callioper	   $googlecloudsdk.command_lib.privatecar
   r   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackGASilentCommandr   rh   r-   r+   <module>ru      sw     &  ' C > : ( . 6 > D G # ) 2 * D%%(()ST S *Sr-   