
                            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)FRoll back to the previous 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)_BaseRollbackCertz)Base class for sql server_certs rollback.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/rollback.pyArgsz_BaseRollbackCert.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/                  |j0                                          }|j                  j3                  d|j4                  |j                  	      }t6        j8                  j;                  ||d
       t=        j>                  |t        j@                        S )a  Roll back to the previous 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 rolled back to, if the operation was
      successful.
    projectzsql.instances)params
collectionz&No previous Server Certificate exists.)nextVersion)rotateServerCertificateContext)r   instance'instancesRotateServerCertificateRequestzsql.operations)	operationr   z+Rolling back to previous Server Certificate)!r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr
   ValidateInstanceNamer"   resource_parserParser   VALUEScorer   	GetOrFailr   GetPreviousServerCertificater   ResourceNotFoundError	instancesRotateServerCertificate*SqlInstancesRotateServerCertificateRequest'InstancesRotateServerCertificateRequestRotateServerCertificateContextsha1FingerprintCreatenamer	   OperationsV1Beta4WaitForOperationr   ServerCertForPrintACTIVE_CERT_LABEL)	selfargsclientr'   r(   instance_refprevious_server_certresult_operationoperation_refs	            r   Runz_BaseRollbackCert.Run)   s     < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L
 (DDL,  ,,
2  "++CC?? ((!**4@4h4h/;/Z/Z 4 D D 0[ 0 5i 5 	@ 	

 **11"''$$ 2 &M
   11M#P
 ##l<< r   N)__name__
__module____qualname____doc__staticmethodr   rD    r   r   r   r      s    1= =7r   r   c                       e Zd ZdZy)RollbackCertr   N)rE   rF   rG   rH   rJ   r   r   rL   rL   c   s    
 Or   rL   N)rH   
__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CreateCommandrL   rJ   r   r   <module>r[      s    M &  ' / 1 1 / 7 ( 0 *A AH $++00$2C2C2I2I $d&8&8  r   