
                             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   " S	 S
\R                   5      r " S S\5      rg)z3Database Migration Service connection profiles API.    N)Any)
list_pager)api_util)base)
exceptions)labels_utilc                       \ rS rSrSrSrg)'UnsupportedConnectionProfileDBTypeError   zFError raised when the connection profile database type is unsupported. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       Dlib/googlecloudsdk/api_lib/database_migration/connection_profiles.pyr
   r
      s    Nr   r
   c                      \ 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SCS 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/ r0S0 r1S1 r2S2 r3S3 r4S4 r5S5 r6S6 r7S7 r8S8 r9S9 r:S: r;SCS; jr<SCS< jr=S=\>S>\?4S? jr@S@ rASA rBSBrCg)DConnectionProfilesClient"   z2Client for connection profiles service in the API.c                    [         R                  " U5      U l        [         R                  " U5      U l        [         R
                  " U5      U l        U R                  R                  U l        [         R                  " U5      U l
        Xl        g N)r   GetApiVersion_api_versionGetClientInstanceclientGetMessagesModulemessages%projects_locations_connectionProfiles_serviceGetResourceParserresource_parser_release_track)selfrelease_tracks     r   __init__!ConnectionProfilesClient.__init__%   sc     ..}=D,,];DK..}=DMKKEEDM#55mDD'r   c                     UR                   R                  (       a  UR                   R                  OUR                   R                  nU(       a#  SR                  U5      R	                  S5      S   $ g)zGets the SQL engine from the Cloud SQL version.

Args:
  cloudsql: Cloud SQL connection profile

Returns:
  A string representing the SQL engine
