
    
                         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  G d dej$                        Zy)z'Cloud Pub/Sub schemas rollback command.    )absolute_import)division)unicode_literals)
exceptions)schemas)base)resource_args)util)logc                   .    e Zd ZdZddiZed        Zd Zy)Rollbackz3Roll back a Pub/Sub schema to a specified revision.EXAMPLESz          To roll back to an existing schema revision called "key-schema" with revision_id: "0a0b0c0d", run:
                    
$ {command} key-schema --revision-id=0a0b0c0d
          c                 b    t        j                  | d       | j                  dt        dd       y )Nzto rollback.z--revision-idzThe revision to roll back to.T)typehelprequired)r	   AddSchemaResourceArgadd_argumentstr)parsers    &lib/surface/pubsub/schemas/rollback.pyArgszRollback.Args*   s3     &&v~>
,	      c                    t        j                         }t        j                  |j                        }t        |dd      }	 |j                  ||      }t        j                  |j                   d       |S # t        j                  $ r^}t        j                  |      }t        j                  |dt        j                  |j                  j                               Y d}~yd}~ww xY w)a  This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      A serialized object (dict) describing the results of the operation.
      This description fits the Resource described in the ResourceRegistry under
      'pubsub.projects.schemas'.

    Raises:
      util.RequestFailedError: if any of the requests to the API failed.
    revision_idN)
schema_refr   zschema revision)kindfailed)r   )r   SchemasClientr
   ParseSchemaNameschemagetattrr   api_ex	HttpErrorr   HttpExceptionr   CreatedResourceCreateFailureErrorMessagepayloadstatus_messagename)selfargsclientr   r   resulterrorexcs           r   RunzRollback.Run5   s     ""$F%%dkk2J$t4K	*+Nf *;<M  $$U+c	
 //0J0JK
 s   A8 8C)AC$$C)N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r1    r   r   r   r      s/    ;  -  r   r   N)r5   
__future__r   r   r   apitools.base.pyr   r#   googlecloudsdk.api_lib.pubsubr   googlecloudsdk.api_lib.utilgooglecloudsdk.callioper   !googlecloudsdk.command_lib.pubsubr	   r
   googlecloudsdk.corer   Commandr   r8   r   r   <module>rA      s8    . &  ' 1 1 2 ( ; 2 #4t|| 4r   