
                             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j&                        Zy)z%Cloud Pub/Sub schemas commit command.    )absolute_import)division)unicode_literals)
exceptions)schemas)base)flags)resource_args)util)logc                   .    e Zd ZdZddiZed        Zd Zy)Commitz!Commit a Pub/Sub schema revision.EXAMPLESa%            To commit a PROTOCOL_BUFFER schema revision called "key-schema" that requires exactly one-string field named "key", run:
                    
$ {command} key-schema --definition="syntax = 'proto3'; message Message { optional string key = 1; }" --type=protocol-buffer
                    To commit an equivalent AVRO schema revision, run:
                    
$ {command} key-schema --definition="{ 'type': 'record', 'namespace': 'my.ns', 'name': 'KeyMsg', 'fields': [ { 'name': 'key', 'type': 'string' } ] }" --type=avro
                  c                 Z    t        j                  | d       t        j                  |        y )Nz
to revise.)r
   AddSchemaResourceArgr	   AddCommitSchemaFlags)parsers    $lib/surface/pubsub/schemas/commit.pyArgszCommit.Args/   s"     &&v|<	v&    c                    t        j                         }t        j                  |j                        }|j
                  r|j
                  }n|j                  }	 |j                  |||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.
    )
schema_refschema_definitionschema_typezschema revision)kindfailedN)r   )r   SchemasClientr   ParseSchemaNameschemadefinition_file
definitionr   typeapi_ex	HttpErrorr   HttpExceptionr   CreatedResourceCreateFailureErrorMessagepayloadstatus_messagename)selfargsclientr   r!   resulterrorexcs           r   Runz
Commit.Run5   s     ""$F%%dkk2J''j??j}}&ii  f *;<M  $$U+c	
 //0J0JK
 s   B D.ADD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
   r   googlecloudsdk.corer   Commandr   r8   r   r   <module>rA      s;    , &  ' 1 1 2 ( 3 ; 2 #;T\\ ;r   