
    R                     8   S 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KJr  \	R                  " S	S
5      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 S r!S r"S r#S r$S  r%S!\&4S" jr'S!\&4S# jr(S(S$ jr)S% r*S& r+S'r,g))zDA library used to support Managed Service for Apache Kafka commands.    N)encoding)
exceptions)core)apis)log)
propertiesmanagedkafkav190929192z
/contexts/z
/subjects/z/mode/z/config/c                 @    U S:  a  [         R                  " SS5      eU $ )zValidate CPU >= 3.   z--cpuzCPU must be at least 3)r   BadArgumentException)cpus    4lib/googlecloudsdk/command_lib/managed_kafka/util.pyValidateCPUr   &   s"    1W

)
)'3K
LL	*    c                     UR                   (       d  U$ UR                  (       d  0 Ul        Sn[        UR                  U5      Ul        [	        XU5      $ )zPrepare the update request with the information from the subnet flag.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
  The updated request with the subnet.
%gcpConfig.accessConfig.networkConfigs)subnetsclusterAppendUpdateMask
updateMaskMapSubnetsToNetworkConfig)_argsrequestsubnet_update_masks       r   PrepareUpdateWithSubnetsr   -   sI     
N 
GO>'(:(:<NO'	"1G	44r   c                    UR                   (       a  [        UR                  S5      Ul        U$ UR                  (       d  U$ UR                  (       d  0 Ul        Sn[        UR                  U5      Ul        [        XU5      $ )zPrepare the update request with the information from the mTLS CA pool flag.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
  The updated request with the CA pool.
z tlsConfig.trustConfig.casConfigs)clear_mtls_ca_poolsr   r   mtls_ca_poolsr   MapCaPoolsToCASConfig)r   r   r   ca_pool_update_masks       r   PrepareUpdateWithCaPoolsr%   G   sv     
)>G N 
		N 
GO:'(:(:<OP'	q	00r   c                 0    U  SU 3n U S   S:w  a  U $ U SS $ )zHandles appending a new mask to an existing mask.

Args:
  update_mask: the existing update mask.
  new_mask: the new mask to append.

Returns:
  The fully appended update mask.
,r      N )update_masknew_masks     r   r   r   k   s0     -q
++#A#-B;qr?Br   c                 ~   UR                   R                  (       d  0 UR                   l        S/ 0UR                   R                  l        UR                   Hc  nSU0nUR                   R                  R                  R                  R                  [        R                  " U[        R                  5      5        Me     U$ )a  Maps the list of subnets from the flag to the API fields in the request.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
  The updated request with networkConfig in the JSON format.
networkConfigssubnet)
r   	gcpConfigaccessConfigr   r-   appendr   DictToMessage_MESSAGENetworkConfig)r   r   r   r.   network_configs        r   r   r   y   s     
	"	" "GOO,<b+A'//(f'NOO**99@@~x/E/EF 
 
.r   c                    UR                   (       d  U$ UR                  R                  (       d  0 UR                  l        S/ 0UR                  R                  l        UR                    Hc  nSU0nUR                  R                  R                  R                  R                  [        R                  " U[        R                  5      5        Me     U$ )a  Maps the list of CA pools from the flag to the API fields in the request.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
  The updated request with CertificateAuthorityServiceConfig in the JSON
  format.

casConfigscaPool)
r"   r   	tlsConfigtrustConfigr7   r1   r   r2   r3   !CertificateAuthorityServiceConfig)r   r   r   ca_pool
cas_configs        r   r#   r#      s     
		N 
	"	" "GOO+7*<'//'##gG$JOO))44;;BB	
 $ 
.r   c                 X    U  Vs/ s H  n[        X"R                  5      PM     sn$ s  snf )zSynthesizes the bootstrap address to the response for a list request.

Args:
  response: the payload to return.
  _: list of flags.

Returns:
  The updated clusters with the bootstrap.
SynthesizeBootstrapAddrname)responser   r   s      r   ListWithBootstrapAddrrC      s1     EM
DLg||4H
  
s   'c                 ,    [        X R                  5      $ )zSynthesizes the bootstrap address to the response for a describe request.

Args:
  response: the payload to return.
  _: list of flags.

Returns:
  The updated cluster with the bootstrap.
r?   )rB   r   s     r   DescribeWithBootstrapAddrrE      s     
!==	99r   c                    UR                  S5      S   nUR                  S5      S   n[        R                  R                  R                  R                  R                  5       nUR                  S5      n[        U5      S:X  a  US    SUS    3nS	U SU S
U S3n[        R                  R                  R                  U 5      nU S[         3US'   [        U S5      (       a  U R                  (       a  U S[         3US'   U$ )zSynthesizes the bootstrap address to the response.

Args:
  response: the payload to update.
  cluster: the fully qualifed name of the cluster.

Returns:
  The updated cluster with the bootstrap
/   r   :   r(   .r   z
bootstrap.z.managedkafka.z.cloud.googbootstrapAddressr9   bootstrapAddressMTLS)splitr   r   VALUESprojectGetlenresourceresource_projectorMakeSerializable	SASL_PORThasattrr9   	MTLS_PORT)rB   r   rA   locationrP   domain_prefixed_project	bootstrapsynthesizeds           r   r@   r@      s    
s	A	$]]3"(OO""''//335'#MM#.	 !Q&(+,A.Ea.H-IJG4&(>'+N)00AA(K+'0k9+$>+ !X{##(:(:-6Kq*DK&'	r   c                     [         R                  R                  UR                  5      nS[        R
                  " U[        R                  R                  5      0Ul	        SUl
        U$ )zLoad the topics JSON from the argument to the request.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
  The updated request with topics.
