
    M                        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Z G d dej"                        Z G d dej"                        Zd Z G d dej*                        Zy)z(Utilities for Eventarc MessageBuses API.    )absolute_import)division)unicode_literals)
list_pager)base)common)apis)
exceptions)log)	resourceszSpecifying a network attachment for a pipeline with an HTTP endpoint is not GA
and the pipeline will be limited to pre-GA features.
c                       e Zd ZdZy)NoFieldsSpecifiedErrorz:Error when no fields were specified for a Patch operation.N__name__
__module____qualname____doc__     0lib/googlecloudsdk/api_lib/eventarc/pipelines.pyr   r   #   s    Br   r   c                       e Zd ZdZy) InvalidDestinationsArgumentErrorz;Error when the pipeline's destinations argument is invalid.Nr   r   r   r   r   r   '   s    Cr   r   c                 x    t         j                  j                  | j                  d      }|j	                         S )Nz%eventarc.projects.locations.pipelines)
collection)r   REGISTRYParseRelativeNamenameSelfLink)resource	pipeliness     r   GetPipelineURIr!   +   s8      22mm G 3 ) 
			r   c                        e Zd ZdZ fdZd dZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z! xZ"S )!PipelineClientV1zBPipeline Client for interaction with v1 of Eventarc Pipelines API.c                    t         t        |   t        j                  t        j
                  d       t        j                  t        j                  t        j
                        }|j                  | _	        |j                  | _        y )Npipeline)superr#   __init__r   API_NAMEAPI_VERSION_1r	   GetClientInstanceMESSAGES_MODULE	_messagesprojects_locations_pipelines_service)selfclient	__class__s     r   r'   zPipelineClientV1.__init__5   s\    	
D*--z
 ##FOOV5I5IJF++DN77DMr   c                     | j                   j                  |j                         j                         ||j	                         |      }| j
                  j                  |      S )a  Creates a Pipeline.

    Args:
      pipeline_ref: Resource, the Pipeline to create.
      pipeline_message: Pipeline, the pipeline message that holds pipeline's
        name, destinations, mediations, input payload format, logging config,
        retry policy, crypto key name, etc.
      dry_run: If set, the changes will not be committed, only validated

    Returns:
      A long-running operation for create.
    )parentr%   
pipelineIdvalidateOnly)r,   /EventarcProjectsLocationsPipelinesCreateRequestParentRelativeNameNamer.   Create)r/   pipeline_refpipeline_messagedry_run
create_reqs        r   r:   zPipelineClientV1.Create@   s\     OO""$113!$$&	 P J ==
++r   c                     | j                   j                  |j                         |      }t        j                  | j
                  |d||d      S )am  List available pipelines in location.

    Args:
      location_ref: Resource, the location to list Pipelines in.
      limit: int or None, the total number of results to return.
      page_size: int, the number of entries in each batch (affects requests
        made, but not the yielded results).

    Returns:
      A generator of Pipelines in the location.
    )r3   pageSizer    r@   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r,   -EventarcProjectsLocationsPipelinesListRequestr8   r   YieldFromListr.   )r/   location_refrD   	page_sizelist_reqs        r   ListzPipelineClientV1.ListU   sW     ~~KK((*Y L H ##' r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zGets the requested Pipeline.

    Args:
      pipeline_ref: Resource, the Pipeline to get.

    Returns:
      The Pipeline message.
    r   )r,   ,EventarcProjectsLocationsPipelinesGetRequestr8   r.   Get)r/   r;   get_reqs      r   rP   zPipelineClientV1.Getm   sA     nnII&&( J G ==W%%r   c                     | j                   j                  |j                         ||      }| j                  j	                  |      S )a  Updates the specified Pipeline.

    Args:
      pipeline_ref: Resource, the Pipeline to update.
      pipeline_message: Pipeline, the pipeline message that holds pipeline's
        name, destinations, mediations, input payload format, logging config,
        retry policy, crypto key name, etc.
      update_mask: str, a comma-separated list of Pipeline fields to update.

    Returns:
      A long-running operation for update.
    )r   r%   
updateMask)r,   .EventarcProjectsLocationsPipelinesPatchRequestr8   r.   Patch)r/   r;   r<   update_mask	patch_reqs        r   rU   zPipelineClientV1.Patch{   sG     MM&&(! N I
 ==y))r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zDeletes the specified Pipeline.

    Args:
      pipeline_ref: Resource, the Pipeline to delete.

    Returns:
      A long-running operation for delete.
    rN   )r,   /EventarcProjectsLocationsPipelinesDeleteRequestr8   r.   Delete)r/   r;   
