
    U                         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      Zy)z)Cloud Datastream connection profiles API.    )
list_pager)
exceptions)util)base)HostPort)labels_util)	resources)yaml)
console_ioc                 x    t         j                  j                  | j                  d      }|j	                         S )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                      e Zd Z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 d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'	 d-d'Z(d-d(Z)d) Z*d* Z+d+ Z,y).ConnectionProfilesClientz2Client for connection profiles service in the API.Nc                     |xs t        j                         | _        |xs t        j                         | _        | j                  j
                  | _        t        j                         | _        y N)	r   GetClientInstance_clientGetMessagesModule	_messages%projects_locations_connectionProfiles_serviceGetResourceParser_resource_parser)selfclientmessagess      r   __init__z!ConnectionProfilesClient.__init__(   sN    5T335DL9!7!7!9DNLLFFDM 224Dr   c                 &    | j                  |       y r   )_ValidateSslConfigArgsr%   argss     r   _ValidateArgsz&ConnectionProfilesClient._ValidateArgs.   s    %r   c                    | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  |j                  d       | j                  |j                  d       y)	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*   z/ConnectionProfilesClient._ValidateSslConfigArgs1   s    ##D$7$79IJ##D$;$;$8:##DOO\B 	##&&(C 	##**,K 	##""$C
 	##""$;r   c                     |sy|j                         }|j                  d      }|d   j                  d      r|d   j                  d      s%t        j                  |dj                  |            y )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   r/   z3ConnectionProfilesClient._ValidateCertificateFormatH   st    DD!JqM$$W-rN%%g.//

F
M
M  /r   c                 z    | j                   j                  |j                  |j                  |j                        S )N	clientKeyclientCertificatecaCertificate)r    MysqlSslConfigr2   r1   r0   r+   s     r   _GetSslConfigz&ConnectionProfilesClient._GetSslConfigT   s7    >>((//11)) ) + +r   c                     | j                  |      }| j                  j                  |j                  |j                  |j
                  |j                  |j                  |      S )N)hostnameportusernamepasswordsecretManagerStoredPassword	sslConfig)rH   r    MysqlProfilemysql_hostname
