
    U                         S 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  SSKJr  SS	KJr  SS
KJr  S r " S S5      rg)z)Cloud Datastream connection profiles API.    )
list_pager)
exceptions)util)base)HostPort)labels_util)	resources)yaml)
console_ioc                 r    [         R                  R                  U R                  SS9nUR	                  5       $ )N0datastream.projects.locations.connectionProfiles
collection)r	   REGISTRYParseRelativeNamenameSelfLink)resourceconnection_profiles     <lib/googlecloudsdk/api_lib/datastream/connection_profiles.pyGetConnectionProfileURIr      s:     ));;mmC < E 
	$	$	&&    c                      \ rS rSrS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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/S( jr)S/S) jr*S* r+S+ r,S, r-S-r.g)0ConnectionProfilesClient%   z2Client for connection profiles service in the API.Nc                     U=(       d    [         R                  " 5       U l        U=(       d    [         R                  " 5       U l        U R                  R
                  U l        [         R                  " 5       U l        g N)	r   GetClientInstance_clientGetMessagesModule	_messages%projects_locations_connectionProfiles_serviceGetResourceParser_resource_parser)selfclientmessagess      r   __init__!ConnectionProfilesClient.__init__(   sN    5T335DL9!7!7!9DNLLFFDM 224Dr   c                 &    U R                  U5        g r   )_ValidateSslConfigArgsr&   argss     r   _ValidateArgs&ConnectionProfilesClient._ValidateArgs.   s    %r   c                    U R                  UR                  S5        U R                  UR                  S5        U R                  UR                  S5        U R                  UR                  S5        U R                  UR
                  S5        U R                  UR                  S5        U R                  UR                  S5        g)	z(Validates Format of all SSL config args.zCA certificatezclient certificatez
client keyzPostgresql CA certificatezPostgresql client certificatezPostgresql client private keyzOracle CA certificateN)_ValidateCertificateFormatca_certificateclient_certificate
client_keypostgresql_ca_certificatepostgresql_client_certificatepostgresql_client_keyoracle_ca_certificater-   s     r   r,   /ConnectionProfilesClient._ValidateSslConfigArgs1   s    ##D$7$79IJ##D$;$;$8:##DOO\B 	##&&(C 	##**,K 	##""$C
 	##""$;r   c                    U(       d  gUR                  5       nUR                  S5      nUS   R                  S5      (       a  US   R                  S5      (       d&  [        R                  " USR                  U5      5      eg )NT
r   z-----z9The certificate does not appear to be in PEM format: 
{0})stripsplit
startswithr   InvalidArgumentExceptionformat)r&   certificater   cert
cert_liness        r   r2   3ConnectionProfilesClient._ValidateCertificateFormatH   sz    DD!JqM$$W--rN%%g..//

F
M
M  /r   c                 t    U R                   R                  UR                  UR                  UR                  S9$ )N	clientKeyclientCertificatecaCertificate)r!   MysqlSslConfigr5   r4   r3   r-   s     r   _GetSslConfig&ConnectionProfilesClient._GetSslConfigT   s7    >>((//11)) ) + +r   c           	          U R                  U5      nU R                  R                  UR                  UR                  UR
                  UR                  UR                  US9$ )N)hostnameportusernamepasswordsecretManagerStoredPassword	sslConfig)rM   r!   MysqlProfilemysql_hostname
