
    ^                        d Z ddlmZ ddlmZ ddlmZ ddl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 G d de      Z ej,                  ej.                  j0                  ej.                  j2                  ej.                  j4                         G d deej6                               Zy)5Create a client certificate for a Cloud SQL instance.    )absolute_import)division)unicode_literalsN)api_util)
exceptions)validate)base)flags)log)
properties)filesc                   &    e Zd ZdZed        Zd Zy)_BaseAddCertz+Base class for sql ssl client_certs create.c                     | j                  dd       | j                  ddd       t        j                  |        | j                  j	                  t        j
                         y)z=Declare flag and positional arguments for the command parser.common_namez7User supplied name. Constrained to ```[a-zA-Z.-_ ]+```.)help	cert_fileNzRLocation of file which the private key of the created ssl-cert will be written to.)defaultr   )add_argumentr   AddInstancedisplay_info	AddFormatCLIENT_CERTS_FORMAT)parsers    *lib/surface/sql/ssl/client_certs/create.pyArgsz_BaseAddCert.Args$   sh     F  H %  '
 
f
!!%";";<    c           	      F   t         j                  j                  |j                        r/t	        j
                  dj                  |j                              	 t        j                  |j                  ddd       t        j                  t        j                        }|j                   }|j"                  }t%        j&                  |j(                         |j*                  j-                  |j(                  d
t.        j0                  j2                  j4                  j6                  id      }|j8                  j;                  |j=                  |j4                  |j(                  |j?                  |j@                                    }|jB                  jD                  }t        j                  |j                  |dz   d       |j*                  jG                  d|j4                  |j(                  |jB                  jH                  jJ                        }	tM        jN                  |	       |jB                  jH                  S # t        j                  t        f$ rH}t	        j
                  dj                  |j                  t        j                  |                  d	}~ww xY w)a}  Create a client certificate for a Cloud SQL instance.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A dict object representing the operations resource describing the create
      operation if the create was successful.
    Raises:
      ArgumentError: If the file path provided cannot be written to.
    zfile [{path}] already exists)pathzplaceholder
TF)privatecreate_pathz!unable to write [{path}]: {error})r    errorNprojectzsql.instances)params
collection)
commonName)r$   instancesslCertsInsertRequest
)r!   zsql.sslCerts)r&   r$   r(   sha1Fingerprint)(osr    existsr   r   ArgumentErrorformatr   WriteFileContentsErrorOSErrorsix	text_typer   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr	   ValidateInstanceNamer(   resource_parserParser   VALUEScorer$   	GetOrFailsslCertsInsertSqlSslCertsInsertRequestSslCertsInsertRequestr   
clientCertcertPrivateKeyCreatecertInfor+   r   CreatedResource)
selfargseclientr7   r8   instance_refresultprivate_keycert_refs
             r   Runz_BaseAddCert.Run2   s-    
ww~~dnn%$$
(
/
/T^^
/
DF F
8
../4UL  < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L   ''-- ((!**"."D"D++ #E #- 	. 	./F ##22K	DNNK$,>M%%,,!$$&&))22BB	 - DH !%%%E KK! 8$$%H%O%O~~S]]1%5 &P &7 8 88s   #H? ?J AJJ N)__name__
__module____qualname____doc__staticmethodr   rP    r   r   r   r   !   s    3= =9&r   r   c                       e Zd ZdZy)AddCertr   N)rQ   rR   rS   rT   rV   r   r   rX   rX   n   s
     >r   rX   )rT   
__future__r   r   r   r,   googlecloudsdk.api_lib.sqlr   r   r	   googlecloudsdk.callioper
   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r3   objectr   ReleaseTracksReleaseTrackGABETAALPHACreateCommandrX   rV   r   r   <module>rf      s    < &  ' 	 / 1 / ( 0 # * * 
J&6 J&Z D%%(($*;*;*@*@%%++-lD.. -r   