z{}_r    )settingsdatabaseVersiondatabaseVersionNameformatsplit)r%   cloudsqldatabase_versoins      r   _GetEngineFromCloudSql/ConnectionProfilesClient._GetEngineFromCloudSql-   s`     ,, 	))22 
 [[)*005a88r   c                 @    UR                   (       a  gUR                  (       a  U R                  UR                  5      $ UR                  (       a  gUR                  (       a  gUR
                  (       a  gUR                  (       a  gg! [         a
  n SnAgSnAff = f)zGets the SQL engine name from the connection profile.

Args:
  profile: the connection profile

Returns:
  A string representing the SQL engine
MYSQLPOSTGRESr+   ORACLE	SQLSERVERN)mysqlr1   r3   
postgresqlalloydboracle	sqlserverAttributeError)r%   profiler*   s      r   GetEngineName&ConnectionProfilesClient.GetEngineNameB   sw    				**7+;+;<< 
							  	s.   B	 +B	  B	 B	 $B	 6B	 	
BBc                 &    U R                   S:X  a  gg)Nv1alpha2certificateclient_certificater   r%   s    r   _ClientCertificateArgName2ConnectionProfilesClient._ClientCertificateArgNameb   s    J&r   c                 &    U R                   S:X  a  gg)NrD   instancecloudsql_instancerG   rH   s    r   _InstanceArgName)ConnectionProfilesClient._InstanceArgNameg   s    J&r   c                 P    U R                   [        R                  R                  :H  $ r   r$   r   ReleaseTrackGArH   s    r   _SupportsPostgresql,ConnectionProfilesClient._SupportsPostgresqll       $"3"3"6"666r   c                 P    U R                   [        R                  R                  :H  $ r   rQ   rH   s    r   _SupportsOracle(ConnectionProfilesClient._SupportsOracleo   rV   r   c                 P    U R                   [        R                  R                  :H  $ r   rQ   rH   s    r   _SupportsSqlServer+ConnectionProfilesClient._SupportsSqlServerr   rV   r   c                 P    U R                   [        R                  R                  :H  $ r   rQ   rH   s    r   _SupportsSslType)ConnectionProfilesClient._SupportsSslTypeu   rV   r   Nc                 H    U R                  U5        U R                  X5        g r   )_ValidateHostArgs_ValidateSslConfigArgsr%   argscp_types      r   _ValidateArgs&ConnectionProfilesClient._ValidateArgsx   s    4 .r   c                     UR                  S5      (       d  g[        R                  " S5      nUR                  UR                  5      (       d  [
        R                  " SS5      eg )NhostTz$[a-zA-Z0-9][-.a-zA-Z0-9]*[a-zA-Z0-9]zUHostname and IP can only include letters, numbers, dots, hyphens and valid IP ranges.)IsKnownAndSpecifiedrecompilematchri   calliope_exceptionsInvalidArgumentException)r%   rd   patterns      r   ra   *ConnectionProfilesClient._ValidateHostArgs|   sX    ##F++jj?@G==##88
  $r   c                     US:X  d  US:X  a  U R                  U5        U R                  US5        U R                  XR                  5       5        U R                  US5        g )Nr6   r7   ca_certificateprivate_key)0_ValidateSslConfigCombinationForPostgresAndMySql_ValidateCertificateFormatrI   rc   s      r   rb   /ConnectionProfilesClient._ValidateSslConfigArgs   sY    'W
2
 ;;DA##D*:;##D*H*H*JK##D-8r   c                 Z   [        X5      (       a  UR                  U5      (       d  g[        X5      n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-----z8The certificate does not appear to be in PEM format:
{0})	hasattrIsSpecifiedgetattrstripr0   
startswithrn   ro   r/   )r%   rd   fieldrE   cert
cert_liness         r   rv   3ConnectionProfilesClient._ValidateCertificateFormat   s    4t'7'7'>'>$&KDD!JqM$$W--"~((1188

E6$<  2r   c                    U R                  5       (       a  UR                  S5      (       d  gUR                  S:X  aZ  UR                  S5      (       a-  UR                  S5      (       d  UR                  S5      (       d  g[        R                  " SS5      eUR                  S	:X  aZ  UR                  S5      (       a-  UR                  S5      (       a  UR                  S5      (       a  g[        R                  " SS
5      eUR                  S:X  d  UR                  S:X  as  UR                  S5      (       d-  UR                  S5      (       d  UR                  S5      (       d  g[        R                  " SSR                  UR                  5      5      e[        R                  " SSR                  UR                  5      5      e)a6  Validates the SSL config combination for PostgreSQL and MySQL when the ssl_type flag is specified.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Raises:
  calliope_exceptions.InvalidArgumentException: If the specified
  certificates and keys combination is invalid.
ssl_typeNSERVER_ONLYrs   rt   rF   sslz>Only ca_certificate must be provided for SSL type SERVER_ONLY.SERVER_CLIENTz_ca_certificate, client_certificate and private_key must be provided for SSL type SERVER_CLIENT.REQUIREDNONEzOCannot set ca_certificate, client_certificate and private_key for SSL type {0}.zUnsupported SSL type {0}.)r^   r|   r   rn   ro   r/   r%   rd   s     r   ru   IConnectionProfilesClient._ValidateSslConfigCombinationForPostgresAndMySql   s      ""$*:*::*F*F}}%


+
,
,""=11""#788!::L
 	
 }}'


+
,
,}--344!::4
 	

 
*	$(?/00""=11""#788!::!!'!6
 	
  88

%
,
,T]]
; r   c                 H    U R                   R                  UR                  S9$ )N)caCertificate)r   	SslConfigrs   r   s     r   _GetSslServerOnlyConfig0ConnectionProfilesClient._GetSslServerOnlyConfig   s     ==""1D1D"EEr   c                     UR                  S5      (       aL  U R                  R                  U R                  R                  R                  R                  UR
                  S9$ [        R                  " SS5      e)Nrs   )typer   4ca_certificate is required for SERVER_ONLY SSL type.)r|   r   r   TypeValueValuesEnumr   rs   rn   ro   r   s     r   _GetSslServerOnlyConfigWithType8ConnectionProfilesClient._GetSslServerOnlyConfigWithType   sm    ())]]$$}}&&::FF++ %  
  88

@ r   c                     U R                   R                  U R                   R                  R                  R                  S9$ N)r   )r   r   r   r   rH   s    r   _GetSslRequiredConfig.ConnectionProfilesClient._GetSslRequiredConfig   s7    ==""]]$$88AA #  r   c                     U R                   R                  U R                   R                  R                  R                  S9$ r   )r   r   r   r   rH   s    r   _GetSslNoneConfig*ConnectionProfilesClient._GetSslNoneConfig   s7    ==""]]$$88== #  r   c                 <   UR                  S5      (       d  gUR                  n/ nUR                  5        HA  u  pEUR                  U R                  R
                  R                  R                  XES95        MC     U R                  R
                  R                  US9$ )zGets the SSL flags.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  SslFlagsValue, to use when creating the connection profile.
	ssl_flagsN)keyvalue)additionalProperties)r|   r   itemsappendr   r   SslFlagsValueAdditionalProperty)r%   rd   ssl_flags_dictflagsr   r   s         r   _GetSslFlags%ConnectionProfilesClient._GetSslFlags   s     K((^^NE$**,
ll
--
!
!
/
/
B
B C  - ==""00e0LLr   c                    SnUR                  S5      (       ad  UR                  S:X  a  U R                  U5      nOiUR                  S:X  a  U R                  5       nOHUR                  S:X  a  U R	                  5       nO'UR                  S5      (       a  U R                  U5      nUb>  U R                  R                  UR                  UR                  U R                  U5      S9$ g)a9  Gets the SSL config based on the specified SSL type.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  SslConfig, to use when creating the connection profile.

Raises:
  calliope_exceptions.InvalidArgumentException: If the specified SSL type is
    unsupported.
Nr   r   r   r   rs   )r   r   sslFlags)r|   r   r   r   r   r   r   r   r   r   r   r%   rd   
ssl_configs      r   !_GetSslServerOnlyOrRequiredConfig:ConnectionProfilesClient._GetSslServerOnlyOrRequiredConfig  s     J
##	-	'99$?
==J&//1
==F"++-
			*	+	+//5j]]$$"00$$T* %   r   c                 h   S nU R                  5       (       aO  UR                  S5      (       a9  U R                  R                  R                  R                  UR                  5      nU R                  R                  UR                  UR                  U R                  5       5      UR                  US9$ )Nr   )	clientKeyclientCertificater   r   )r^   r|   r   r   r   lookup_by_namer   rt   GetValuerI   rs   )r%   rd   r   s      r   _GetSslConfig&ConnectionProfilesClient._GetSslConfig*  s    H4#3#3J#?#?((<<KK
--h ==""""--(F(F(HI))	 #  r   c                    U R                  5       (       a  UR                  S5      (       Gd  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                  U R                  5       5      (       aJ  UR                  U R                  5       5      UR                  R                  l        UR                  S5        g	g	U R                  U5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S:X  a  UR                  UR                  R                  l        S	UR                  R                  l        S	UR                  R                  l        U R                  R                  R                   R"                  UR                  R                  l        UR                  S
:X  a  UR                  UR                  R                  l        UR                  UR                  R                  l        UR                  U R                  5       5      UR                  R                  l        U R                  R                  R                   R&                  UR                  R                  l        g	UR                  S:X  d  UR                  S:X  a  S	UR                  R                  l        S	UR                  R                  l        S	UR                  R                  l        U R                  R                  R                   R)                  UR                  5      UR                  R                  l        g	g	)zIFills connection_profile and update_fields with MySQL SSL data from args.r   rs   zmysql.ssl.caCertificatert   zmysql.ssl.clientKeyzmysql.ssl.clientCertificatezmysql.ssl.typer   Nr   r   r   )r^   r|   rs   r:   r   r   r   rt   r   rI   r   r   ru   r   r   r   r   r   r   r   r   r%   connection_profilerd   update_fieldss       r   _UpdateMySqlSslConfig.ConnectionProfilesClient._UpdateMySqlSslConfig7  s     ""$*:*::*F*F 
		*	+	+595H5H  $$267			-	(	(151A1A  $$.23			$88:	;	;9=**,:
  $$6 	:;	 
< ;;DA458901+,	-	'595H5H  $$215  $$.9=  $$6MM##77CC 	  $$) 
/	)595H5H  $$2151A1A  $$.9=**,:
  $$6 MM##77EE 	  $$) ==J&$--6*A59  $$215  $$.9=  $$6MM##77FF 	  $$)	 +Br   c                     U R                  U5      nU R                  R                  UR                  UR                  UR
                  UR                  UUR                  U R                  5       5      S9$ )N)ri   portusernamepasswordr   
cloudSqlId)	r   r   MySqlConnectionProfileri   r   r   r   r   rN   r   s      r   _GetMySqlConnectionProfile3ConnectionProfilesClient._GetMySqlConnectionProfileh  sb    ##D)J==//YYYY==!6!6!89 0 ; ;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      (       a,  UR                  UR                  l        UR                  S5        UR                  U R                  5       5      (       a?  UR                  U R                  5       5      UR                  l	        UR                  S	5        U R                  XU5        g
)z!Updates MySQL connection profile.ri   z
mysql.hostr   z
mysql.portr   zmysql.usernamer   zmysql.passwordzmysql.instanceN)r|   ri   r:   r   r   r   r   rN   r   r   r   r   s       r   _UpdateMySqlConnectionProfile6ConnectionProfilesClient._UpdateMySqlConnectionProfiler  s,    &*ii#<(&*ii#<(
##*.--'+,
##*.--'+,--/00,0MM



!-#)+,1Gr   c                    U R                  5       (       a  UR                  S5      (       Gd  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                  U R                  5       5      (       aJ  UR                  U R                  5       5      UR                  R                  l        UR                  S5        g	g	U R                  U5        UR                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  S:X  a  UR                  UR                  R                  l        S	UR                  R                  l        S	UR                  R                  l        U R                  R                  R                   R"                  UR                  R                  l        UR                  S
:X  a  UR                  UR                  R                  l        UR                  UR                  R                  l        UR                  U R                  5       5      UR                  R                  l        U R                  R                  R                   R&                  UR                  R                  l        g	UR                  S:X  d  UR                  S:X  a  S	UR                  R                  l        S	UR                  R                  l        S	UR                  R                  l        U R                  R                  R                   R)                  UR                  5      UR                  R                  l        g	g	)zNFills connection_profile and update_fields with PostgreSQL SSL data from args.r   rs   zpostgresql.ssl.caCertificatert   zpostgresql.ssl.clientKeyz postgresql.ssl.clientCertificatezpostgresql.ssl.typer   Nr   r   r   )r^   r|   rs   r;   r   r   r   rt   r   rI   r   r   ru   r   r   r   r   r   r   r   r   r   s       r   _UpdatePostgreSqlSslConfig3ConnectionProfilesClient._UpdatePostgreSqlSslConfig  s     ""$*:*::*F*F 
		*	+	+:>:M:M%%))7;<			-	(	(6:6F6F%%))378			$88:	;	;>Bmm**,?
%%)); 	?@	 
< ;;DA9:=>5601	-	':>:M:M%%))76:%%))3>B%%));MM##77CC 	%%)). 
/	):>:M:M%%))76:6F6F%%))3>Bmm**,?
%%)); MM##77EE 	%%)). ==J&$--6*A:>%%))76:%%))3>B%%));MM##77FF 	%%)).	 +Br   c                    U R                  U5      nU R                  S:X  a  UR                  OSnU R                  R	                  UR
                  UR                  UR                  UR                  UR                  UUR                  U R                  5       5      US9nUR                  S5      (       a  [        UR                  5      Ul        UR                  S5      (       aR  UR                   R"                  R%                  5       nU R                  R'                  UR)                  5       S9Ul        U$ UR                  S5      (       a  U R-                  U5      Ul        U$ UR                  S5      (       a	  0 Ul        U$ UR                  S	5      (       aP  UR                   R2                  R%                  5       nU R                  R5                  UR)                  5       S
9Ul        U$ )zCreates a Postgresql connection profile according to the given args.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  PostgreSqlConnectionProfile, to use when creating the connection profile.
v1r+   )ri   r   r   r   databaser   r   alloydbClusterIdenable_iam_authenticationprivate_connectionprivateConnectionforward_ssh_hostnamestatic_ip_connectivitypsc_service_attachmentserviceAttachment)r   r   alloydb_clusterr   PostgreSqlConnectionProfileri   r   r   r   r   r   rN   rj   boolr   enableIamAuthenticationCONCEPTSr   ParsePrivateConnectivityRelativeNameprivateConnectivity _GetForwardSshTunnelConnectivityforwardSshConnectivitystaticIpConnectivityr   !PrivateServiceConnectConnectivity!privateServiceConnectConnectivity)r%   rd   r   r   connection_profile_objprivate_connectivitypsc_refs          r   _GetPostgreSqlConnectionProfile8ConnectionProfilesClient._GetPostgreSqlConnectionProfile  s    ##D)J.2.?.?4.Gd**RO!]]FFYYYY==!6!6!89( G 	  ;<<7;

(
(84  455!]]==CCE
--
+
+ 4 A A C ,  0$ "! 
	!	!"8	9	9

/
/
5 3 "! 
	!	!":	;	;461 "! 
	!	!":	;	;44::<g
--
9
9 ' 4 4 6 :  >
 "!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      (       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      (       a5  [        UR                  5      UR                  l        UR                  S5        UR                  U R                  5       5      (       a?  UR                  U R                  5       5      UR                  l        UR                  S5        U R                  S:X  aB  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.ri   zpostgresql.hostr   zpostgresql.databaser   zpostgresql.portr   zpostgresql.usernamer   zpostgresql.passwordr   z$postgresql.enable_iam_authenticationzpostgresql.instancer   r   zpostgresql.alloydb_clusterN)r|   ri   r;   r   r   r   r   r   rj   r   r   r   rN   r   r   r   r   r   r   r   s       r   "_UpdatePostgreSqlConnectionProfile;ConnectionProfilesClient._UpdatePostgreSqlConnectionProfile  s    +/99##(,-
##/3}}##,01+/99##(,-
##/3}}##,01
##/3}}##,01 ;<<>B

(
(?##; AB--/0015



!2###.01D T%5%56G%H%H7;7K7K##478##$6mLr   c                     UR                  S5      (       a7  UR                  UR                  R                  l        UR                  S5        gg)zJFills connection_profile and update_fields with Oracle SSL data from args.rs   zoracle.ssl.caCertificateN)r|   rs   r=   r   r   r   r   s       r   _UpdateOracleSslConfig/ConnectionProfilesClient._UpdateOracleSslConfig  sC    ())484G4G##156 *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      (       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                  XU5        g)z"Updates Oracle connection profile.ri   zoracle.hostr   zoracle.portr   zoracle.usernamer   zoracle.passworddatabase_servicezoracle.databaseServiceN)
r|   ri   r=   r   r   r   r   r   databaseServicer   r   s       r   _UpdateOracleConnectionProfile7ConnectionProfilesClient._UpdateOracleConnectionProfile  s    '+yy$=)'+yy$=)
##+/==(,-
##+/==(,-*++262G2G/34 2-Hr   c                    UR                   UR                  R                  l        U R                  R
                  R                  R                  UR                  R                  l        UR                  S5        UR                  S5        g )Nsqlserver.ssl.caCertificatesqlserver.ssl.type)
rs   r>   r   r   r   r   r   r   r   r   r   s       r   #_UpdateSqlServerSslConfigServerOnly<ConnectionProfilesClient._UpdateSqlServerSslConfigServerOnly&  sl     6:5H5H  $$233??   $$) 67-.r   c                 4   UR                  S5      (       GaX  UR                  S:X  a@  UR                  S5      (       a  U R                  XU5        g[        R                  " SS5      eUR                  S:X  d  UR                  S:X  a  UR                  S5      (       aA  UR
                  (       a0  [        R                  " SSR                  UR                  5      5      eSUR                  R                  l	        U R                  R                  R                  R                  UR                  5      UR                  R                  l        UR                  S	5        UR                  S
5        ggUR                  S5      (       a  U R                  XU5        gg)zMFills connection_profile and update_fields with SqlServer SSL data from args.r   r   rs   r   r   r   z+Cannot set CA certificate for SSL type {0}.Nr   r   )r|   r   r   rn   ro   rs   r/   r>   r   r   r   r   r   r   r   r   r   s       r   _UpdateSqlServerSslConfig2ConnectionProfilesClient._UpdateSqlServerSslConfig0  s_   
##	-	',--

2
2  $<<D  ==J&$--6*A,--$2E2E#<<;BB--  :>$$((6MM##77FF 	$$((-
 	:;12 +B  
		*	+	+
..
M 
,r   c                 X   UR                  S5      (       a?  UR                  U R                  5       5      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        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                  R                  c  [         R"                  " SS5      eU R%                  U5      UR                  l        UR                  S5        U R'                  XU5        g)z%Updates SqlServer connection profile.rM   zsqlserver.cloudSqlIdcloudsql_project_idzsqlserver.cloudSqlProjectIdri   zsqlserver.hostr   zsqlserver.portdbm_portzsqlserver.dbmPortr   zsqlserver.usernamer   zsqlserver.passwordr   zsqlserver.database
gcs_bucketNzWCannot update GCS Bucket or GCS Prefix for a destination SQL Server connection profile.zsqlserver.backups)r|   r   rN   r>   r   r   r  cloudSqlProjectIdri   r   r  dbmPortr   r   r   backupsrn   ro   _GetSqlServerBackupsr   r   s       r   !_UpdateSqlServerConnectionProfile:ConnectionProfilesClient._UpdateSqlServerConnectionProfileR  s-    +,,04



!1""- 12-..7;7O7O""489*.))""'+,*.))""'+,
##-1]]""*./
##.2mm""+/0
##.2mm""+/0
##.2mm""+/0%%		%	%	-	-	5!::*
 	

 .2-F-Ft-L""*./""#5]Kr   c                 j    Uc  UR                   R                  $ UR                   R                  U5      $ r   )ProviderValueValuesEnumDATABASE_PROVIDER_UNSPECIFIEDr   )r%   re   providers      r   _GetProvider%ConnectionProfilesClient._GetProvider{  s1    ,,JJJ**99(CCr   c                 8    UR                   R                  U5      $ r   )RoleValueValuesEnumr   )r%   re   roles      r   _GetRole!ConnectionProfilesClient._GetRole  s    &&55d;;r   c                 j    Uc  UR                   R                  $ UR                   R                  U5      $ r   )ActivationPolicyValueValuesEnum!SQL_ACTIVATION_POLICY_UNSPECIFIEDr   )r%   re   policys      r   _GetActivationPolicy-ConnectionProfilesClient._GetActivationPolicy  s4    ~

1
1
S
S 22AA&IIr   c                 8    UR                   R                  U5      $ )zoReturns the database version.

Args:
  cp_type: str, the connection profile type.
  version: database version.
)DatabaseVersionValueValuesEnumr   )r%   re   versions      r   _GetDatabaseVersion,ConnectionProfilesClient._GetDatabaseVersion  s     11@@IIr   c                 z    U R                   R                  nUR                   Vs/ s H	  nU" US9PM     sn$ s  snf )N)	cidrRange)r   AuthorizedNetworkauthorized_network_cidr_ranges)r%   rd   authorized_networkrs       r   _GetAlloyDbAuthorizedNetworks6ConnectionProfilesClient._GetAlloyDbAuthorizedNetworks  sD    88 444A 	Q'4  s   8c                 f    U R                   R                  nU Vs/ s H	  nU" US9PM     sn$ s  snf )N)r   )r   SqlAclEntry)r%   networks	acl_entrynetworks       r   _GetAuthorizedNetworks/ConnectionProfilesClient._GetAuthorizedNetworks  s=    ))I  G 	   s   .c                     U R                   R                  UR                  UR                  UR                  U R                  UR                  5      S9nU R                  S:X  a  UR                  Ul	        U$ )N)
enableIpv4privateNetwork
requireSslauthorizedNetworksr   )
r   SqlIpConfigenable_ip_v4private_networkrequire_sslr-  authorized_networksr   allocated_ip_rangeallocatedIpRange)r%   rd   	ip_configs      r   _GetIpConfig%ConnectionProfilesClient._GetIpConfig  sn    ))$$++##66t7O7OP	 * I D #'#:#:i r   c                 j    Uc  UR                   R                  $ UR                   R                  U5      $ r   )DataDiskTypeValueValuesEnumSQL_DATA_DISK_TYPE_UNSPECIFIEDr   )r%   re   data_disk_types      r   _GetDataDiskType)ConnectionProfilesClient._GetDataDiskType  s1    11PPP..==nMMr   c                 j    Uc  UR                   R                  $ UR                   R                  U5      $ r   )AvailabilityTypeValueValuesEnum!SQL_AVAILABILITY_TYPE_UNSPECIFIEDr   )r%   re   availability_types      r   _GetAvailabilityType-ConnectionProfilesClient._GetAvailabilityType  s:     

1
1
S
S 22AA r   c                     UR                  S5      (       aW  U R                  R                  R                  R	                  UR
                  R                  SS5      R                  5       5      $ g )Nedition-r*   )rj   r   CloudSqlSettingsEditionValueValuesEnumr   rK  replaceupperr   s     r   _GetEdition$ConnectionProfilesClient._GetEdition  sX    	**
--
(
(
?
?
N
Nll""3,224 r   c                 |    UR                  S5      (       a&  U R                  R                  nU" UR                  S9$ g )Nenable_data_cache)dataCacheEnabled)rj   r   DataCacheConfigrT  )r%   rd   data_cache_config_objs      r   _GetDataCacheConfig,ConnectionProfilesClient._GetDataCacheConfig  s?     344"mm;;"11  r   c                    U R                   R                  nUR                  R                  R	                  5       R                  5       n[        R                  " XR                  S5      n[        R                  " XR                  S5      nU R                   R                  UUR                  UR                  U R                  X!R                  5      U R                  U5      UR                  UU R!                  X!R"                  5      UR$                  UR&                  UR(                  US9nUR*                  (       a!  U R-                  X!R*                  5      Ul        OUR0                  Ul        U R4                  S:X  a]  U R7                  X!R8                  5      Ul        UR<                  Ul        U RA                  U5      Ul!        U RE                  U5      Ul#        U RH                  [J        RL                  RN                  :X  a\  UR                  RP                  R	                  5       b7  UR                  RP                  R	                  5       R                  5       Ul)        U$ )zCreates a Cloud SQL connection profile according to the given args.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  CloudSqlConnectionProfile, to use when creating the connection profile.
user_labelsdatabase_flags)
userLabelstierstorageAutoResizeLimitactivationPolicyipConfigautoStorageIncreasedatabaseFlagsdataDiskTypedataDiskSizeGbzonerootPasswordsourceIdr   )*r   rM  r   	source_idr   r   r   ParseCreateArgsUserLabelsValueDatabaseFlagsValuer^  storage_auto_resize_limitr  activation_policyr<  auto_storage_increaserB  rA  data_disk_sizerf  root_passworddatabase_versionr  r-   database_version_namer.   r   rH  rG  availabilityTypesecondary_zonesecondaryZonerQ  rK  rX  dataCacheConfigr$   r   rR   rS   cmek_keycmekKeyName)r%   rd   re   ri  user_labels_valuer\  cloud_sql_settingss          r   _GetCloudSqlSettings-ConnectionProfilesClient._GetCloudSqlSettings  s    mm,,G''--/<<>I#33%%}6 00((*:<N77$YY#==22++
 ""4( 66$**74G4GH**YY'' 8   +/+C+C
((,( 04/I/I,D ,0,E,E
))-) *.)<)<&#'#3#3D#9 +/+C+CD+I(t00333MM""((*6 --
 
 
&
&
(
5
5
7 $ r   c                 V    U R                  U5      nU R                  R                  US9$ )N)r,   )r|  r   CloudSqlConnectionProfile)r%   rd   r,   s      r   _GetCloudSqlConnectionProfile6ConnectionProfilesClient._GetCloudSqlConnectionProfile  s*    ((.H==22H2EEr   c                     UR                  S5      (       a9  U R                  R                  R                  R	                  UR
                  5      $ g )Nrr  )rj   r   AlloyDbSettingsr  r   rr  r   s     r   _GetAlloyDBDatabaseVersion3ConnectionProfilesClient._GetAlloyDBDatabaseVersion	  sA     233
--
'
'
F
F>$//0
 r   c                 t   U R                   R                  nU R                   R                  n[        R                  " UUR
                  S5      n[        R                  " UUR
                  S5      n[        R                  " XR                  S5      nU" UR                  U R                   R                  UR                  S9U R                   R                  UR                  UR                  U R                  U5      S9UUS9nU" U R                   R                  SUR                  S9UR                   UUS	9nU R#                  U5      Ul        UR&                  R(                  R+                  5       nUb,  U R                   R-                  UR/                  5       S
9Ul        U R                   R3                  X#S9$ )a  Creates an AlloyDB connection profile according to the given args.

Uses the connection profile ID as the cluster ID, and also sets "postgres"
as the initial user of the cluster.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.
  connection_profile_id: str, the ID of the connection profile.

Returns:
  AlloyDBConnectionProfile, to use when creating the connection profile.
cluster_labelsprimary_labelsr\  )cpuCount)enablePublicIpenableOutboundPublicIpauthorizedExternalNetworks)idmachineConfiginstanceNetworkConfigrc  labelspostgres)userr   )initialUser
vpcNetworkr  primaryInstanceSettings)
kmsKeyName)	clusterIdr,   )r   r  PrimaryInstanceSettingsr   rj  LabelsValuerl  
primary_idMachineConfig	cpu_countInstanceNetworkConfigenable_public_ipenable_outbound_public_ipr&  UserPasswordr   r,  r  r-   r   kms_keyr   EncryptionConfigr   encryptionConfigAlloyDbConnectionProfile)	r%   rd   connection_profile_idcluster_settingsprimary_settingsr  r  r\  kms_key_refs	            r   _GetAlloyDBConnectionProfile5ConnectionProfilesClient._GetAlloyDBConnectionProfile  s    }}44}}<< 001A1M1M1ACN !001A1M1M1ACN !00113CEN (??mm114>>1J"mmAA00#'#A#A'+'I'I$'O B 

 %
 (MM..dmm / 5<< 02 (,'F'Ft'L$--''--/K*.--*H*H --/ +I +' ==11' 2 D Dr   c                     U R                   R                  UR                  [        UR                  5      UR
                  UR                  UR                  S9$ )N)hostnamer   r   
privateKeyr   )r   ForwardSshTunnelConnectivityr   intforward_ssh_portforward_ssh_usernameforward_ssh_private_keyforward_ssh_passwordr   s     r   r   9ConnectionProfilesClient._GetForwardSshTunnelConnectivityG  sP    ==55**&&'**//** 6 , ,r   c           	         U R                  U5      nU R                  R                  UR                  UR                  UR
                  UR                  UUR                  S9nUR                  R                  R                  5       nU(       a.  U R                  R                  UR                  5       S9Ul        U$ UR                  (       a  U R                  U5      Ul        U$ UR"                  (       a  0 Ul        U$ )zCreates an Oracle connection profile according to the given args.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  OracleConnectionProfile, to use when creating the connection profile.
)ri   r   r   r   r   r   r   )r   r   OracleConnectionProfileri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticServiceIpConnectivity)r%   rd   r   r   private_connectivity_refs        r   _GetOracleConnectionProfile4ConnectionProfilesClient._GetOracleConnectionProfileO  s     --d3J!]]BBYYYY-- C   $}}??EEG
--
+
+ 8 E E G ,  0 "! 
	"	"

/
/
5 3
 "! 
	$	$;=8!!r   c                     U R                   R                  UR                  S9nUR                  S5      (       a  UR                  Ul        U$ )N)	gcsBucket
gcs_prefix)r   SqlServerBackupsr  rj   r  	gcsPrefix)r%   rd   backups_objs      r   r  -ConnectionProfilesClient._GetSqlServerBackupsr  s@    --004??0KK--"ookr   c                 $   U R                   R                  U R                  U5      S9nUR                  S5      (       aJ  UR                  Ul        UR
                  Ul        UR                  S5      (       a  UR                  Ul        O,UR                  S5      (       a  U R                  U5      Ul	        UR                  S5      (       a  UR                  Ul
        UR                  Ul        UR                  S5      (       a$  UR                  U R                  5       5      Ul        UR                  S5      (       a  UR                  Ul        UR                  S5      (       a  UR"                  Ul        UR                  S	5      (       aR  UR$                  R&                  R)                  5       nU R                   R+                  UR-                  5       S
9Ul        U$ UR                  S5      (       a  U R1                  U5      Ul        U$ UR                  S5      (       a	  0 Ul        U$ UR                  S5      (       aP  UR$                  R6                  R)                  5       nU R                   R9                  UR-                  5       S9Ul        U$ )zCreates an SQL Server connection profile according to the given args.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  SqlServerConnectionProfile, to use when creating the connection profile.
)r   ri   r  r  r   rM   r  r   r   r   r   r   r   r   )r   SqlServerConnectionProfiler   rj   ri   r   r  r  r  r  r   r   r   rN   r   r  r  r   r   r   r   r   r   r   r   r   r   r   r   r   )r%   rd   r   r   r   s        r   _GetSqlServerConnectionProfile7ConnectionProfilesClient._GetSqlServerConnectionProfilex  sN    "]]EE2248 F  ''$(II!$(II!		!	!*	-	-)-&		!	!,	/	/'+'@'@'F$
++(,%(,%		!	!"5	6	6,0MM!!#-
) 
	!	!"7	8	8373K3K0
++(,% 455!]]==CCE
--
+
+ 4 A A C ,  0$ "! 
	!	!"8	9	9

/
/
5 3 "! 
	!	!":	;	;461 "! 
	!	!":	;	;44::<g
--
9
9 ' 4 4 6 :  >
 "!r   c                 0   U R                   R                  n[        R                  " X$R                  5      n0 nUS:X  a4  U R                  U5      nXvS'   U R                  XBR                  5      US'   OUS:X  a4  U R                  U5      nXS'   U R                  XBR                  5      US'   OUS:X  a  U R                  U5      n	XS'   OqUS:X  a  U R                  X#5      n
XS	'   OUUS
:X  a  U R                  U5      nXS'   O9US:X  a3  U R                  U5      nXS'   U R                  XBR                  5      US'   UR                  S5      (       a  U R                  XBR                  5      US'   U" SUUR                   R"                  UR$                  S.UD6$ )z/Returns a connection profile according to type.r6   r:   r  CLOUDSQLr1   
POSTGRESQLr;   ALLOYDBr<   r8   r=   r9   r>   r  )r  statedisplayNamer   )r   ConnectionProfiler   rj  r  r   r  r  r  r   r  r  r  rj   r  r  StateValueValuesEnumCREATINGdisplay_name)r%   re   rd   r  connection_profile_typer  paramsmysql_connection_profilecloudsql_connection_profilepostgresql_connection_profilealloydb_connection_profileoracle_connection_profilesqlserver_connection_profiles                r   _GetConnectionProfile.ConnectionProfilesClient._GetConnectionProfile  s   "mm==((11F F'!%!@!@!F0Wo,,
!==fZ 
J	$($F$Ft$L!6Z,,
!==fZ 
L	 &*&J&J4&P#:\	I	#'#D#D
$  5Y	H	"&"B"B4"H2X	K	%)%H%H%N"8[,,
!==fZ ''}}%<iiHfVn" %::CC%% 	 r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )N)name)r   :DatamigrationProjectsLocationsConnectionProfilesGetRequestr!   Get)r%   r  get_reqs      r   _GetExistingConnectionProfile6ConnectionProfilesClient._GetExistingConnectionProfile  s6    mmVV W G ==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   rd   
add_labelsremove_labels
value_typeupdate_results          r   _UpdateLabels&ConnectionProfilesClient._UpdateLabels  s    88>J;;DAM00<<J$$" eJ112	 
 !!"/"6"6 "r   c                 4   / nUR                  S5      (       a"  UR                  Ul        UR                  S5        UR                  b  U R                  UUU5        OU R                  5       (       a   UR                  b  U R                  XU5        OuU R                  5       (       a   UR                  b  U R                  XU5        O@U R                  5       (       a   UR                  b  U R                  XU5        O[        S5      eU R!                  X5        X4$ )z>Returns updated connection profile and list of updated fields.r  r  zThe requested connection profile does not contain a MySQL, PostgreSQL or Oracle object. Currently only MySQL, PostgreSQL and Oracle connection profiles are supported.)r|   r  r  r   r:   r   rT   r;   r   rX   r=   r   r[   r>   r  r
   r  r   s       r   _GetUpdatedConnectionProfile5ConnectionProfilesClient._GetUpdatedConnectionProfile  s   M'''+'8'8$=)+
(();)-)68 
"
"
$
$

'
'
3
--.@.;=					$6$=$=$I
))
M 
	 	 	"	"'9'C'C'O
,,
M 47  	)0,,r   c                     U R                  XC5        U R                  X4U5      n[        R                  " 5       nU R                  R
                  nU" U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
    datamigration.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', 'POSTGRESQL',
    ''
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for creating the connection profile.
)connectionProfileconnectionProfileIdparent	requestId)rf   r  r   GenerateRequestIdr   =DatamigrationProjectsLocationsConnectionProfilesCreateRequestr!   Create)	r%   
parent_refr  re   rd   r   
request_idcreate_req_type
create_reqs	            r   r  ConnectionProfilesClient.Create  sz     	t%33G4IK ++-JSS  !,1	J ==
++r   c                 <   U R                  U5        U R                  U5      nU R                  X25      u  pE[        R                  " 5       nU R
                  R                  nU" UUR                  SR                  U5      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.
  args: argparse.Namespace, The arguments that this command was
      invoked with.

Returns:
  Operation: the operation for updating the connection profile.
,)r  r  
updateMaskr  )rf   r  r  r   r  r   <DatamigrationProjectsLocationsConnectionProfilesPatchRequestr  joinr!   Patch)	r%   r  rd   
current_cp
updated_cpr   r  update_req_type
update_reqs	            r   UpdateConnectionProfilesClient.Update/  s     	t33D9J $ A A!J ++-JRR  !$__88M*	J ==z**r   r  returnc                     U R                  U5      n[        R                  " 5       nU R                  R                  nU" UUR
                  SSUS9nU R                  R                  U5      $ )zTest a connection profile.

Args:
  name: str, the reference of the connection profile to test.

Returns:
  Operation: the operation for testing the connection profile.
r  T)r  r  r  validateOnlyr  )r  r   r  r   r  r  r!   r  )r%   r  r  r  r	  r
  s         r   TestConnectionProfilesClient.TestO  sj     33D9J++-JRR  !$__ J ==z**r   c           	         U R                   R                  SUUR                  S5      (       a  UR                  OS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 datamigration.projects.locationsregionrL  )
projectsIdlocationsIdr  N)r  filterorderByconnectionProfilespageSize)servicerequestlimit
batch_sizer   batch_size_attribute)r#   r  rj   r  r   ;DatamigrationProjectsLocationsConnectionProfilesListRequestr   r  sort_byr  r   YieldFromListr   r    r  	page_size)r%   
project_idrd   location_reflist_req_typelist_reqs         r   ListConnectionProfilesClient.Listi  s     ''..*#'#;#;H#E#EDKK3 / PL 	QQ  ((*{{*.,,&DBH
 ##AAjj>>"') )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
z3datamigration.projects.locations.connectionProfiles)
collection)r#   ParseRelativeNameSelfLink)r%   r  uris      r   GetUriConnectionProfilesClient.GetUri  s4     


0
0H 1 JC <<>r   )r   r$   r!   r   r   r#   r   )Dr   r   r   r   r   r'   r3   rA   rI   rN   rT   rX   r[   r^   rf   ra   rb   rv   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r&  r-  r<  rB  rH  rQ  rX  r|  r  r  r  r   r  r  r  r  r  r  r  r  r  strr   r  r'  r.  r   r   r   r   r   r   "   s[   :(*@ 

7777/		98tF


M2>/
b;H*/
b1"fM@7I*/ D'LRD
<JJ	N
5nF3Dj,!"F6"p*X&7-@,@+@+s +s +4)>r   r   )r   rk   typingr   apitools.base.pyr   )googlecloudsdk.api_lib.database_migrationr   googlecloudsdk.callioper   r   rn   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corecore_exceptionsErrorr
   objectr   r   r   r   <module>r:     sF    : 
  ' > ( E < =Oo.C.C Osv sr   