mysql_portmysql_usernamemysql_password$mysql_secret_manager_stored_passwordr&   r.   
ssl_configs      r   _GetMySqlProfile)ConnectionProfilesClient._GetMySqlProfileZ   s\    ##D)J>>&&$$__$$$$$($M$M '  r   c           
          U R                  U5      nU R                  R                  UR                  UR                  UR
                  UR                  UR                  UR                  US9$ )N)rP   rQ   rR   rS   rT   databaseServiceoracleSslConfig)	_GetOracleSslConfigr!   OracleProfileoracle_hostnameoracle_portoracle_usernameoracle_password%oracle_secret_manager_stored_passworddatabase_servicer\   s      r   _GetOracleProfile*ConnectionProfilesClient._GetOracleProfiled   sg    ))$/J>>''%%%%%%$($N$N--" ( $ $r   c                 ^    U R                   R                  UR                  UR                  S9$ )z:Returns a OracleSslConfig message based on the given args.)rK   "serverCertificateDistinguishedName)r!   OracleSslConfigr9   ,oracle_server_certificate_distinguished_namer-   s     r   rc   ,ConnectionProfilesClient._GetOracleSslConfigo   s0    >>))00+/+\+\ *  r   c           	         UR                   (       d  UR                  (       a[  U R                  R                  U R                  R	                  UR                   UR                  UR
                  UR                  S9S9$ UR
                  (       aE  U R                  R                  U R                  R                  UR
                  UR                  S9S9$ g)z>Returns a PostgresqlSslConfig message based on the given args.)rJ   rI   rK   serverCertificateHostname)serverAndClientVerification)rK   rs   )serverVerificationN)r7   r8   r!   PostgresqlSslConfigServerAndClientVerificationr6   &postgresql_server_certificate_hostnameServerVerificationr-   s     r   _GetPostgresqlSslConfig0ConnectionProfilesClient._GetPostgresqlSslConfigv   s    ))T-G-G^^//&*nn&P&P $ B B22 ::(,(S(S	 'Q ' 0   %%^^//!^^>> ::(,(S(S ?  0   r   c           
          U R                  U5      nU R                  R                  UR                  UR                  UR
                  UR                  UR                  UR                  US9$ )N)rP   rQ   rR   rS   rT   databaserU   )	rz   r!   PostgresqlProfilepostgresql_hostnamepostgresql_portpostgresql_usernamepostgresql_password)postgresql_secret_manager_stored_passwordpostgresql_databaser\   s      r   _GetPostgresqlProfile.ConnectionProfilesClient._GetPostgresqlProfile   sg    --d3J>>++))!!))))$($R$R)) ,  r   c           	          U R                   R                  UR                  UR                  UR                  UR
                  UR                  UR                  S9$ )N)rP   rQ   rR   rS   rT   r}   )r!   SqlServerProfilesqlserver_hostnamesqlserver_portsqlserver_usernamesqlserver_password(sqlserver_secret_manager_stored_passwordsqlserver_databaser-   s     r   _GetSqlServerProfile-ConnectionProfilesClient._GetSqlServerProfile   sT    >>**((  (((($($Q$Q(( +  r   c                    UR                   (       a[  U R                  R                  UR                  U R                  R	                  UR                   UR
                  UR                  S9S9$ U R                  R                  UR                  U R                  R                  UR                  UR                  UR                  UR                  UR                  S9S9$ )N)clientIdclientSecretsecretManagerStoredClientSecret)domainoauth2ClientCredentials)rR   rS   rT   securityToken secretManagerStoredSecurityToken)r   userCredentials)salesforce_oauth2_client_idr!   SalesforceProfilesalesforce_domainOauth2ClientCredentialssalesforce_oauth2_client_secret5salesforce_secret_manager_stored_oauth2_client_secretUserCredentialssalesforce_usernamesalesforce_password)salesforce_secret_manager_stored_passwordsalesforce_security_token/salesforce_secret_manager_stored_security_tokenr-   s     r   _GetSalesforceProfile.ConnectionProfilesClient._GetSalesforceProfile   s    ''^^--''"&.."H"H77??.2.h.h #I # .   ^^--''..88////*.*X*X ::/3/c/c 9  . 	 	r   c                     U[         R                  R                  :X  a  UR                  nOUR                  nU R
                  R                  US9nUR                  (       a  UR                  Ul        U$ SUl        U$ )N)bucket/)	r   ReleaseTrackBETAbucket_namer   r!   
GcsProfile	root_pathrootPath)r&   r.   release_trackr   gcs_profiles        r   _GetGCSProfile'ConnectionProfilesClient._GetGCSProfile   sk    ))...f{{f..++6+:K-1^^4>>K BEKr   c           	         / nUR                    H  nUR                  (       a*  UR                  U R                  R	                  US95        M>  [
        R                  " U5      nUR                  U R                  R	                  UR                  [        UR                  5      S95        M     U R                  R                  UUR                  UR                  UR                  UR                  S9nUR                  (       a(  UR                   (       d  ["        R$                  " SS5      eUR                  (       a  0 Ul        UR                   (       a(  U R                  R)                  UR                  S9Ul        UR,                  (       a3  0 Ul        UR0                  (       a  UR0                  UR.                  l        U$ )z<Returns the MongoDB profile message based on the given args.rP   rP   rQ   )hostAddressesrR   
replicaSetrS   rT   zmongodb-direct-connectionzOmongodb direct connection can only be used with the standard connection format.)directConnection)mongodb_host_addressesmongodb_srv_connection_formatappendr!   HostAddressr   ParsehostintrQ   MongodbProfilemongodb_usernamemongodb_replica_setmongodb_password&mongodb_secret_manager_stored_passwordmongodb_direct_connection"mongodb_standard_connection_formatr   rA   srvConnectionFormatStandardConnectionFormatstandardConnectionFormatmongodb_tlsrU   mongodb_ca_certificaterK   )r&   r.   	addresseshost_addresshostportprofiles         r   _GetMongodbProfile+ConnectionProfilesClient._GetMongodbProfile   st   I33		+	+NN&&&=	
 >>,/NN&&!S-? ' 	
 4 nn++&&++&&$($O$O , G 	&&77//
%  
 ))$&g!..
