
    7                        S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSKJ
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\R                   5      r " S S\R                   5      r " S S\R                   5      r " S S\R                   5      r " S S\R                   5      rS r " S S\	R2                  5      rg)z(Utilities for Eventarc KafkaSources API.    )absolute_import)division)unicode_literalsN)
list_pager)base)common)apis)
exceptions)	resourcesc                       \ rS rSrSrSrg)NoFieldsSpecifiedError   z:Error when no fields were specified for a Patch operation. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       4lib/googlecloudsdk/api_lib/eventarc/kafka_sources.pyr   r      s    Br   r   c                       \ rS rSrSrSrg)!InvalidNetworkConfigArgumentError#   zJError when the Kafka Source's network configuration arguments are invalid.r   Nr   r   r   r   r   r   #   s    Rr   r   c                       \ rS rSrSrSrg)InvalidDestinationArgumentError'   z>Error when the Kafka Source's destination argument is invalid.r   Nr   r   r   r   r   r   '   s    Fr   r   c                       \ rS rSrSrSrg)(InvalidAuthenticationMethodArgumentError+   zCError when the Kafka Source's authentication arguments are invalid.r   Nr   r   r   r   r    r    +   s    Kr   r    c                       \ rS rSrSrSrg)InvalidBrokerUrisArgumentError/   zDError when the Kafka Source's bootstrap_servers argument is invalid.r   Nr   r   r   r   r#   r#   /   s    Lr   r#   c                       \ rS rSrSrSrg)InvalidTopicsArgumentError3   z9Error when the Kafka Source's topics argument is invalid.r   Nr   r   r   r   r&   r&   3   s    Ar   r&   c                       \ rS rSrSrSrg)!InvalidInitialOffsetArgumentError7   zAError when the Kafka Source's initial offset argument is invalid.r   Nr   r   r   r   r)   r)   7   s    Ir   r)   c                 r    [         R                  R                  U R                  SS9nUR	                  5       $ )Nz(eventarc.projects.locations.kafkaSources)
collection)r   REGISTRYParseRelativeNamenameSelfLink)resourcekafka_sourcess     r   GetKafkaSourceURIr3   ;   s8    $$66mm J 7 - 
			!!r   c                      ^  \ rS rSrSrU 4S jrSS jrS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rSrU =r$ )KafkaSourceClientV1B   zJKafka Source Client for interaction with v1 of Eventarc Kafka Sources API.c                   > [         [        U ]  [        R                  [        R
                  S5        [        R                  " [        R                  [        R
                  5      nUR                  U l	        UR                  U l        g )NkafkaSource)superr5   __init__r   API_NAMEAPI_VERSION_1r	   GetClientInstanceMESSAGES_MODULE	_messagesprojects_locations_kafkaSources_service)selfclient	__class__s     r   r:   KafkaSourceClientV1.__init__E   s\    	
t---}
 ##FOOV5I5IJF++DN::DMr   c                     U R                   R                  UR                  5       R                  5       UUR	                  5       US9nU R
                  R                  U5      $ )a  Creates a Kafka Source.

Args:
  kafka_source_ref: Resource, the Kafka Source to create.
  kafka_source_message: Kafka Source, the Kafka Source message that holds
    Kafka source'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.
)parentr8   kafkaSourceIdvalidateOnly)r?   2EventarcProjectsLocationsKafkaSourcesCreateRequestParentRelativeNameNamerA   Create)rB   kafka_source_refkafka_source_messagedry_run
create_reqs        r   rN   KafkaSourceClientV1.CreateP   s_     	II#**,99;,*//1 	 	J 	
  ==
++r   c           	          U R                   R                  UR                  5       US9n[        R                  " U R
                  USUUSS9$ )aY  List available Kafka Sources in location.