delete_reqs      r   rZ   zPipelineClientV1.Delete   sA     OO&&( P J ==
++r   c                    | j                   j                  |j                         | j                  ||      | j	                  |||      | j                  |      | j                  |      | j                  ||	|
      ||      S )N)r   destinationsinputPayloadFormat
mediationsloggingConfigretryPolicycryptoKeyNamelabels)r,   Pipeliner8   _BuildDestinations_BuildInputPayloadFormat_BuildMediations_BuildLoggingConfig_BuildRetryPolicy)r/   r;   r]   input_payload_format_json+input_payload_format_avro_schema_definition/input_payload_format_protobuf_schema_definitionr_   logging_configmax_retry_attemptsmin_retry_delaymax_retry_delaycrypto_key_namerc   s                r   BuildPipelinezPipelineClientV1.BuildPipeline   s     >>""&&(,,\<H88%7;

 ((4..~>**
 & #  r   c                 d   g }|r|j                  d       |s|s|r|j                  d       |r|j                  d       |r|j                  d       |s|s|s|	r|j                  d       |
s|r|j                  d       |r|j                  d       |st        d      d	j                  |      S )
a_  Builds an update mask for updating a pipeline.

    Args:
      destinations: bool, whether to update the destinations.
      input_payload_format_json: bool, whether to update the
        input_payload_format_json.
      input_payload_format_avro_schema_definition: bool, whether to update the
        input_payload_format_avro_schema_definition.
      input_payload_format_protobuf_schema_definition: bool, whether to update
        the input_payload_format_protobuf_schema_definition.
      mediations: bool, whether to update the mediations.
      logging_config: bool, whether to update the logging_config.
      max_retry_attempts: bool, whether to update the max_retry_attempts.
      min_retry_delay: bool, whether to update the min_retry_delay.
      max_retry_delay: bool, whether to update the max_retry_delay.
      crypto_key: bool, whether to update the crypto_key.
      clear_crypto_key: bool, whether to clear the crypto_key.
      labels: bool, whether to update the labels.

    Returns:
      The update mask as a string.


    Raises:
      NoFieldsSpecifiedError: No fields are being updated.
    r]   r^   r_   r`   ra   rb   rc   z*Must specify at least one field to update.,)appendr   join)r/   r]   rj   rk   rl   r_   rm   rn   ro   rp   
crypto_keyclear_crypto_keyrc   rV   s                 r   BuildUpdateMaskz PipelineClientV1.BuildUpdateMask   s    R K(!6:-.&)'%)""#OPP88K  r   c                 B    | j                   j                  j                  S N)r,   rd   LabelsValue)r/   s    r   LabelsValueClassz!PipelineClientV1.LabelsValueClass  s    >>""...r   c                 T    |g S |D cg c]  }| j                  ||       c}S c c}w r{   )_BuildDestination)r/   r;   r]   ds       r   re   z#PipelineClientV1._BuildDestinations  s2    i=IJ\D""<3\JJJs   %c                 l   | j                  |      }| j                  ||      }| j                  ||      }| j                  ||      }|d u|d uz   |d uz   |d uz   dk7  rt	        d      |j                  d      	 |s|s|rt	        d      |j                  d      r|j                  d      rt	        d      |j                  d      r|j                  d      rt	        d	      | j                  j                  ||||| j                  ||      | j                  |      | j                  |      
      S )N   zTExactly one of http_endpoint_uri, workflow, message_bus, or pubsub_topic must be set&http_endpoint_message_binding_templatezghttp_endpoint_message_binding_template cannot be set when workflow, message_bus, or pubsub_topic is sethttp_endpoint_uriprojectz3project cannot be set when http_endpoint_uri is setlocationz4location cannot be set when http_endpoint_uri is set)httpEndpointworkflow
messageBustopicnetworkConfigauthenticationConfigoutputPayloadFormat)_BuildDestinationHttpEndpoint_BuildDestinationWorkflow_BuildDestinationMessageBus_BuildDestinationPubsubTopicr   getr,   (GoogleCloudEventarcV1PipelineDestination_BuildDestinationNetworkConfig%_BuildDestinationAuthenticationConfig$_BuildDestinationOutputPayloadFormat)r/   r;   destinationhttp_endpointr   message_buspubsub_topics          r   r   z"PipelineClientV1._BuildDestination  sz   66{CM--lKHH22<MK44\;OLT!hd&:;4	T	!#&'( -&  0;,,1  *+	0J,
?  *+
0K,
@  >>BB"99+
 "GG
 !EE
 C  r   c                     |j                  d      y | j                  j                  |j                  d      |j                  d            S )Nr   r   )urimessageBindingTemplate)r   r,   4GoogleCloudEventarcV1PipelineDestinationHttpEndpointr/   r   s     r   r   z.PipelineClientV1._BuildDestinationHttpEndpoint6  sN    *+3>>NNOO/0*4 
 O  r   c                     |j                  d      y |j                  d      xs |j                  }|j                  d      xs |j                  }d| d| d|j                  d       S )Nr   r   r   	projects//locations/z/workflows/r   
projectsIdlocationsIdr/   r;   r   r   r   s        r   r   z*PipelineClientV1._BuildDestinationWorkflow@  sj    z"*ooi(CL,C,CGz*Fl.F.FHwi{8*KPZ@[?\]]r   c                     |j                  d      y |j                  d      xs |j                  }|j                  d      xs |j                  }d| d| d|j                  d       S )Nr   r   r   r   r   z/messageBuses/r   r   s        r   r   z,PipelineClientV1._BuildDestinationMessageBusG  sj    }%-ooi(CL,C,CGz*Fl.F.FHwi{8*N;??S`CaBbccr   c                     |j                  d      y |j                  d      xs |j                  }d| d|j                  d       S )Nr   r   r   z/topics/)r   r   )r/   r;   r   r   s       r   r   z-PipelineClientV1._BuildDestinationPubsubTopicN  sJ    ~&.ooi(CL,C,CGwix(G'HIIr   c           
      D   |j                  d      s|j                  d      at        j                  t               | j                  j                  d|j                   d|j                   d|j                  d             S y |j                  d      t        d      y )Nr   network_attachmentr   z	/regions/z/networkAttachments/)networkAttachmentz"network_attachment must not be set)	r   r   warning NO_NA_FOR_HTTP_ENDPOINTS_WARNINGr,   5GoogleCloudEventarcV1PipelineDestinationNetworkConfigr   r   r   )r/   r;   r   s      r   r   z/PipelineClientV1._BuildDestinationNetworkConfigT  s    *+7	-	.	:45~~SS ),*A*A)B)LLdLdKeey  {F  {J  {J  K_  {`  za  b T 
 	
  +,8,