mysql_portmysql_usernamemysql_password$mysql_secret_manager_stored_passwordr%   r,   
ssl_configs      r   _GetMySqlProfilez)ConnectionProfilesClient._GetMySqlProfileZ   s\    ##D)J>>&&$$__$$$$$($M$M '  r   c           	          | j                  |      }| j                  j                  |j                  |j                  |j
                  |j                  |j                  |j                  |      S )N)rJ   rK   rL   rM   rN   databaseServiceoracleSslConfig)	_GetOracleSslConfigr    OracleProfileoracle_hostnameoracle_portoracle_usernameoracle_password%oracle_secret_manager_stored_passworddatabase_servicerV   s      r   _GetOracleProfilez*ConnectionProfilesClient._GetOracleProfiled   sg    ))$/J>>''%%%%%%$($N$N--" ( $ $r   c                 d    | j                   j                  |j                  |j                        S )z:Returns a OracleSslConfig message based on the given args.)rF   "serverCertificateDistinguishedName)r    OracleSslConfigr6   ,oracle_server_certificate_distinguished_namer+   s     r   r\   z,ConnectionProfilesClient._GetOracleSslConfigo   s0    >>))00+/+\+\ *  r   c                    |j                   s|j                  ra| j                  j                  | j                  j	                  |j                   |j                  |j
                  |j                              S |j
                  rK| j                  j                  | j                  j                  |j
                  |j                              S y)z>Returns a PostgresqlSslConfig message based on the given args.)rE   rD   rF   serverCertificateHostname)serverAndClientVerification)rF   rj   )serverVerificationN)r4   r5   r    PostgresqlSslConfigServerAndClientVerificationr3   &postgresql_server_certificate_hostnameServerVerificationr+   s     r   _GetPostgresqlSslConfigz0ConnectionProfilesClient._GetPostgresqlSslConfigv   s    ))T-G-G^^//&*nn&P&P $ B B22 ::(,(S(S	 'Q ' 0   %%^^//!^^>> ::(,(S(S ?  0   r   c           	          | j                  |      }| j                  j                  |j                  |j                  |j
                  |j                  |j                  |j                  |      S )N)rJ   rK   rL   rM   rN   databaserO   )	rq   r    PostgresqlProfilepostgresql_hostnamepostgresql_portpostgresql_usernamepostgresql_password)postgresql_secret_manager_stored_passwordpostgresql_databaserV   s      r   _GetPostgresqlProfilez.ConnectionProfilesClient._GetPostgresqlProfile   sg    --d3J>>++))!!))))$($R$R)) ,  r   c                     | j                   j                  |j                  |j                  |j                  |j
                  |j                  |j                        S )N)rJ   rK   rL   rM   rN   rs   )r    SqlServerProfilesqlserver_hostnamesqlserver_portsqlserver_usernamesqlserver_password(sqlserver_secret_manager_stored_passwordsqlserver_databaser+   s     r   _GetSqlServerProfilez-ConnectionProfilesClient._GetSqlServerProfile   sT    >>**((  (((($($Q$Q(( +  r   c           
         |j                   ra| j                  j                  |j                  | j                  j	                  |j                   |j
                  |j                              S | j                  j                  |j                  | j                  j                  |j                  |j                  |j                  |j                  |j                              S )N)clientIdclientSecretsecretManagerStoredClientSecret)domainoauth2ClientCredentials)rL   rM   rN   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   _GetSalesforceProfilez.ConnectionProfilesClient._GetSalesforceProfile   s    ''^^--''"&.."H"H77??.2.h.h #I # .   ^^--''..88////*.*X*X ::/3/c/c 9  . 	 	r   c                     |t         j                  j                  k(  r|j                  }n|j                  }| j
                  j                  |      }|j                  r|j                  |_        |S d|_        |S )N)bucket/)	r   ReleaseTrackBETAbucket_namer   r    
GcsProfile	root_pathrootPath)r%   r,   release_trackr   gcs_profiles        r   _GetGCSProfilez'ConnectionProfilesClient._GetGCSProfile   sk    ))...f{{f..++6+:K-1^^4>>K BEKr   c           	      L   g }|j                   D ]  }|j                  r,|j                  | j                  j	                  |             ;t        j                  |      }|j                  | j                  j	                  |j                  t        |j                                      | j                  j                  ||j                  |j                  |j                  |j                        }|j                  r"|j                   st#        j$                  dd      |j                  ri |_        |j                   r+| j                  j)                  |j                        |_        |j,                  r.i |_        |j0                  r|j0                  |j.                  _        |S )z<Returns the MongoDB profile message based on the given args.rJ   rJ   rK   )hostAddressesrL   
replicaSetrM   rN   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intrK   MongodbProfilemongodb_usernamemongodb_replica_setmongodb_password&mongodb_secret_manager_stored_passwordmongodb_direct_connection"mongodb_standard_connection_formatr   r=   srvConnectionFormatStandardConnectionFormatstandardConnectionFormatmongodb_tlsrO   mongodb_ca_certificaterF   )r%   r,   	addresseshost_addresshostportprofiles         r   _GetMongodbProfilez+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                     | j                   j                  |j                  d      |j                  d      |j                  d            S )Nr2   r1   r0   rC   )r    rG   getr%   datas     r   _ParseSslConfigz(ConnectionProfilesClient._ParseSslConfig   sD    >>((((<(((#78hh/0 ) 2 2r   c                     |si S | j                  |      }| j                  j                  |j                  d      |j                  d      |j                  d      |j                  d      |      S )NrJ   rK   rL   rM   )rJ   rK   rL   rM   rO   )r   r    rP   r   )r%   r   rW   s      r   _ParseMySqlProfilez+ConnectionProfilesClient._ParseMySqlProfile   si    i%%d+J>>&&*%XXf*%*% '  r   c           	          |si S | j                   j                  |j                  d      |j                  d      |j                  d      |j                  d      |j                  d            S )NrJ   rK   rL   rM   rc   )rJ   rK   rL   rM   rZ   )r    r]   r   r   s     r   _ParseOracleProfilez,ConnectionProfilesClient._ParseOracleProfile   sc    i>>''*%XXf*%*%!34 ( 6 6r   c           	          |si S | j                   j                  |j                  d      |j                  d      |j                  d      |j                  d      |j                  d            S NrJ   rK   rL   rM   rs   )rJ   rK   rL   rM   rs   )r    rt   r   r   s     r   _ParsePostgresqlProfilez0ConnectionProfilesClient._ParsePostgresqlProfile
  sb    i>>++*%XXf*%*%*% , ' 'r   c           	          |si S | j                   j                  |j                  d      |j                  d      |j                  d      |j                  d      |j                  d            S r   )r    r}   r   r   s     r   _ParseSqlServerProfilez/ConnectionProfilesClient._ParseSqlServerProfile  sb    i>>***%XXf*%*%*% +  r   c                     |si S | j                   j                  |j                  d      |j                  d            S )Nr   r   )r   r   )r    r   r   r   s     r   _ParseGCSProfilez)ConnectionProfilesClient._ParseGCSProfile  s?    i>>$$xx&+1F % H Hr   c                     | j                   j                  |j                  |j                  |j                  |j
                  |j                        S )N)rJ   rK   rL   