Args:
  location_ref: Resource, the location to list Kafka Sources 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 Kafka Sources in the location.
)rG   pageSizekafkaSourcesrU   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r?   0EventarcProjectsLocationsKafkaSourcesListRequestrL   r   YieldFromListrA   )rB   location_refrZ   	page_sizelist_reqs        r   ListKafkaSourceClientV1.Listg   sW     ~~NN((*Y O H ##' r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )zGets the requested Kafka Source.

Args:
  kafka_source_ref: Resource, the Kafka Source to get.

Returns:
  The Kafka Source message.
r/   )r?   /EventarcProjectsLocationsKafkaSourcesGetRequestrL   rA   Get)rB   rO   get_reqs      r   rg   KafkaSourceClientV1.Get   sA     nnLL**, M G ==W%%r   c                     U R                   R                  UR                  5       UUS9nU R                  R	                  U5      $ )a  Updates the specified Kafka Source.

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

Returns:
  A long-running operation for update.
)r/   kafka_source
updateMask)r?   1EventarcProjectsLocationsKafkaSourcesPatchRequestrL   rA   Patch)rB   rO   rP   update_mask	patch_reqs        r   rn   KafkaSourceClientV1.Patch   sJ     	HH!..0-" 	I 	
  ==y))r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )zDeletes the specified Kafka Source.

Args:
  kafka_source_ref: Resource, the Kafka Source to delete.

Returns:
  A long-running operation for delete.
re   )r?   2EventarcProjectsLocationsKafkaSourcesDeleteRequestrL   rA   Delete)rB   rO   
delete_reqs      r   rt   KafkaSourceClientV1.Delete   sD     	II!..0 	J 	
 
 ==