.  r   c                 d   | j                  |      }| j                  |      }|d u|d uz   dkD  rt        d      |j                  d      r|rt        d      |t        d      |j                  d      r|rt        d      |t        d      ||y | j                  j                  ||	      S )
Nr   zrAt most one of google_oidc_authentication_service_account or oauth_token_authentication_service_account can be set oauth_token_authentication_scopezeoauth_token_authentication_scope cannot be set when google_oidc_authentication_service_account is setzioauth_token_authentication_scope cannot be set when oauth_token_authentication_service_account is not set#google_oidc_authentication_audiencezhgoogle_oidc_authentication_audience cannot be set when oauth_token_authentication_service_account is setzlgoogle_oidc_authentication_audience cannot be set when google_oidc_authentication_service_account is not set)
googleOidc
oauthToken))_BuildDestinationAuthenticationGoogleOidc)_BuildDestinationAuthenticationOauthTokenr   r   r,   <GoogleCloudEventarcV1PipelineDestinationAuthenticationConfig)r/   r   google_oidcoauth_tokens       r   r   z6PipelineClientV1._BuildDestinationAuthenticationConfigf  s    @@MK@@MK4Kt$;<q@,C  9:	.A
 	
 
	.E
 	
 <=	.A
 	
 
	.E
 	
 {2>>VV W  r   c                     |j                  d      y | j                  j                  |j                  d      |j                  d            S )N*google_oidc_authentication_service_accountr   )serviceAccountaudience)r   r,   EGoogleCloudEventarcV1PipelineDestinationAuthenticationConfigOidcTokenr   s     r   r   z:PipelineClientV1._BuildDestinationAuthenticationGoogleOidc  sP    CDL>>__"8
 !FG	 `  r   c                     |j                  d      y | j                  j                  |j                  d      |j                  d            S )N*oauth_token_authentication_service_accountr   )r   scope)r   r,   FGoogleCloudEventarcV1PipelineDestinationAuthenticationConfigOAuthTokenr   s     r   r   z:PipelineClientV1._BuildDestinationAuthenticationOauthToken  sP    CDL>>``"8
 oo@A	 a  r   c                     | j                  |      }| j                  |      }| j                  |      }|d u|d uz   |d uz   dkD  rt        d      |||y | j                  j                  |||      S )Nr   zAt most one of output_payload_format_json, output_payload_format_avro_schema_definition, or output_payload_format_protobuf_schema_definition can be setjsonavroprotobuf)._BuildDestinationOutputPayloadFormatJsonFormat._BuildDestinationOutputPayloadFormatAvroFormat2_BuildDestinationOutputPayloadFormatProtobufFormatr   r,   1GoogleCloudEventarcV1PipelineMessagePayloadFormat)r/   r   r   r   r   s        r   r   z5PipelineClientV1._BuildDestinationOutputPayloadFormat  s    >>{KD>>{KDFFH 	DT-.($2FG!K,I 
 |)9>>KK L  r   c                 |    |j                  d      y | j                  j                  |j                  d            S )N,output_payload_format_avro_schema_definitionschemaDefinition)r   r,   ;GoogleCloudEventarcV1PipelineMessagePayloadFormatAvroFormatr   s     r   r   z?PipelineClientV1._BuildDestinationOutputPayloadFormatAvroFormat  sA    EFN>>UU$:
 V  r   c                 ~    |j                  d      	 y | j                  j                  |j                  d            S )N0output_payload_format_protobuf_schema_definitionr   )r   r,   ?GoogleCloudEventarcV1PipelineMessagePayloadFormatProtobufFormatr   s     r   r   zCPipelineClientV1._BuildDestinationOutputPayloadFormatProtobufFormat  sH    JK	 >>YY$>
 Z  r   c                 @    d|vry | j                   j                         S )Noutput_payload_format_jsonr,   ;GoogleCloudEventarcV1PipelineMessagePayloadFormatJsonFormatr   s     r   r   z?PipelineClientV1._BuildDestinationOutputPayloadFormatJsonFormat  s"    #;6RRTr   c                     |||y | j                   j                  | j                  |      | j                  |      | j	                  |            S )Nr   )r,   r   "_BuildInputPayloadFormatJsonFormat"_BuildInputPayloadFormatAvroFormat&_BuildInputPayloadFormatProtobufFormat)r/   r   avro_schema_definitionprotobuf_schema_definitions       r   rf   z)PipelineClientV1._BuildInputPayloadFormat  sc     	"*&.>>KK44T:445KL<<&
 L  r   c                 @    |y | j                   j                  |      S Nr   )r,   r   r/   schema_definitions     r   r   z3PipelineClientV1._BuildInputPayloadFormatAvroFormat  s+     >>UU* V  r   c                 @    |y | j                   j                  |      S r   )r,   r   r   s     r   r   z7PipelineClientV1._BuildInputPayloadFormatProtobufFormat  s+     >>YY* Z  r   c                 <    |y | j                   j                         S r{   r   )r/   r   s     r   r   z3PipelineClientV1._BuildInputPayloadFormatJsonFormat  s    |RRTr   c           
          |g S |D cg c]G  }| j                   j                  | j                   j                  |j                  d                  I c}S c c}w )Ntransformation_template)transformationTemplate)transformation)r,   &GoogleCloudEventarcV1PipelineMediation4GoogleCloudEventarcV1PipelineMediationTransformationr   )r/   r_   ms      r   rg   z!PipelineClientV1._BuildMediations  sq    i  A 	==>>^^'(uu-F'G _  	> 	

   s   AAc                     |y | j                   j                  | j                   j                  j                  |            S )N)logSeverity)r,   LoggingConfigLogSeverityValueValuesEnum)r/   rm   s     r   rh   z$PipelineClientV1._BuildLoggingConfig  sB    >>''NN00KK
 (  r   c                 L    |||y | j                   j                  |||      S )N)maxAttemptsminRetryDelaymaxRetryDelay)r,   (GoogleCloudEventarcV1PipelineRetryPolicy)r/   rn   ro   rp   s       r   ri   z"PipelineClientV1._BuildRetryPolicy
  s?     	"##>>BB&%% C  r   )F)#r   r   r   r   r'   r:   rL   rP   rU   rZ   rr   ry   r}   re   r   r   r   r   r   r   r   r   r   r   r   r   r   rf   r   r   r   rg   rh   ri   __classcell__)r1   s   @r   r#   r#   2   s    J	8,*0&*(,@D!L/K
)V^dJ$#J(
"
r   r#   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.corer
   r   r   r   Errorr   r   r!   EventarcClientBaser#   r   r   r   <module>r      sq    / &  ' ' 0 2 , * # )$  CZ-- CDz'7'7 Det.. er   