
                            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 Zd Ze	j,                   e	j.                  e	j0                  j2                  e	j0                  j4                  e	j0                  j6                         G d de	j8                                      Zdddde_        y)z&Command for creating SSL certificates.    )absolute_import)division)unicode_literals)base_classes)arg_parsers)base)
exceptions)scope)flags)ssl_certificates_utils)filesc                 n   | j                  dd       | j                  j                  t        j                         | j                  ddd      }|j                  ddt        j                  d	
      g d       |j                  d      }|j                  dddd       |j                  dddd       y)z:Add the SSL certificates command line flags to the parser.z--descriptionz9An optional, textual description for the SSL certificate.)helpTz/Flags for managed or self-managed certificate. )mutexrequiredr   z	--domainsDOMAIN   )
min_lengthzA      List of domains to create a managed certificate for.
      )metavartypedefaultr   z"Flags for self-managed certificatez--certificateLOCAL_FILE_PATHz      Path to a local certificate file to create a self-managed
      certificate. The certificate must be in PEM format. The certificate
      chain must be no greater than 5 certs long. The chain must include at
      least one intermediate cert.
      )r   r   r   z--private-keyz      Path to a local private key file. The private key must be in PEM
      format and must use RSA or ECDSA encryption.
      N)add_argumentdisplay_infoAddCacheUpdaterr   SslCertificatesCompleterBeta	add_groupr   ArgList)parsermanaged_or_notnot_manageds      .lib/surface/compute/ssl_certificates/create.py_Argsr#      s    F  H 	%%e&H&HI##< $ >.
 !,
   (()MN+
	  	 
	      c           	         |j                   }| j                  rt        j                  |      rt	        j
                  d      |j                  j                  |j                  j                  |j                  j                  j                  j                  |j                         |j                  j                  | j                        | j                        |j                        }|j                  j                   }nCt#        j$                  | j&                        }t#        j$                  | j(                        }t        j                  |      r~|j                  j+                  |j                  j                  |j                         ||| j                        |j,                  |j                        }|j                  j.                  }nr|j                  j                  |j                  j                  |j                         ||| j                        |j                        }|j                  j                   }|j1                  |d|fg      S )z&Make a SslCertificates.Insert request.z9--domains flag is not supported for regional certificates)domains)r   namemanageddescription)sslCertificateproject)r'   certificate
privateKeyr)   )r*   regionr+   Insert)clientr&   r   IsRegionalSslCertificatesRefcompute_exceptionsArgumentErrormessages#ComputeSslCertificatesInsertRequestSslCertificateTypeValueValuesEnumMANAGEDName#SslCertificateManagedSslCertificater)   r+   apitools_clientsslCertificatesr   ReadFileContentsr,   private_key)ComputeRegionSslCertificatesInsertRequestr.   regionSslCertificatesMakeRequests)argsholderssl_certificate_refr0   request
collectionr,   r>   s           r"   _RunrG   J   s   ==&	\\::;NO,,
EG GooAA55//CCKK$))+OOGG H &(( 6 * $++ B -G ''77J(()9)9:K(()9)9:K::;NOII77&++-%$**	 8 ,
 %++%-- J /g ))??jCC77&++-%$**	 8 ,
 &-- D /g ))99j			z8W=>	??r$   c                   *    e Zd ZdZdZed        Zd Zy)CreateaJ  Create a Compute Engine SSL certificate resource.

  *{command}* is used to create SSL certificate resources. An SSL certificate
  resource consists of the certificate itself and a private key. The private key
  is encrypted before it is stored.

  You can create either a managed or a self-managed SslCertificate resource. A
  managed SslCertificate is provisioned and renewed for you, when you specify
  the `--domains` flag. A self-managed certificate is created by passing the
  certificate obtained from Certificate Authority through `--certificate` and
  `--private-key` flags.
  Nc                     |j                   j                  t        j                         t        j                         | _        | j
                  j                  |d       t        |       y )Ncreate)operation_type)r   	AddFormatr   DEFAULT_LIST_FORMATSslCertificateArgumentSSL_CERTIFICATE_ARGAddArgumentr#   )clsr   s     r"   ArgszCreate.Args   sM    
!!%";";<#::<C''x'H	&Mr$   c                     t        j                  | j                               }| j                  j	                  ||j
                  t        j                  j                        }t        |||      S )z<Issues the request necessary for adding the SSL certificate.)default_scope)
r   ComputeApiHolderReleaseTrackrP   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALrG   )selfrB   rC   rD   s       r"   Runz
Create.Run   sb    **4+<+<+>?F22DDfm.E.E.L.L E Nf122r$   )__name__
__module____qualname____doc__rP   classmethodrS   r^    r$   r"   rI   rI   v   s&      3r$   rI   z'Create a Compute Engine SSL certificateaR          *{command}* creates SSL certificate resources, which you can use in a
        target HTTPS or target SSL proxy. An SSL certificate resource consists
        of a certificate and private key. The private key is encrypted before it
        is stored.

        You can create either a managed or a self-managed SslCertificate
        resource. A managed SslCertificate is provisioned and renewed for you. A
        self-managed certificate is created by passing the
        certificate obtained from Certificate Authority through `--certificate`
        and `--private-key` flags.
        a          To create a self-managed certificate resource 'my-cert' from a
        certificate placed under path
        'foo/cert' and a private key placed under path 'foo/pk', run:

            $ {command} my-cert --certificate=foo/cert --private-key=foo/pk
        )briefDESCRIPTIONEXAMPLESN)rb   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   r2   r
   rZ   3googlecloudsdk.command_lib.compute.ssl_certificatesr   r   googlecloudsdk.core.utilr   r#   rG   UnicodeIsSupportedReleaseTracksrW   GABETAALPHACreateCommandrI   detailed_helprd   r$   r"   <module>ru      s    - &  ' 7 / ( O E E V *(V)@X D%%(($*;*;*@*@%%++-3T 3- 3D 	2		# r$   