topics)r   yamlloadtopics_filer   r2   r3   ConsumerGroupTopicsValueconsumerGroupr   )r   r   r   r^   s       r   UpdateTopicsre      sV     99>>$**+&&&
(((44'
  '	.r   c                    UR                   (       d  UR                  (       d  U$ UR                  R                  (       d  0 UR                  l        S/ 0UR                  R                  l        UR                   (       d  S/ 0nOUR                   / / S.nUR
                  (       d  / Ul        [        UR
                  5      US'   UR                  (       d  / Ul        [        UR                  5      US'   UR                  R                  R                  R                  R                  [        R                  " U[        R                  5      5        [        U[        R                  5      (       au  [        R                   " SSUR"                  5      Ul        [        R                   " SSUR"                  5      Ul        [        R                   " SSUR"                  5      Ul        U$ )	zMaps subnets and DNS names to the network config API field.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
  The updated request with networkConfig in the JSON format.
r-   dns_domain_names)primary_subnetadditional_subnetsrg   ri   z7gcpConfig\.accessConfig\.networkConfigs\.dnsDomainNamesr   z6gcpConfig\.accessConfig\.networkConfigs\.primarySubnetz:gcpConfig\.accessConfig\.networkConfigs\.additionalSubnets)rh   dns_nameconnectClusterr/   r0   additional_subnetlistr-   r1   r   r2   r3   ConnectNetworkConfig
isinstance8ManagedkafkaProjectsLocationsConnectClustersPatchRequestresubr   )r   r   r   r5   s       r   MapConnectParamsToNetworkConfigrs      s    
		T]]N				)	)')G$3CR2H'""/			("-N -- N
 
		D)-d.D.D)E.%&	DM'+DMM':.#$	""//>>EE^X-J-JK GG 
 B/G
 A/G
 E/G
 