privateKeyrM   )r    ForwardSshTunnelConnectivityforward_ssh_hostnameforward_ssh_portforward_ssh_usernameforward_ssh_private_keyforward_ssh_passwordr+   s     r    _GetForwardSshTunnelConnectivityz9ConnectionProfilesClient._GetForwardSshTunnelConnectivity%  sK    >>66**""**//** 7 , ,r   c                 |   t        j                  || j                  j                  j                        }| j                  j                  |||j
                        }|dk(  r| j                  |      |_        n|dk(  r| j                  |      |_	        n|dk(  r| j                  |      |_        n|dk(  r| j                  |      |_        n|dk(  r| j                  ||      |_        n|dk(  r | j                  j!                         |_        n]|dk(  r| j%                  |      |_        nA|d	k(  r| j)                  |      |_        n%t-        j.                  |d
j1                  |            |t2        j4                  j6                  k(  r%|j8                  j:                  j=                         }n$|j8                  j>                  j=                         }|r1| j                  jA                  |jC                               |_"        |S |jF                  r| jI                  |      |_%        |S |jL                  ri |_'        |S )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_namerX   mysqlProfilerd   oracleProfiler{   postgresqlProfiler   sqlServerProfiler   
gcsProfileBigQueryProfilebigqueryProfiler   salesforceProfiler   mongodbProfiler   r=   r>   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   _GetConnectionProfilez.ConnectionProfilesClient._GetConnectionProfile-  s(    ((dnn..::<F!^^=="6%% > ' ',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                 R   |t         j                  j                  k7  r+t        j                  |d| j
                  j                        S t        j                  |d      }	 t        j                  |      }|j                  d      }|j                  d      }| j
                  j                  ||      }| j!                  |j                  d	i             }	| j#                  |j                  d
i             }
| j%                  |j                  di             }| j'                  |j                  di             }| j)                  |j                  di             }|	r|	|_        n'|
r|
|_        n|r||_        n|r||_        n	|r||_        d|v r|j                  d      |_        |S d|v r|j                  d      |_        |S d|v r|j                  d      |_        |S t        j                  d      # t        $ r)}t        j                  dj                  |            d}~ww xY w)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
ParseErrorr>   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   !_ParseConnectionProfileObjectFilez:ConnectionProfilesClient._ParseConnectionProfileObjectFilef  sV    ))...//
(

..
*
*  ))&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   !G4 4	H&=$H!!H&c                 h   |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      r,|j
                  |j                  _        |j	                  d       |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      r,|j                  |j                  _
        |j	                  d       |j                  d	      r-|j                  |j                  _
        |j	                  d
       yy)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   rJ   r   r   rK   r   rL   r   r   r   r%   r   r,   update_fieldss       r   #_UpdateForwardSshTunnelConnectivityz<ConnectionProfilesClient._UpdateForwardSshTunnelConnectivity  s    ./

