
    +                     b    S r SSKJr  SSKJr  S rS rS rS rSS jr	SS
 jr
 " S S\5      rg	)z(Utilities for Cloud Pub/Sub Schemas API.    )apisInvalidArgumentErrorc                      [        S5      $ )NzRThe schema name must include a revision-id of the format: SCHEMA_NAME@REVISION_ID.r        ,lib/googlecloudsdk/api_lib/pubsub/schemas.pyNoRevisionIdSpecifiedr
      s    	"
 r   c                 @    U R                  S5      n[        U5      S:  $ )N@   )splitlen)
schema_reffind_ids     r	   CheckRevisionIdInSchemaPathr      s!    S!'	W	r   c                      [        S5      $ )Nz7The schema type must be either AVRO or PROTOCOL-BUFFER.r   r   r   r	   InvalidSchemaTyper   "   s    	?
 r   c                     UR                  5       nUS:X  d  US:X  a   U R                  R                  R                  $ US:X  a   U R                  R                  R                  $ [        5       e)Nzprotocol-bufferprotocol_bufferavro)lowerSchemaTypeValueValuesEnumPROTOCOL_BUFFERAVROr   )messagesschema_typetype_strs      r	   ParseSchemaTyper    (   s^     (""h2C&C??..>>>6??..333r   c                 .    [         R                  " SSU S9$ )Npubsubv1no_http)r   GetClientInstancer$   s    r	   r&   r&   1   s    			$	@@r   Nc                 @    U =(       d
    [        5       n U R                  $ N)r&   MESSAGES_MODULE)clients    r	   GetMessagesModuler+   5   s    (&(&			r   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
SchemasClient:   z4Client for schemas service in the Cloud Pub/Sub API.Nc                     U=(       d
    [        5       U l        U=(       d    [        U5      U l        U R                  R                  U l        g r(   )r&   r*   r+   r   projects_schemas_service)selfr*   r   s      r	   __init__SchemasClient.__init__=   s5    /-/DK9 1& 9DMKK00DMr   c                     U R                   R                  U[        U R                   U5      US9nU R                   R                  U R                   R	                  US9US9nU R
                  R                  U5      $ )zCommits a revision for a Schema.

Args:
  schema_ref: The full schema_path.
  schema_definition: The new schema definition to commit.
  schema_type: The type of the schema (avro or protocol-buffer).

Returns:
Schema: the committed Schema revision
)nametype
definition)schema)commitSchemaRequestr6   )r   r   r    "PubsubProjectsSchemasCommitRequestCommitSchemaRequestr1   Commit)r2   r   schema_definitionr   r9   
commit_reqs         r	   r=   SchemasClient.CommitB   s|     ]]!!T]]K8$ " F
 AA MM==V=L B J ==
++r   c                     U R                   R                  U R                   R                  US9US9nU R                  R	                  U5      $ )a  Rolls back to a previous schema revision.

Args:
  schema_ref: The path of the schema to rollback.
  revision_id: The revision_id to rollback to.

Returns:
Schema: the new schema revision you have rolled back to.

Raises:
  InvalidArgumentError: If no revision_id is provided.
)
revisionId)rollbackSchemaRequestr6   )r   $PubsubProjectsSchemasRollbackRequestRollbackSchemaRequestr1   Rollback)r2   r   revision_idrollback_reqs       r	   rF   SchemasClient.RollbackX   sU     ==EE"mmAA" B 
 	 F L ==!!,//r   c                     [        U5      (       d
  [        5       eU R                  R                  US9nU R                  R                  U5      $ )zDeletes a schema revision.

Args:
  schema_ref: The path of the schema, with the revision_id.

Returns:
Schema: the deleted schema revision.
)r6   )r   r
   r   *PubsubProjectsSchemasDeleteRevisionRequestr1   DeleteRevision)r2   r   delete_revision_reqs      r	   rL   SchemasClient.DeleteRevisionm   sR     'z22!## 	@@ 	A 	
 
 ==''(;<<r   )r1   r*   r   )NN)
__name__
__module____qualname____firstlineno____doc__r3   r=   rF   rL   __static_attributes__r   r   r	   r-   r-   :   s    <1
,,0*=r   r-   )Fr(   )rS   googlecloudsdk.api_lib.utilr   &googlecloudsdk.command_lib.pubsub.utilr   r
   r   r   r    r&   r+   objectr-   r   r   r	   <module>rX      s?    / - G
A 
D=F D=r   