.r   c                    UR                   (       ag  [        R                  R                  UR                   5      n[        R
                  " U[        R                  R                  5      UR                  l
        UR                  =(       d<    [        R                  R                  R                  R                  R                  5       nUR                  n[         R"                  " SUR                  5      (       dF  UR$                  =(       d    UR&                  R)                  S5      S   nSU SU SUR                   3nXRR                  l        U$ )zLoad the config JSON from the argument to the request and build the kafka cluster resource path.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
z$projects/.+/locations/.+/clusters/.+rG   r   z	projects/z/locations/z
/clusters/)config_filer   r_   r`   r   r2   r3   ConnectClusterConfigValuerk   configrP   r   rO   rQ   kafka_clusterrq   matchrY   connect_clusterrN   kafkaCluster)r   r   r   rx   rP   kafka_cluster_pathrY   s          r   PrepareConnectClusterCreater~   5  s     
YY^^D,,-F$,$:$:''33%G! LLEDOO2277??CCE'))	94;M;M	N	N}}B 4 4 : :3 ? BH
G9KzD<N<N;OP  );%	.r   c                    UR                   (       a  [        R                  R                  UR                   5      n[        R
                  " U[        R                  R                  5      UR                  l
        [        UR                  S5      Ul        UR                  (       a  [        UR                  S5      Ul        UR                  (       a  [        UR                  S5      Ul        UR                  (       a  [        UR                  S5      Ul        UR                   (       a  [        UR                  S5      Ul        U$ )zMap the update flags to the request and update mask.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
rx   z4gcpConfig.accessConfig.networkConfigs.dnsDomainNameszgcpConfig.secretPathslabels)ru   r   r_   r`   r   r2   r3   rv   rw   rk   rx   r   r   clear_configsclear_dns_namesclear_secretsclear_labels)r   r   r   rx   s       r   PrepareConnectClusterUpdater   P  s     
YY^^D,,-F$,$:$:''33%G! *'*<*<hGG	)'*<*<hGG	)>G 
)3G 
)'*<*<hGG	.r   c                 x   UR                   (       d  0 Ul         UR                  (       ag  [        R                  R	                  UR                  5      n[
        R                  " U[        R                  R                  5      UR                   l
        0 nUR                  (       a%  [        UR                  R                  5      S-   US'   UR                  (       a%  [        UR                  R                  5      S-   US'   U(       a4  [
        R                  " U[        R                  5      UR                   l        U$ )zLoad the config JSON from the argument to the request.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
smaximum_backoffminimum_backoff)	connectorru   r   r_   r`   r   r2   r3   	ConnectorConfigsValueconfigstask_restart_max_backoffstrtotal_secondstask_restart_min_backoffTaskRetryPolicytaskRestartPolicyr   r   r   rx   task_restart_policy_dicts        r   -ConnectorCreateReadConfigAndTaskRestartPolicyr   p  s     
		G	YY^^D,,-F ( 6 6""//!G
  	""D))7783> ./ 
""D))7783> ./ *2*@*@   +G' 
.r   c                    UR                   (       d  0 Ul         UR                  (       a  [        R                  R	                  UR                  5      n[
        R                  " U[        R                  R                  5      UR                   l
        [        UR                  S5      Ul        0 nUR                  (       a%  [        UR                  R                  5      S-   US'   UR                   (       a%  [        UR                   R                  5      S-   US'   U(       a4  [
        R                  " U[        R"                  5      UR                   l        U$ )zLoad the config JSON from the argument to the request, and parse out the task restart policy.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
r   r   r   r   )r   ru   r   r_   r`   r   r2   r3   r   r   r   r   r   r   r   r   r   r   r   r   s        r   -ConnectorUpdateReadConfigAndTaskRestartPolicyr     s    
		G	YY^^D,,-F ( 6 6""//!G *'*<*<iHG  	""D))7783> ./ 
""D))7783> ./ *2*@*@   +G' 
.r   c                    UR                   (       a  UR                  R                  S5      nUR                  S5        / nUR                   R	                  5        H  u  pPUR                  SU S35        M     [        SR                  U5      SR                  U5      5      Ul        UR                  (       a  [        UR                  S5      Ul        U$ )zUnnest the configs dictionary to the update mask.

Args:
  _:  resource parameter required but unused variable.
  args: list of flags.
  request:  the payload to return.

Returns:
  The new update mask with the configs.
r'   r   z	configs["z"])	r   r   rN   removeitemsr1   r   joinr   )r   r   r   r*   configs_listkeys         r   PatchConfigsr     s     
\\$$**3/Ky!L,,$$&IcU"-. ')sxx5G 
)'*<*<iHG	.r   returnc                     U [         R                  R                  R                  :X  a  gU [         R                  R                  R                  :X  a  gU [         R                  R                  R
                  :X  a  gg)z~Parse the mode enum to a string.

Args:
  mode: The mode enum of the schema registry or subject.

Returns:
  The mode string.
	READWRITEREADONLYIMPORTNONE)r3   
SchemaModeModeValueValuesEnumr   r   r   )modes    r   	ParseModer     s^     
X  44>>>x""66???x""66===r   c                    U [         R                  R                  R                  :X  a  gU [         R                  R                  R                  :X  a  gU [         R                  R                  R
                  :X  a  gU [         R                  R                  R                  :X  a  gU [         R                  R                  R                  :X  a  gU [         R                  R                  R                  :X  a  gg)zParse the compatibility enum to a string.

Args:
  compatibility: The compatibility enum of the schema registry or subject.

Returns:
  The compatibility string.
BACKWARDBACKWARD_TRANSITIVEFORWARDFORWARD_TRANSITIVEFULLFULL_TRANSITIVEr   )	r3   SchemaConfigCompatibilityValueValuesEnumr   r   r   r   r   r   )compatibilitys    r   ParseCompatibilityr     s     				;	;	D	DE 				;	;	O	OP !				;	;	C	CD 				;	;	N	NO  --JJOOO				;	;	K	KL r   c                 v    U =(       d1    [         R                  R                  R                  R	                  SS9$ )NT)required)r   rO   r   rP   rQ   )
project_ids    r   ParseProjectr     s-    		Hz((--559949HHr   c                 p   [         R                  " SS5      n[         R                  " SS5      nUnU [         U  3nU(       aa  [        R
                  R                  SU -  5        UR                  US9n UR                  R                  US9  [        R                  " U SS9  g[        R
                  R                  SU -  5        UR%                  US9n UR&                  R                  US9  [        R                  " U SS9  g! [        R                   a  n[        R                  " U[        5      n[        R
                  R                  UR                   5        SUR                   ;   a$  [        R                  " US	R#                  U 5      S
9e SnAgSnAff = f! [        R                   a  n[        R                  " U[        5      n[        R
                  R                  UR                   5        SUR                   ;   a$  [        R                  " US	R#                  U 5      S
9e SnAgSnAff = f)a3  Called when the user runs gcloud managed-kafka schema-registries subject delete ...

Args:
  subject: The subject of the attribute to delete.
  subject_run_resource: The subject resource path.
  context: The context of the schema registry if provided.

Returns:
  The updated subject with its mode deleted.
r	   r
   zDeleting subject mode for [%s].rA   r   zmode. It is now unset.detailsResource not foundSubject {} not found.error_formatN)r   GetMessagesModuleGetClientInstanceSUBJECTS_MODE_RESOURCE_PATHr   statusPrintFManagedkafkaProjectsLocationsSchemaRegistriesContextsModeDeleteRequest1projects_locations_schemaRegistries_contexts_modeDeleteUpdatedResourceapitools_exceptionsHttpNotFoundErrorr   HttpExceptionHTTP_ERROR_FORMATmessageformat>ManagedkafkaProjectsLocationsSchemaRegistriesModeDeleteRequest(projects_locations_schemaRegistries_mode)	subjectsubject_run_resourcecontextr   clientschema_registry_resourcer   e	api_errors	            r   DeleteSubjectModer     s	    "">48'!!.$7&1 
""#>"?yI 
 JJ6@A\\% ] G
>>EE F  
'+CD JJ6@ANN) 	O 	
 
	
55<<W<M	'+CD! 00 
**1.?@i	jjy(()	!2!2	2&&3::7C
 	
 
3
" 00 
**1.?@i	jjy(()	!2!2	2&&3::7C
 	
 
3
s2   6.D .F FA8FFH53A8H00H5c                 l   [         R                  " SS5      n[         R                  " SS5      nU [         U  3nU(       aa  [        R
                  R                  SU -  5        UR                  US9n UR                  R                  US9  [        R                  " U SS9  g[        R
                  R                  SU -  5        UR%                  US9n UR&                  R                  US9  [        R                  " U SS9  g! [        R                   a  n[        R                  " U[        5      n[        R
                  R                  UR                   5        SUR                   ;   a$  [        R                  " US	R#                  U 5      S
9e SnAgSnAff = f! [        R                   a  n[        R                  " U[        5      n[        R
                  R                  UR                   5        SUR                   ;   a$  [        R                  " US	R#                  U 5      S
9e SnAgSnAff = f)aA  Called when the user runs gcloud managed-kafka schema-registries subject delete ...

Args:
  subject: The subject of the attribute to delete.
  schema_registry_resource: The schema registry resource path.
  context: The context of the schema registry if provided.

Returns:
  The updated subject with its config deleted.
r	   r
   z!Deleting subject config for [%s].r   r   zconfig. It is now unset.r   r   r   r   N)r   r   r   SUBJECTS_CONFIG_RESOURCE_PATHr   r   r   HManagedkafkaProjectsLocationsSchemaRegistriesContextsConfigDeleteRequest3projects_locations_schemaRegistries_contexts_configr   r   r   r   r   r   r   r   r   @ManagedkafkaProjectsLocationsSchemaRegistriesConfigDeleteRequest*projects_locations_schemaRegistries_config)	r   r   r   r   r   rA   r   r   r   s	            r   DeleteSubjectConfigr   M  s    "">48'!!.$7&$%&C%DWI	N$JJ87BC^^ _ G
@@GG H  
'+EF JJ87BCVV W G	
77>>w>O	'+EF 00 
**1.?@i	jjy(()	!2!2	2&&3::7C
 	
 
3
 00 
**1.?@i	jjy(()	!2!2	2&&3::7C
 	
 
3
s2   4.D .F FA8FFH31A8H..H3z;ResponseError: code={status_code}, message={status_message})N)-__doc__rq   apitools.base.pyr   r   r   googlecloudsdkr   googlecloudsdk.api_lib.utilr   googlecloudsdk.calliopegooglecloudsdk.corer   r   r   r3   rV   rX   CONTEXTS_RESOURCE_PATHSUBJECTS_RESOURCE_PATHr   r   r   r   r%   r   r   r#   rC   rE   r@   re   rs   r~   r   r   r   r   r   r   r   r   r   r   r   r)   r   r   <module>r      s    K 	 % >  , . # * !!.$7		% % &  * 54!1HC.:
:6*9x6@!H"J4s (% %PI7
t.
d B r   