
                             S r SSKJr  SSKJr  SSKJr   " S S\R                  5      r " S S\R                  5      r	SS	 jr
SS jr " S S\5      rg
)z3Utilities for Cloud Pub/Sub Message Transforms API.    )utils)apis)
exceptionsc                       \ rS rSrSrSrg)EmptyMessageException   z9Error when no message was specified for a Test operation. N__name__
__module____qualname____firstlineno____doc____static_attributes__r	       7lib/googlecloudsdk/api_lib/pubsub/message_transforms.pyr   r      s    Ar   r   c                       \ rS rSrSrSrg)EmptyFilePathException   zMError when no message transforms file was specified for a Validate operation.r	   Nr
   r	   r   r   r   r      s    Ur   r   c                 .    [         R                  " SSU S9$ )Npubsubv1no_http)r   GetClientInstancer   s    r   r   r      s    			$	@@r   Nc                 @    U =(       d
    [        5       n U R                  $ N)r   MESSAGES_MODULE)clients    r   GetMessagesModuler    "   s    (&(&			r   c                   @    \ rS rSrSrSS jrS	S jr     S
S jrSrg)MessageTransformsClient'   z?Client for message transforms 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    messagesprojects_service)selfr   r%   s      r   __init__ MessageTransformsClient.__init__*   s5    /-/DK9 1& 9DMKK((DMr   c                    U(       d  [        S5      e [        R                  " U R                  R                  U5      nU R                  R                  UR                  5       U R                  R                  US9S9nU R                  R                  U5      $ ! [        R
                  [        R                  [        R                  4 a"  n[        R                  " U5      4Ul	        e SnAff = f)a  Validates a message transform.

Args:
  project_ref (Resource): Resource reference for the project.
  message_transform_file (str): The file path to the JSON or YAML file
    containing the message transform.

Returns:
  ValidateMessageTransformResponse (success) if the message transform is
  valid, otherwise an error.

Raises:
  EmptyFilePathException: If no message transform file was specified.
z]You need to specify a path to JSON or YAML file containing the message transform to validate.N)messageTransform)projectvalidateMessageTransformRequest)r   r   (GetMessageTransformFromFileForValidationr%   MessageTransform#MessageTransformsInvalidFormatErrorMessageTransformsEmptyFileError!MessageTransformsMissingFileErrorGetErrorMessageargs-PubsubProjectsValidateMessageTransformRequestRelativeNameValidateMessageTransformRequestr'   ValidateMessageTransform)r(   project_refmessage_transform_filemessage_transformevalidate_requests         r   Validate MessageTransformsClient.Validate/   s     "", 

HH
--
(
(*@ }}RR((*(,(U(U. )V )
 S  ==112BCC 	11--// 
 %%a(*afs   +B 3C.C))C.c           
         U(       d  U(       d  [        S5      eU R                  R                  UU R                  R                  R                  US9S9nSnU(       a+   [        R
                  " U R                  R                  USS9nU(       a  U R                  R                  US9OSn
U R                  R                  UR                  5       U R                  R                  UU
U(       a  UR                  5       OSU(       a  UR                  5       OSS9S	9nU R                   R#                  U5      $ ! [        R                  [        R                  [        R                  4 a"  n	[        R                  " U	5      4U	l        e Sn	A	ff = f)
a;  Tests applying message transforms to a message.

Args:
  project_ref (Resource): Resource reference for the project.
  message_body (bytes): The message to test.
  attributes (list[AdditionalProperty]): List of attributes to attach to the
    message.
  message_transforms_file (str): The file path to the JSON or YAML file
    containing the message transforms.
  topic_ref (Resource): The topic containing the message transforms to test
    against.
  subscription_ref (Resource): The subscription containing the message
    transforms to test against.

Returns:
  TestMessageTransformsResponse which contains a list of TransformedMessage.

Raises:
  EmptyMessageException: If no message body or attributes were specified.
  EmptyMessageTransformsException: If no message
  transforms file/topic/subscription were specified.
zdYou cannot send an empty message. You must specify either a MESSAGE, one or more ATTRIBUTE, or both.)additionalProperties)data
attributesNF)enable_vertex_ai_smt)messageTransforms)messagerF   topicsubscription)r-   testMessageTransformsRequest)r   r%   PubsubMessageAttributesValuer   GetMessageTransformsFromFiler0   r1   r2   r3   r4   r5   MessageTransforms*PubsubProjectsTestMessageTransformsRequestr7   TestMessageTransformsRequestr'   TestMessageTransforms)r(   r:   message_bodyrD   message_transforms_file	topic_refsubscription_refrG   message_transformsr=   message_transforms_msgtest_requests               r   TestMessageTransformsClient.TestW   s|   > 
!5 
 mm))==..>>!+ ? 
 * G "??MM**#!&
  	'':L'M  ==KK((*%)]]%O%O4.7)((*T *668 &P &
 L 
L ==..|<<1 
3
3

/
/

1
1 
 ''*,s   *D6 63F)FF)r'   r   r%   )NNr   )NNNNN)	r   r   r   r   r   r)   r?   rY   r   r	   r   r   r"   r"   '   s(    G)
&DV "L=r   r"   )Fr   )r   googlecloudsdk.api_lib.pubsubr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   Errorr   r   r   r    objectr"   r	   r   r   <module>r`      sT    : / , *BJ,, BVZ-- VA 
|=f |=r   