..
1
1#== 2  &
 g		$	$*.*E*E'Nr   c                     U R                   R                  UR                  S5      UR                  S5      UR                  S5      S9$ )Nr5   r4   r3   rH   )r!   rL   getr&   datas     r   _ParseSslConfig(ConnectionProfilesClient._ParseSslConfig   sD    >>((((<(((#78hh/0 ) 2 2r   c                     U(       d  0 $ U R                  U5      nU R                  R                  UR                  S5      UR                  S5      UR                  S5      UR                  S5      US9$ )NrP   rQ   rR   rS   )rP   rQ   rR   rS   rU   )r   r!   rV   r   )r&   r   r]   s      r   _ParseMySqlProfile+ConnectionProfilesClient._ParseMySqlProfile   si    i%%d+J>>&&*%XXf*%*% '  r   c           	          U(       d  0 $ U R                   R                  UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      S9$ )NrP   rQ   rR   rS   rj   )rP   rQ   rR   rS   ra   )r!   rd   r   r   s     r   _ParseOracleProfile,ConnectionProfilesClient._ParseOracleProfile   sc    i>>''*%XXf*%*%!34 ( 6 6r   c           	          U(       d  0 $ U R                   R                  UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      S9$ NrP   rQ   rR   rS   r}   )rP   rQ   rR   rS   r}   )r!   r~   r   r   s     r   _ParsePostgresqlProfile0ConnectionProfilesClient._ParsePostgresqlProfile
  sb    i>>++*%XXf*%*%*% , ' 'r   c           	          U(       d  0 $ U R                   R                  UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      S9$ r   )r!   r   r   r   s     r   _ParseSqlServerProfile/ConnectionProfilesClient._ParseSqlServerProfile  sb    i>>***%XXf*%*%*% +  r   c                     U(       d  0 $ U R                   R                  UR                  S5      UR                  S5      S9$ )Nr   r   )r   r   )r!   r   r   r   s     r   _ParseGCSProfile)ConnectionProfilesClient._ParseGCSProfile  s?    i>>$$xx&+1F % H Hr   c                     U R                   R                  UR                  UR                  UR                  UR
                  UR                  S9$ )N)rP   rQ   rR   