#
# //8 <=*+7;7L7L//489./

#
# //8 <=12

&
& //: >?./

#
# //: <=	 0r   c                    |t         j                  j                  k(  r=|j                  d      r,|j                  |j
                  _        |j                  d       |t         j                  j                  k(  r=|j                  d      r,|j                  |j
                  _        |j                  d       |j                  d      r-|j                  |j
                  _
        |j                  d       yy)z0Updates GOOGLE CLOUD STORAGE connection profile.r   zgcsProfile.bucketr   r   zgcsProfile.rootPathN)r   r   r   r  r   r   r   r   GAr   r   )r%   r   r   r,   r  s        r   _UpdateGCSProfilez*ConnectionProfilesClient._UpdateGCSProfile  s    
 ))...43C3C4 .2-=-=##*./)),,,1A1A(1K-1[[##*./$/3~~##,01 %r   c                    |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      r,|j
                  |j                  _        |j	                  d       |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      s|j                  d      rX|j                  |j                  _
        |j                  |j                  _        |j	                  d	       |j	                  d
       |j                  d      r-|j                  |j                  _        |j	                  d       yy)z"Updates Oracle connection profile.r^   zoracleProfile.hostnamer_   zoracleProfile.portr`   zoracleProfile.usernamera   rb   zoracleProfile.passwordz)oracleProfile.secretManagerStoredPasswordrc   zoracleProfile.databaseServiceN)r  r^   r   rJ   r   r_   rK   r`   rL   ra   rM   rb   rN   rc   rZ   r  s       r   _UpdateOracleProfilez-ConnectionProfilesClient._UpdateOracleProfile  sA   
 )*262F2F&&/34&.2.>.>&&+/0)*262F2F&&/34)*d.>.>// 372F2F&&/

4
4 &&B 34FG*+9=9N9N&&6:; ,r   c                    |j                  d      r6|j                  |j                  j                  _        |j                  d       |j                  d      r6|j                  |j                  j                  _        |j                  d       |j                  d      r7|j                  |j                  j                  _	        |j                  d       yy)zUpdates Mysql SSL config.r2   z mysqlProfile.sslConfig.clientKeyr1   z(mysqlProfile.sslConfig.clientCertificater0   z$mysqlProfile.sslConfig.caCertificateN)
r  r2   r   rO   rD   r   r1   rE   r0   rF   r  s       r   _UpdateMysqlSslConfigz.ConnectionProfilesClient._UpdateMysqlSslConfig  s    %<@OO%%//9=>,-

!
! %%//A EF()


 %%//= AB	 *r   c                    |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      r,|j
                  |j                  _        |j	                  d       |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      s|j                  d      rX|j                  |j                  _
        |j                  |j                  _        |j	                  d	       |j	                  d
       | j                  |||       y)z!Updates MySQL connection profile.rQ   zmysqlProfile.hostnamerR   zmysqlProfile.portrS   zmysqlProfile.usernamerT   rU   zmysqlProfile.passwordz(mysqlProfile.secretManagerStoredPasswordN)r  rQ   r   rJ   r   rR   rK   rS   rL   rT   rM   rU   rN   r%  r  s       r   _UpdateMySqlProfilez,ConnectionProfilesClient._UpdateMySqlProfile  s   ()151D1D%%.23%-1__%%*./()151D1D%%.23()T-=-=.. 261D1D%%.