++r   c                 Z   U R                   R                  UR                  5       U R                  U5      U R	                  U5      U R                  U5      U R                  UUUUU	5      U R                  X5      U R                  X5      U R                  U5      U R                  U5      US9
$ )N)
r/   
brokerUrisconsumerGroupIdtopicsauthenticationConfignetworkConfigdestinationinitialOffsetloggingConfiglabels)r?   KafkaSourcerL   _BuildBrokerUris_BuildConsumerGroupID_BuildTopics_BuildAuthenticationConfig_BuildNetworkConfig_BuildDestination_BuildInitialOffset_BuildLoggingConfig)rB   rO   bootstrap_serversconsumer_group_idrz   sasl_mechanismsasl_usernamesasl_passwordtls_client_certificatetls_client_keynetwork_attachmentmessage_businitial_offsetlogging_configr   s                  r   BuildKafkaSource$KafkaSourceClientV1.BuildKafkaSource   s    " >>%%**,(():;223DE  (!<<"
 ..
 **+;I..~>..~>% &  r   c                    / nU(       a  UR                  S5        U(       d  U(       d  U(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U(       d  U(       d  U(       d  U	(       a  UR                  S5        U
(       d  U(       a  UR                  S5        U(       a  UR                  S5        U(       d  [        S5      eS	R                  U5      $ )
a  Builds an update mask for updating a Kafka Source.

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.
destinationsinputPayloadFormat
mediationsr   retryPolicycryptoKeyNamer   z*Must specify at least one field to update.,)appendr   join)rB   r   input_payload_format_json+input_payload_format_avro_schema_definition/input_payload_format_protobuf_schema_definitionr   r   max_retry_attemptsmin_retry_delaymax_retry_delay
crypto_keyclear_crypto_keyr   ro   s                 r   BuildUpdateMask#KafkaSourceClientV1.BuildUpdateMask   s    R K(!6:-.&)'%)""#OPP88K  r   c                 B    U R                   R                  R                  $ )N)r?   r   LabelsValue)rB   s    r   LabelsValueClass$KafkaSourceClientV1.LabelsValueClass  s    >>%%111r   c                 4    Uc  [        S5      e[        U5      $ )Nz+Must specify at least one bootstrap server.)r#   list)rB   r   s     r   r   $KafkaSourceClientV1._BuildBrokerUris"  s&     *
7  !""r   c                 4    Uc  [        S5      e[        U5      $ )Nz Must specify at least one topic.)r&   r   )rB   rz   s     r   r    KafkaSourceClientV1._BuildTopics)  s    ~&'IJJ<r   c                 \    Uc  [        S5      eSUR                   SUR                   SU 3$ )Nzmessage_bus must be set	projects/z/locations/z/messageBuses/)r   
projectsIdlocationsId)rB   rO   r   s      r   r   %KafkaSourceClientV1._BuildDestination.  s@    +,EFF'223;?O?[?[>\\jkvjwxxr   c                     Uc  [        S5      eU R                  R                  SUR                   SUR                   SU 3S9$ )Nznetwork_attachment must be setr   z	/regions/z/networkAttachments/)networkAttachment)r   r?   NetworkConfigr   r   )rB   rO   r   s      r   r   'KafkaSourceClientV1._BuildNetworkConfig3  sd    !-.NOO>>''%&6&A&A%B)L\LhLhKii}  Q  ~R  S (  r   c                 <    Uc  S[         R                  " 5        3$ U$ )Nz	eventarc-)uuiduuid4)rB   r   s     r   r   )KafkaSourceClientV1._BuildConsumerGroupID:  s!     ''r   c                 <    Uc  gUS:w  a  US:w  a  [        S5      eU$ )Nnewestoldestz.initial_offset must be one of newest or oldest)r)   )rB   r   s     r   r   'KafkaSourceClientV1._BuildInitialOffset?  s2    !n&@-
:  r   c           
         US LUS L-   US L-   nUS LUS L-   nUS:  a  US:  a  [        S5      eUS:  aS  US:w  a  [        S5      eU R                  R                  U R                  R                  U R	                  U5      UUS9S S9$ US:  aZ  US:w  a  [        S5      eU R                  R                  S U R                  R                  U R                  R                  UUS	9S
9S9$ [        S5      e)Nr   zExactly one of the following authentication methods must be set:
  - SASL Authentication (--sasl-mechanism, --sasl-username, --sasl-password)
  - TLS Authentication (--tls-client-certificate, --tls-client-key)   zpWhen using SASL Authentication, all three arguments sasl_mechanism, sasl_username, and sasl_password must be set)	mechanismusernameSecretpasswordSecret)saslAuthmutualTlsAuth   zYWhen using TLS Authentication, both tls_client_certificate and tls_client_key must be set)clientCertificate	clientKey)secretManagerResources)r    r?   AuthenticationConfigSaslAuthConfig_ConvertSaslMechanismToEnumMutualTlsAuthConfigMutualTlsSecrets)rB   r   r   r   r   r   num_args_saslnum_args_mtlss           r   r   .KafkaSourceClientV1._BuildAuthenticationConfigH  sh    
t	#$	&$	& 
 ,47d"M q]Q.4  q	!	6L
 	
 ^^00>>0088H** 1 
  1   q	!	6*
 	
 ^^00::%)^^%D%D$:* &E & ;  1   3	 r   c                     Uc  g U R                   R                  U R                   R                  R                  U5      S9$ )N)logSeverity)r?   LoggingConfigLogSeverityValueValuesEnum)rB   r   s     r   r   'KafkaSourceClientV1._BuildLoggingConfig  sB    >>''NN00KK
 (  r   c                    US:X  a%  U R                   R                  R                  S5      $ US:X  a%  U R                   R                  R                  S5      $ US:X  a%  U R                   R                  R                  S5      $ [        S5      e)z)Convert human-readable mechanism to enum.PLAINzSCRAM-SHA-256SHA_256zSCRAM-SHA-512SHA_512zDsasl_mechanism must be one of PLAIN, SCRAM_SHA_256, or SCRAM_SHA_512)r?   r   MechanismValueValuesEnumr    )rB   r   s     r   r   /KafkaSourceClientV1._ConvertSaslMechanismToEnum  s}    G^^**CCGLLO#^^**CCINNO#^^**CCINN
2	 r   )r?   rA   )F)r   r   r   r   r   r:   rN   rb   rg   rn   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)rD   s   @r   r5   r5   B   sj    R	;,.0&*,, $LD!L2#
y

;z r   r5   )r   
__future__r   r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.corer
   r   Errorr   r   r   r    r#   r&   r)   r3   EventarcClientBaser5   r   r   r   <module>r      s    / &  '  ' 0 2 , * )CZ-- CS
(8(8 SGj&6&6 GLz/?/? LMZ%5%5 MB!1!1 BJ
(8(8 J"W$11 Wr   