privateKeyrS   )r!   ForwardSshTunnelConnectivityforward_ssh_hostnameforward_ssh_portforward_ssh_usernameforward_ssh_private_keyforward_ssh_passwordr-   s     r    _GetForwardSshTunnelConnectivity9ConnectionProfilesClient._GetForwardSshTunnelConnectivity%  sK    >>66**""**//** 7 , ,r   c                    [         R                  " X0R                  R                  R                  5      nU R                  R                  X%UR
                  S9nUS:X  a  U R                  U5      Ul        OUS:X  a  U R                  U5      Ul	        OUS:X  a  U R                  U5      Ul        OUS:X  a  U R                  U5      Ul        OUS:X  a  U R                  X45      Ul        OUS:X  a   U R                  R!                  5       Ul        O`US:X  a  U R%                  U5      Ul        OCUS	:X  a  U R)                  U5      Ul        O&[,        R.                  " US
R1                  U5      5      eU[2        R4                  R6                  :X  a%  UR8                  R:                  R=                  5       nO$UR8                  R>                  R=                  5       nU(       a.  U R                  RA                  URC                  5       S9Ul"        U$ URF                  (       a  U RI                  U5      Ul%        U$ URL                  (       a  0 Ul'        U$ )z/Returns a connection profile according to type.)r   labelsdisplayNameMYSQLORACLE
POSTGRESQL	SQLSERVERGOOGLE-CLOUD-STORAGEBIGQUERY
SALESFORCEMONGODBGThe connection profile type {0} is either unknown or not supported yet.)privateConnection)(r   ParseCreateArgsr!   ConnectionProfileLabelsValuedisplay_namer^   mysqlProfilerk   oracleProfiler   postgresqlProfiler   sqlServerProfiler   
gcsProfileBigQueryProfilebigqueryProfiler   salesforceProfiler   mongodbProfiler   rA   rB   r   r   r   CONCEPTSprivate_connection_namer   private_connectionPrivateConnectivityRelativeNameprivateConnectivityr   r   forwardSshConnectivitystatic_ip_connectivitystaticServiceIpConnectivity)r&   cp_typeconnection_profile_idr.   r   r   connection_profile_objprivate_connectivity_refs           r   _GetConnectionProfile.ConnectionProfilesClient._GetConnectionProfile-  s"    ((nn..::<F!^^=="%% > ' ',0,A,A$,G)	H	-1-C-CD-I*	L	 151K1K
2.	K	040I0I$0O-	*	**.*=*=
+'	J	/3~~/M/M/O,	L	 151K1K
2. 
I	.2.E.Ed.K+//
&/  ))...!%!F!F!L!L!N!%!A!A!G!G!I
..
,
, 8 E E G -  0 "! 
	"	"

/
/
5 3 "! 
	$	$;=8!!r   c                    U[         R                  R                  :w  a,  [        R                  " USU R
                  R                  5      $ [        R                  " USS9n [        R                  " U5      nUR                  S5      nUR                  S5      nU R
                  R                  UUS9nU R!                  UR                  S	0 5      5      n	U R#                  UR                  S
0 5      5      n
U R%                  UR                  S0 5      5      nU R'                  UR                  S0 5      5      nU R)                  UR                  S0 5      5      nU	(       a  Xl        O7U
(       a  Xl        O)U(       a  Xl        OU(       a  Xl        OU(       a  Xl        SU;   a  UR                  S5      Ul        U$ SU;   a  UR                  S5      Ul        U$ SU;   a  UR                  S5      Ul        U$ [        R                  " S5      e! [         a*  n[        R                  " SR                  U5      5      eSnAff = f)zDParses a connection-profile-file into the ConnectionProfile message.r  F)binaryzCannot parse YAML:[{0}]Nr  r   )r   r   oracle_profilemysql_profilepostgresql_profilesqlserver_profiler   static_service_ip_connectivityforward_ssh_connectivityprivate_connectivityz/Cannot parse YAML: missing connectivity method.)r   r   r   r   ParseMessageAndValidateSchemar!   r  r   ReadFromFileOrStdinr
   load	Exceptionds_exceptions
ParseErrorrB   r   r   r   r   r   r   r  r  r  r  r	  r  r  r  )r&   connection_profile_object_filer   r   connection_profile_dataer  r   connection_profile_msgr  r   r!  r"  r   s                 r   !_ParseConnectionProfileObjectFile:ConnectionProfilesClient._ParseConnectionProfileObjectFilef  sG    ))...//
(

..
*
*  ))&u6DJ $		$ +..~>L$((2F!^^==  >  --##$4b9;N++##OR8:M55##$8"=?33##$7< ''##M268K-;*	,9)	1C.	0A-	*5''+BB
!
%
%&F
G 8  "! 
$'>	>
!
%
%&@
A 3 "! 
 #:	:3J3N3N
 40 "!	 $$
; Y  J$$%>%E%Ea%HIIJs   !H 
I%H<<Ic                    UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR
                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR                  UR                  l
        UR	                  S5        UR                  S	5      (       a-  UR                  UR                  l
        UR	                  S
5        gg)z/Updates Forward SSH tunnel connectivity config.r   zforwardSshConnectivity.hostnamer   zforwardSshConnectivity.portr   zforwardSshConnectivity.usernamer   z!forwardSshConnectivity.privateKeyr   zforwardSshConnectivity.passwordN)IsSpecifiedr   r  rP   r   r   rQ   r   rR   r   r   r   r&   r   r.   update_fieldss       r   #_UpdateForwardSshTunnelConnectivity<ConnectionProfilesClient._UpdateForwardSshTunnelConnectivity  s'    .//

#
# //8 <=*++7;7L7L//489.//

#
# //8 <=122

&
& //: >?.//

#
# //: <=	 0r   c                 
   U[         R                  R                  :X  aB  UR                  S5      (       a,  UR                  UR
                  l        UR                  S5        U[         R                  R                  :X  aB  UR                  S5      (       a,  UR                  UR
                  l        UR                  S5        UR                  S5      (       a-  UR                  UR
                  l
        UR                  S5        gg)z0Updates GOOGLE CLOUD STORAGE connection profile.r   zgcsProfile.bucketr   r   zgcsProfile.rootPathN)r   r   r   r3  r   r	  r   r   GAr   r   )r&   r   r   r.   r5  s        r   _UpdateGCSProfile*ConnectionProfilesClient._UpdateGCSProfile  s    
 ))...43C3C4 4 .2-=-=##*./)),,,1A1A(1K1K-1[[##*./$$/3~~##,01 %r   c                    UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR
                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       d  UR                  S5      (       aX  UR                  UR                  l
        UR                  UR                  l        UR	                  S	5        UR	                  S
5        UR                  S5      (       a-  UR                  UR                  l        UR	                  S5        gg)z"Updates Oracle connection profile.re   zoracleProfile.hostnamerf   zoracleProfile.portrg   zoracleProfile.usernamerh   ri   zoracleProfile.passwordz)oracleProfile.secretManagerStoredPasswordrj   zoracleProfile.databaseServiceN)r3  re   r  rP   r   rf   rQ   rg   rR   rh   rS   ri   rT   rj   ra   r4  s       r   _UpdateOracleProfile-ConnectionProfilesClient._UpdateOracleProfile  sU   
 )**262F2F&&/34&&.2.>.>&&+/0)**262F2F&&/34)**d.>.>// / 372F2F&&/

4
4 &&B 34FG*++9=9N9N&&6:; ,r   c                    UR                  S5      (       a6  UR                  UR                  R                  l        UR                  S5        UR                  S5      (       a6  UR                  UR                  R                  l        UR                  S5        UR                  S5      (       a7  UR                  UR                  R                  l	        UR                  S5        gg)zUpdates Mysql SSL config.r5   z mysqlProfile.sslConfig.clientKeyr4   z(mysqlProfile.sslConfig.clientCertificater3   z$mysqlProfile.sslConfig.caCertificateN)
r3  r5   r  rU   rI   r   r4   rJ   r3   rK   r4  s       r   _UpdateMysqlSslConfig.ConnectionProfilesClient._UpdateMysqlSslConfig  s    %%<@OO%%//9=>,--

!
! %%//A EF())


 %%//= AB	 *r   c                    UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR
                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       d  UR                  S5      (       aX  UR                  UR                  l
        UR                  UR                  l        UR	                  S	5        UR	                  S
5        U R                  XU5        g)z!Updates MySQL connection profile.rW   zmysqlProfile.hostnamerX   zmysqlProfile.portrY   zmysqlProfile.usernamerZ   r[   zmysqlProfile.passwordz(mysqlProfile.secretManagerStoredPasswordN)r3  rW   r  rP   r   rX   rQ   rY   rR   rZ   rS   r[   rT   r@  r4  s       r   _UpdateMySqlProfile,ConnectionProfilesClient._UpdateMySqlProfile  s'   ())151D1D%%.23%%-1__%%*./())151D1D%%.23())T-=-=.. . 261D1D%%.

3
3 %%A 23EF1Gr   c                 N   UR                  S5      (       a@  UR                  UR                  R                  R                  l        UR                  S5        UR                  S5      (       a@  UR                  UR                  R                  R                  l        UR                  S5        UR                  S5      (       a  UR                  R                  R                  (       aA  UR                  UR                  R                  R                  l
        UR                  S5        O@UR                  UR                  R                  R                  l
        UR                  S5        UR                  S5      (       a  UR                  R                  R                  (       aA  UR                  UR                  R                  R                  l        UR                  S	5        gUR                  UR                  R                  R                  l        UR                  S
5        gg)zUpdates Postgresql SSL config.r7   zIpostgresqlProfile.sslConfig.serverAndClientVerification.clientCertificater8   zApostgresqlProfile.sslConfig.serverAndClientVerification.clientKeyr6   zEpostgresqlProfile.sslConfig.serverAndClientVerification.caCertificatez<postgresqlProfile.sslConfig.serverVerification.caCertificaterx   zQpostgresqlProfile.sslConfig.serverAndClientVerification.serverCertificateHostnamezHpostgresqlProfile.sslConfig.serverVerification.serverCertificateHostnameN)r3  r7   r  rU   rt   rJ   r   r8   rI   r6   rK   ru   rx   rs   r4  s       r   _UpdatePostgresqlSslConfig3ConnectionProfilesClient._UpdatePostgresqlSslConfig  s   788

,
, **44PPb 
U /00

$
$ **44PPZ 
M 344		-	-	7	7	S	S** 	,,66RR` 	S	

 ** 	,,66IIW 	J	
 @AA

