
    6                        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 certificate for a Cloud SQL instance.    )absolute_import)division)unicode_literals)api_util)
exceptions)
operations)validate)server_certs)base)flags)
propertiesc                   &    e Zd ZdZed        Zd Zy)_BaseRotateCertz'Base class for sql server_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_CERTS_FORMAT)parsers    *lib/surface/sql/ssl/server_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       t7        j8                  |t        j:                        S )	a  Rotate in the upcoming server certificate for a Cloud SQL instance.

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

    Returns:
      The Server Cert that was rotated in, if the operation was successful.
    projectzsql.instances)params
collectionz&No upcoming Server Certificate exists.)r   instancezsql.operations)	operationr   z'Rotating to upcoming Server Certificate)r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr	   ValidateInstanceNamer   resource_parserParser   VALUEScorer   	GetOrFailr
   GetNextServerCertificater   ResourceNotFoundError	instancesRotateServerCertificate*SqlInstancesRotateServerCertificateRequestCreatenamer   OperationsV1Beta4WaitForOperationr   ServerCertForPrintACTIVE_CERT_LABEL)	selfargsclientr#   r$   instance_refnext_server_certresult_operationoperation_refs	            r   Runz_BaseRotateCert.Run)   sj     < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L
 $<<L, ,,
2  "++CC?? ((<3H3H 	@ 	
 **11"''$$ 2 &M
   11M#L
 ##,88 r   N)__name__
__module____qualname____doc__staticmethodr   r=    r   r   r   r      s    /= =0r   r   c                       e Zd ZdZy)
RotateCertzCRotate in the upcoming server certificate for a Cloud SQL instance.N)r>   r?   r@   rA   rC   r   r   rE   rE   \   s    
 Lr   rE   N)rA   
__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DefaultUniverseOnlyCreateCommandrE   rC   r   r   <module>rT      s    F &  ' / 1 1 / 7 ( 0 *:f :z $++00$2C2C2I2I $"4"4  r   