
                            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  G d de      Z ej(                  ej*                  j,                  ej*                  j.                  ej*                  j0                        ej2                   G d deej4                                      Zy)z;Rotate in the next server CA cert for a Cloud SQL instance.    )absolute_import)division)unicode_literals)api_util)
exceptions)
operations)validate)server_ca_certs)base)flags)
propertiesc                   &    e Zd ZdZed        Zd Zy)_BaseRotateCertz*Base class for sql server_ca_certs rotate.c                     t         j                  j                  |        t        j                  |        | j
                  j                  t        j                         y)z=Declare flag and positional arguments for the command parser.N)r   
ASYNC_FLAGAddToParserr   AddInstancedisplay_info	AddFormatSERVER_CA_CERTS_FORMAT)parsers    -lib/surface/sql/ssl/server_ca_certs/rotate.pyArgsz_BaseRotateCert.Args"   s>     	OO'	f
!!%">">?    c                    t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }t        j                   |||      }|st#        j$                  d      |j&                  j)                  |j+                  |j                  |j                              }|j                  j-                  d|j.                  |j                        }t0        j2                  j5                  ||d       |S )	a  Rotate in the upcoming server CA cert for a Cloud SQL instance.

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

    Returns:
      The Server CA Cert that was rotated in, if the operation was successful.
    projectzsql.instances)params
collectionz)No upcoming Server CA Certificate exists.)r   instancezsql.operations)	operationr   z*Rotating to upcoming Server CA Certificate)r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr	   ValidateInstanceNamer   resource_parserParser   VALUEScorer   	GetOrFailr
   GetNextServerCar   ResourceNotFoundError	instancesRotateServerCa!SqlInstancesRotateServerCaRequestCreatenamer   OperationsV1Beta4WaitForOperation)	selfargsclientr#   r$   instance_refnext_server_caresult_operationoperation_refs	            r   Runz_BaseRotateCert.Run)   sT     < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L
 %44Z5ACN ,,
57 7 "++::66 ((<3H3H 	7 	JK **11"''$$ 2 &M
   11M#OQ r   N)__name__
__module____qualname____doc__staticmethodr   r;    r   r   r   r      s    2@ @(r   r   c                       e Zd ZdZy)
RotateCertz?Rotate in the upcoming server CA cert for a Cloud SQL instance.N)r<   r=   r>   r?   rA   r   r   rC   rC   T   s    
 Hr   rC   N)r?   
__future__r   r   r   googlecloudsdk.api_lib.sqlr   r   r   r	   googlecloudsdk.api_lib.sql.sslr
   googlecloudsdk.callioper   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   objectr   ReleaseTracksReleaseTrackGABETAALPHAUniverseCompatibleCreateCommandrC   rA   r   r   <module>rR      s    B &  ' / 1 1 / : ( 0 *2f 2j $++00$2C2C2I2I $"4"4  r   