.
.
8
8
T
T 77 	,,66RRl 	_	

 77 	,,66IIc 	V	
 Br   c                 @   UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR
                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       d  UR                  S5      (       aX  UR                  UR                  l
        UR                  UR                  l        UR	                  S	5        UR	                  S
5        UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        U R                  XU5        g)z&Updates Postgresql connection profile.r   zpostgresqlProfile.hostnamer   zpostgresqlProfile.portr   zpostgresqlProfile.usernamer   r   zpostgresqlProfile.passwordz-postgresqlProfile.secretManagerStoredPasswordr   zpostgresqlProfile.databaseN)r3  r   r  rP   r   r   rQ   r   rR   r   rS   r   rT   r   r}   rF  r4  s       r   _UpdatePostgresqlProfile1ConnectionProfilesClient._UpdatePostgresqlProfileI  s`   -..6:6N6N**378)**262F2F**/34-..6:6N6N**378-..$2B2B33 3 7;6N6N**3

8
8 **F 78JK-..6:6N6N**378##$6mLr   c                    UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR
                  UR                  l        UR	                  S5        UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       d  UR                  S5      (       aX  UR                  UR                  l
        UR                  UR                  l        UR	                  S	5        UR	                  S
5        UR                  S5      (       a-  UR                  UR                  l        UR	                  S5        gg)z%Updates SqlServer connection profile.r   zsqlServerProfile.hostnamer   zsqlServerProfile.portr   zsqlServerProfile.usernamer   r   zsqlServerProfile.passwordz,sqlServerProfile.secretManagerStoredPasswordr   zsqlServerProfile.databaseN)r3  r   r  rP   r   r   rQ   r   rR   r   rS   r   rT   r   r}   r4  s       r   _UpdateSqlServerProfile0ConnectionProfilesClient._UpdateSqlServerProfilec  sT   ,--595L5L))267())151D1D)).23,--595L5L))267,--1A1A22 2 6:5L5L))2

7
7 ))E 67IJ,--595L5L))267 .r   c                 J   UR                  S5      (       a,  UR                  UR                  l        UR	                  S5        UR                  S5      (       a6  UR
                  UR                  R                  l        UR	                  S5        UR                  S5      (       d  UR                  S5      (       al  UR                  UR                  R                  l	        UR                  UR                  R                  l        UR	                  S5        UR	                  S5        UR                  S	5      (       d  UR                  S
5      (       al  UR                  UR                  R                  l        UR                  UR                  R                  l        UR	                  S5        UR	                  S5        UR                  S5      (       a6  UR                   UR                  R"                  l        UR	                  S5        UR                  S5      (       d  UR                  S5      (       am  UR&                  UR                  R"                  l        UR*                  UR                  R"                  l        UR	                  S5        UR	                  S5        gg)z&Updates Salesforce connection profile.r   zsalesforceProfile.domainr   z*salesforceProfile.userCredentials.usernamer   r   z*salesforceProfile.userCredentials.passwordz=salesforceProfile.userCredentials.secretManagerStoredPasswordr   r   z/salesforceProfile.userCredentials.securityTokenzBsalesforceProfile.userCredentials.secretManagerStoredSecurityTokenr   z2salesforceProfile.oauth2ClientCredentials.clientIdr   r   z6salesforceProfile.oauth2ClientCredentials.clientSecretzIsalesforceProfile.oauth2ClientCredentials.secretManagerStoredClientSecretN)r3  r   r  r   r   r   r   rR   r   rS   r   rT   r   r   r   r   r   r   r   r   r   r   r   r4  s       r   _UpdateSalesforceProfile1ConnectionProfilesClient._UpdateSalesforceProfile{  sZ   +,,484J4J**156-..

"
" **::C GH-..$2B2B33 3 
"
" **::C 
8
8 **::V GH
I 3448H8H99 9 
(
( **::H 
>
> **::[ LM
N 566

*
* **BBK OP9::d>N>N?? ? 
.
. **BBO 
D
D **BBb 
B 
U?r   c           	         UR                  S5      (       a  / nUR                   H  nUR                  (       a*  UR                  U R                  R                  US95        M>  UR                  S5      u  pgUR                  U R                  R                  U[        U5      S95        M     XAR                  l	        UR                  S5        UR                  S5      (       a,  UR                  UR                  l        UR                  S5        UR                  S5      (       d  UR                  S	5      (       af  UR                  (       a  0 UR                  l        UR                  (       a  0 UR                  l        UR                  S
5        UR                  S5        UR                  S5      (       a,  UR                  UR                  l        UR                  S5        UR                  S5      (       d  UR                  S5      (       aY  UR"                  UR                  l        UR&                  UR                  l        UR                  S5        UR                  S5        gg)z#Updates MongoDB connection profile.r   r   :r   zmonogodbProfile.hostAddressesr   zmongodbProfile.replicaSetr   r   z"mongodbProfile.srvConnectionFormatz'mongodbProfile.standardConnectionFormatr   zmongodbProfile.usernamer   r   zmongodbProfile.passwordz*mongodbProfile.secretManagerStoredPasswordN)r3  r   r   r   r!   r   r?   r   r  r   r   r   r   r   r   r   rR   r   rS   r   rT   )r&   r   r.   r5  r   r   rP   rQ   s           r   _UpdateMongodbProfile.ConnectionProfilesClient._UpdateMongodbProfile  s   011i55,--


nn((,(? (--c2.(


nn(((T(K 6 9B''5:;-..595M5M''267788D<L<L,= = 
	+	+@B))=		0	0EG))B?@DE*++373H3H''045*++t/?/?00 0 483H3H''0

5
5 ''C 45GH0r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )N)r   )r!   7DatastreamProjectsLocationsConnectionProfilesGetRequestr#   Get)r&   r   get_reqs      r   _GetExistingConnectionProfile6ConnectionProfilesClient._GetExistingConnectionProfile  s9    NN 	O 	
 
 ==W%%r   c                 T   [         R                  " U5      n[         R                  " U5      nU R                  R                  R
                  n[         R                  " UUUR                  S9R                  XQR                  5      nUR                  (       a  UR                  Ul	        gg)z)Updates labels of the connection profile.)	additionssubtractionsclearN)r   GetUpdateLabelsDictFromArgsGetRemoveLabelsListFromArgsr!   r  r  Diffclear_labelsApplyr   needs_update)r&   r   r.   
add_labelsremove_labels
value_typeupdate_results          r   _UpdateLabels&ConnectionProfilesClient._UpdateLabels  s    88>J;;DAM11==J$$" eJ112	 
 !!"/"6"6 "r   c                 H   / nUR                  S5      (       a"  UR                  Ul        UR                  S5        US:X  a  U R	                  XU5        OUS:X  a  U R                  XU5        OUS:X  a  U R                  XU5        OUS:X  a  U R                  XU5        OxUS:X  a  U R                  XU5        O_US:X  a  U R                  XXE5        OFUS	:X  a  O?US
:X  a  U R                  XU5        O&[        R                  " USR                  U5      5      eU[        R                  R                   :X  a%  UR"                  R$                  R'                  5       nO$UR"                  R(                  R'                  5       nU(       a>  U R*                  R-                  UR/                  5       S9Ul        UR                  S5        OMUR2                  (       a  U R5                  XU5        O)UR6                  (       a  0 Ul        UR                  S5        U R;                  X5        X4$ )z>Returns updated connection profile and list of updated fields.r  r   r   r   r   r   r   r   r   r   r   )privateConnectionNamer  r  )r3  r  r   r   rC  r=  rI  rL  rO  r:  rS  r   rA   rB   r   r   r   r  r  r   r  r!   r  r  r  r   r6  r  r  ri  )r&   r   r  r   r.   r5  r  s          r   _GetUpdatedConnectionProfile5ConnectionProfilesClient._GetUpdatedConnectionProfile  s    M'''+'8'8$=)'

M3	H	
 2-H	L	 
##$6mL	K	
""#5]K	L	 
##$6mL	*	*

T 
J	
	I	
  !3=I//
&/  ))...!%!F!F!L!L!N!%!A!A!G!G!I
..
,
,$<$I$I$K -  ,
 01		"	"
..
M 
	$	$79489)0,,r   c                 d   U R                  U5        U R                  UX%U5      nSnU[        R                  R                  :X  d  UR
                  (       a  Sn[        R                  " 5       nU R                  R                  n	U	" UUR                  UUUS9n
U R                  R                  U
5      $ )a  Creates a connection profile.

Args:
  parent_ref: a Resource reference to a parent datastream.projects.locations
    resource for this connection profile.
  connection_profile_id: str, the name of the resource to create.
  cp_type: str, the type of the connection profile ('MYSQL', ''
  release_track: Some arguments are added based on the command release
    track.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for creating the connection profile.
FT)connectionProfileconnectionProfileIdparent	requestIdforce)r/   r  r   r   r   rt  r   GenerateRequestIdr!   :DatastreamProjectsLocationsConnectionProfilesCreateRequestr   r#   Create)r&   
parent_refr  r  r   r.   r   rt  
request_idcreate_req_type
create_reqs              r   rw  ConnectionProfilesClient.Create/  s    * 	t33G4I4AC E))...$**e'')JQQ  !,.33J ==
++r   c                    U R                  U5        U R                  U5      nU R                  XRX45      u  pgSnU[        R                  R
                  :X  d  UR                  (       a  Sn[        R                  " 5       n	U R                  R                  n
U
" UUR                  SR                  U5      U	US9nU R                  R                  U5      $ )a  Updates a connection profile.

Args:
  name: str, the reference of the connection profile to
      update.
  cp_type: str, the type of the connection profile ('MYSQL', 'ORACLE')
  release_track: Some arguments are added based on the command release
    track.
  args: argparse.Namespace, The arguments that this command was
      invoked with.

Returns:
  Operation: the operation for updating the connection profile.
FT,)rp  r   
updateMaskrs  rt  )r/   rY  rm  r   r   r   rt  r   ru  r!   9DatastreamProjectsLocationsConnectionProfilesPatchRequestr   joinr#   Patch)r&   r   r  r   r.   
current_cp
updated_cpr5  rt  ry  update_req_type
update_reqs               r   UpdateConnectionProfilesClient.Update[  s     	t33D9J $ A A]!2J E))...$**e'')JPP  !$__88M*J ==z**r   c           	         U R                   R                  SUUR                  S9nU R                  R                  nU" UR                  5       UR                  UR                  (       a  SR                  UR                  5      OSS9n[        R                  " U R                  R                  UUR                  UR                  SSS9$ )	zGet the list of connection profiles in a project.

Args:
  project_id: The project ID to retrieve
  args: parsed command line arguments

Returns:
  An iterator over all the matching connection profiles.
zdatastream.projects.locations)
projectsIdlocationsIdr~  N)rr  filterorderByconnectionProfilespageSize)servicerequestlimit
batch_sizefieldbatch_size_attribute)r%   rw  locationr!   8DatastreamProjectsLocationsConnectionProfilesListRequestr  r  sort_byr  r   YieldFromListr   r"   r  	page_size)r&   
project_idr.   location_reflist_req_typelist_reqs         r   ListConnectionProfilesClient.List  s     ((//'MM 0 L 	OO  ((*{{*.,,&DH ##BBjj>>"') )r   c                    U R                   R                  5       nUR                  (       a:  UR                  R                  R	                  5       nUR                  5       Ul        O2UR                  (       a!  U R                  UR                  U5      Ul	        UR                  (       d  UR                  (       a  SUl        O_UR                  (       a  [        UR                  5      Ul        O3UR                   (       a  [        UR                   5      Ul        OSUl        UR"                  (       a2  [$        R&                  " U R                   UR"                  U5      Ul        OUR*                  (       a2  [$        R,                  " U R                   UR*                  U5      Ul        OUR0                  (       a1  [$        R2                  " U R                   UR0                  5      Ul        OAUR6                  (       a0  [$        R8                  " U R                   UR6                  5      Ul        U R                   R<                  nU" XAS9nU R>                  RA                  U5      $ )a  Discover a connection profile.

Args:
  parent_ref: a Resource reference to a parent datastream.projects.locations
    resource for this connection profile.
  release_track: Some arguments are added based on the command release
    track.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for discovering the connection profile.
TF) discoverConnectionProfileRequestrr  )!r!    DiscoverConnectionProfileRequestconnection_profile_namer  r   r  connectionProfileNamer,  r0  rp  	recursivefull_hierarchyfullHierarchyrecursive_depthr   hierarchyDepthhierarchy_depthmysql_rdbms_filer   ParseMysqlRdbmsFile
mysqlRdbmsoracle_rdbms_fileParseOracleRdbmsFileoracleRdbmspostgresql_rdbms_fileParsePostgresqlRdbmsFilepostgresqlRdbmssqlserver_rdbms_fileParseSqlServerRdbmsFilesqlServerRdbms<DatastreamProjectsLocationsConnectionProfilesDiscoverRequestr#   Discover)r&   rx  r   r.   r  connection_profile_refdiscover_req_typediscover_reqs           r   r  !ConnectionProfilesClient.Discover  s    nn==?G###}}DDJJL&<&I&I&Kg#		,	,"&"H"H

-
-}#g ~~,,"g			 #T%9%9:g			 #T%9%9:g#g33DNN484I4I4ACg 
		 55dnn6:6L6L6CEg 
	#	# $ = =
..$44!6g		"	"#;;
..$33 g 	SS  %)0EL==!!,//r   c                 V    U R                   R                  USS9nUR                  5       $ )zGet the URL string for a connection profile.

Args:
  name: connection profile's full name.

Returns:
  URL of the connection profile resource
r   r   )r%   r   r   )r&   r   uris      r   GetUriConnectionProfilesClient.GetUri  s2     


1
1K 2 MC<<>r   )r   r!   r%   r#   )NNr   )/__name__
__module____qualname____firstlineno____doc__r)   r/   r,   r2   rM   r^   rk   rc   rz   r   r   r   r   r   r   r   r   r   r   r   r   r  r0  r6  r:  r=  r@  rC  rF  rI  rL  rO  rS  rY  ri  rm  rw  r  r  r  r  __static_attributes__ r   r   r   r   %   s    :5&.
+	$,	,	+Z2	6'	H,7"r?"B>82"<6C H.1
fM4809v'IR&79-@ *,X'+R)B40lr   r   N)r  apitools.base.pyr   !googlecloudsdk.api_lib.datastreamr   r*  r   googlecloudsdk.callioper   #googlecloudsdk.calliope.arg_parsersr   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer	   r
   googlecloudsdk.core.consoler   r   r   r  r   r   <module>r     s;    0 ( I 2 ( . 8 < ) $ 2'B Br   