3
3 %%A 23EF14Gr   c                    |j                  d      r@|j                  |j                  j                  j                  _        |j                  d       |j                  d      r@|j                  |j                  j                  j                  _        |j                  d       |j                  d      r|j                  j                  j                  rA|j                  |j                  j                  j                  _
        |j                  d       n@|j                  |j                  j                  j                  _
        |j                  d       |j                  d      r|j                  j                  j                  rA|j                  |j                  j                  j                  _        |j                  d	       y|j                  |j                  j                  j                  _        |j                  d
       yy)zUpdates Postgresql SSL config.r4   zIpostgresqlProfile.sslConfig.serverAndClientVerification.clientCertificater5   zApostgresqlProfile.sslConfig.serverAndClientVerification.clientKeyr3   zEpostgresqlProfile.sslConfig.serverAndClientVerification.caCertificatez<postgresqlProfile.sslConfig.serverVerification.caCertificatero   zQpostgresqlProfile.sslConfig.serverAndClientVerification.serverCertificateHostnamezHpostgresqlProfile.sslConfig.serverVerification.serverCertificateHostnameN)r  r4   r   rO   rk   rE   r   r5   rD   r3   rF   rl   ro   rj   r  s       r   _UpdatePostgresqlSslConfigz3ConnectionProfilesClient._UpdatePostgresqlSslConfig  s   78

,
, **44PPb 
U /0

$
$ **44PPZ 
M 34		-	-	7	7	S	S** 	,,66RR` 	S	

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

 77 	,,66IIc 	V	
 Br   c                    |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      r,|j
                  |j                  _        |j	                  d       |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      s|j                  d      rX|j                  |j                  _
        |j                  |j                  _        |j	                  d	       |j	                  d
       |j                  d      r,|j                  |j                  _        |j	                  d       | j                  |||       y)z&Updates Postgresql connection profile.ru   zpostgresqlProfile.hostnamerv   zpostgresqlProfile.portrw   zpostgresqlProfile.usernamerx   ry   zpostgresqlProfile.passwordz-postgresqlProfile.secretManagerStoredPasswordrz   zpostgresqlProfile.databaseN)r  ru   r   rJ   r   rv   rK   rw   rL   rx   rM   ry   rN   rz   rs   r)  r  s       r   _UpdatePostgresqlProfilez1ConnectionProfilesClient._UpdatePostgresqlProfileI  sN   -.6:6N6N**378)*262F2F**/34-.6:6N6N**378-.$2B2B33 7;6N6N**3

8
8 **F 78JK-.6:6N6N**378##$6mLr   c                    |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      r,|j
                  |j                  _        |j	                  d       |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      s|j                  d      rX|j                  |j                  _
        |j                  |j                  _        |j	                  d	       |j	                  d
       |j                  d      r-|j                  |j                  _        |j	                  d       yy)z%Updates SqlServer connection profile.r~   zsqlServerProfile.hostnamer   zsqlServerProfile.portr   zsqlServerProfile.usernamer   r   zsqlServerProfile.passwordz,sqlServerProfile.secretManagerStoredPasswordr   zsqlServerProfile.databaseN)r  r~   r   rJ   r   r   rK   r   rL   r   rM   r   rN   r   rs   r  s       r   _UpdateSqlServerProfilez0ConnectionProfilesClient._UpdateSqlServerProfilec  s@   ,-595L5L))267()151D1D)).23,-595L5L))267,-1A1A22 6:5L5L))2

7
7 ))E 67IJ,-595L5L))267 .r   c                    |j                  d      r,|j                  |j                  _        |j	                  d       |j                  d      r6|j
                  |j                  j                  _        |j	                  d       |j                  d      s|j                  d      rl|j                  |j                  j                  _	        |j                  |j                  j                  _        |j	                  d       |j	                  d       |j                  d	      s|j                  d
      rl|j                  |j                  j                  _        |j                  |j                  j                  _        |j	                  d       |j	                  d       |j                  d      r6|j                   |j                  j"                  _        |j	                  d       |j                  d      s|j                  d      rm|j&                  |j                  j"                  _        |j*                  |j                  j"                  _        |j	                  d       |j	                  d       yy)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)r  r   r   r   r   r   r   rL   r   rM   r   rN   r   r   r   r   r   r   r   r   r   r   r   r  s       r   _UpdateSalesforceProfilez1ConnectionProfilesClient._UpdateSalesforceProfile{  s9   +,484J4J**156-.

"
" **::C GH-.$2B2B33 
"
" **::C 
8
8 **::V GH
I 348H8H99 
(
( **::H 
>
> **::[ LM
N 56

*
* **BBK OP9:d>N>N?? 
.
. **BBO 
D
D **BBb 
B 
U?r   c           	      x   |j                  d      rg }|j                  D ]  }|j                  r,|j                  | j                  j                  |             ;|j                  d      \  }}|j                  | j                  j                  |t        |                    ||j                  _	        |j                  d       |j                  d      r,|j                  |j                  _        |j                  d       |j                  d      s|j                  d	      r\|j                  ri |j                  _        |j                  ri |j                  _        |j                  d
       |j                  d       |j                  d      r,|j                  |j                  _        |j                  d       |j                  d      s|j                  d      rY|j"                  |j                  _        |j&                  |j                  _        |j                  d       |j                  d       yy)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)r  r   r   r   r    r   r;   r   r   r   r   r   r   r   r   r   rL   r   rM   r   rN   )r%   r   r,   r  r   r   rJ   rK   s           r   _UpdateMongodbProfilez.ConnectionProfilesClient._UpdateMongodbProfile  s   01i55,--


nn((,(? (--c2.(D


nn(((T(K 6 9B''5:;-.595M5M''26778D<L<L,= 
	+	+@B))=		0	0EG))B?@DE*+373H3H''045*+t/?/?00 483H3H''0

5
5 ''C 45GH0r   c                 p    | j                   j                  |      }| j                  j                  |      S )N)r   )r    7DatastreamProjectsLocationsConnectionProfilesGetRequestr"   Get)r%   r   get_reqs      r   _GetExistingConnectionProfilez6ConnectionProfilesClient._GetExistingConnectionProfile  s9    NN 	O 	
 
 ==W%%r   c                 L   t        j                  |      }t        j                  |      }| j                  j                  j
                  }t        j                  |||j                        j                  ||j                        }|j                  r|j                  |_	        yy)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   _UpdateLabelsz&ConnectionProfilesClient._UpdateLabels  s    88>J;;DAM11==J$$" eJ*112	 
 !!"/"6"6 "r   c                 (   g }|j                  d      r"|j                  |_        |j                  d       |dk(  r| j	                  |||       n|dk(  r| j                  |||       n|dk(  r| j                  |||       n|dk(  r| j                  |||       nw|dk(  r| j                  |||       n^|dk(  r| j                  ||||       nD|d	k(  rn>|d
k(  r| j                  |||       n%t        j                  |dj                  |            |t        j                  j                   k(  r%|j"                  j$                  j'                         }n$|j"                  j(                  j'                         }|rA| j*                  j-                  |j/                               |_        |j                  d       nD|j2                  r| j5                  |||       n$|j6                  ri |_        |j                  d       | j;                  ||       ||fS )z>Returns updated connection profile and list of updated fields.r   r   r   r   r   r   r   r   r   r   r   )privateConnectionNamer   r   )r  r   r   r   r'  r#  r+  r-  r/  r!  r2  r   r=   r>   r   r   r   r   r   r   r   r    r   r   r   r   r  r   r   rF  )r%   r   r  r   r,   r  r  s          r   _GetUpdatedConnectionProfilez5ConnectionProfilesClient._GetUpdatedConnectionProfile  s    M''+'8'8$=)'

dM3	H	
 2D-H	L	 
##$6mL	K	
""#5t]K	L	 
##$6mL	*	*

mT= 
J	
	I	
  !3T=I//
&/  ))...!%!F!F!L!L!N!%!A!A!G!G!I
..
,
,$<$I$I$K -  ,
 01		"	"
..
dM 
	$	$79489)40},,r   c                 ^   | j                  |       | j                  ||||      }d}|t        j                  j                  k(  s|j
                  rd}t        j                         }| j                  j                  }	 |	||j                  |||      }
| j                  j                  |
      S )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   rO  r   GenerateRequestIdr    :DatastreamProjectsLocationsConnectionProfilesCreateRequestr   r"   Create)r%   
parent_refr  r  r   r,   r   rO  
request_idcreate_req_type
create_reqs              r   rR  zConnectionProfilesClient.Create/  s    * 	t33G4I44AC E))...$**e'')JQQ  !,.33J ==
++r   c                    | j                  |       | j                  |      }| j                  ||||      \  }}d}|t        j                  j
                  k(  s|j                  rd}t        j                         }	| j                  j                  }
 |
||j                  dj                  |      |	|      }| j                  j                  |      S )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,)rK  r   
updateMaskrN  rO  )r-   r7  rI  r   r   r   rO  r   rP  r    9DatastreamProjectsLocationsConnectionProfilesPatchRequestr   joinr"   Patch)r%   r   r  r   r,   
current_cp
updated_cpr  rO  rT  update_req_type
update_reqs               r   UpdatezConnectionProfilesClient.Update[  s     	t33D9J $ A AG]D!2J E))...$**e'')JPP  !$__88M*J ==z**r   c                    | j                   j                  d||j                        }| j                  j                  } ||j                         |j                  |j                  rdj                  |j                        nd      }t        j                  | j                  j                  ||j                  |j                  dd      S )	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locationsIdrX  N)rM  filterorderByconnectionProfilespageSize)servicerequestlimit
batch_sizefieldbatch_size_attribute)r$   rR  locationr    8DatastreamProjectsLocationsConnectionProfilesListRequestr   re  sort_byr[  r   YieldFromListr   r!   rk  	page_size)r%   
project_idr,   location_reflist_req_typelist_reqs         r   ListzConnectionProfilesClient.List  s     ((//'MM 0 L 	OO  ((*{{*.,,&DH ##BBjj>>"') )r   c                 ^   | j                   j                         }|j                  r:|j                  j                  j	                         }|j                         |_        n-|j                  r!| j                  |j                  |      |_	        |j                  s|j                  rd|_        nU|j                  rt        |j                        |_        n.|j                   rt        |j                         |_        nd|_        |j"                  r1t%        j&                  | j                   |j"                  |      |_        n|j*                  r1t%        j,                  | j                   |j*                  |      |_        nw|j0                  r0t%        j2                  | j                   |j0                        |_        n;|j6                  r/t%        j8                  | j                   |j6                        |_        | j                   j<                  } |||      }| j>                  jA                  |      S )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) discoverConnectionProfileRequestrM  )!r     DiscoverConnectionProfileRequestconnection_profile_namer   r   r   connectionProfileNamer  r  rK  	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%   rS  r   r,   rj  connection_profile_refdiscover_req_typediscover_reqs           r   r  z!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                 \    | j                   j                  |d      }|j                         S )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   GetUrizConnectionProfilesClient.GetUri  s2     


1
1K 2 MC<<>r   )NNr   )-__name__
__module____qualname____doc__r(   r-   r*   r/   rH   rX   rd   r\   rq   r{   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r!  r#  r%  r'  r)  r+  r-  r/  r2  r7  rF  rI  rR  ra  rx  r  r   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   