
    M              	          S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSKJr  SSKJ
r  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKrSrSr\S-   rSSSSSS.r\R>                  R@                  S\R>                  RB                  S0\R>                  R@                  S\R>                  RB                  S0\R>                  R@                  S\R>                  RB                  S0\R>                  R@                  S\R>                  RB                  S0\R>                  R@                  S \R>                  RB                  S0\R>                  R@                  S!\R>                  RB                  S0S".r"S# r#\S$4S% jr$\4S& jr%\4S' jr&S( r'S) r(\R>                  R@                  4S* jr)\R>                  R@                  4S+ jr*S, r+S- r,S. r-S/ r. SFS0 jr/S1 r0S2 r1S3 r2S4 r3S5 r4\R>                  R@                  4S6 jr5S7 r6S8 r7S9 r8\R>                  R@                  4S: jr9S; r:S< r;S= r<S> r=S? r>S@ r?SA r@SB rASC rB\R>                  R@                  4SD jrC\R>                  R@                  4SE jrDg)GzCloud Datastream API utilities.    )absolute_import)division)unicode_literalsN)encoding)
exceptions)camel_case_utils)apis)base)util)	resources)yaml)
console_iov1
datastream_camel_case_conversioninclude_objectsexclude_objectssource_connection_profiledestination_connection_profilevpc)	allowlist
rejectlistsource_connection_profile_name#destination_connection_profile_namevpc_nameschema_nameschemadatabase_namedatabase
table_nametablecolumn_namecolumnr   r   )r   r   r!   r#   r   r   c                     [         R                  " [        [        USS9n[        R
                  " U SS9n[        R                  " U5      n[        UUUS9nU$ )z2Parses a config message and validates it's schema.F)for_helpbinary)message_typeparsed_yamlschema_path)	export_utilGetSchemaPath_DEFAULT_API_NAME_DEFAULT_API_VERSIONr   ReadFromFileOrStdinr   load$CreateMessageWithCamelCaseConversion)config_file_pathr   r(   r*   datar)   messages          -lib/googlecloudsdk/api_lib/datastream/util.pyParseMessageAndValidateSchemar6   L   sX    ))-{U+
 
	'	'(8	G$		$+0' 
.    Fc                 ,    [         R                  " SXS9$ )Nr   )no_http)r	   GetClientInstance)api_versionr9   s     r5   r:   r:   _   s    			k	KKr7   c                 0    [         R                  " SU 5      $ Nr   )r	   GetMessagesModule)r;   s    r5   r>   r>   c   s    			k	::r7   c                 T    [         R                  " 5       nUR                  SU 5        U$ r=   )r   RegistryRegisterApiByName)r;   resource_parsers     r5   GetResourceParserrC   g   s&    &&(/##L+>	r7   c                 $    SR                  X5      $ )a  Get the resource name of the parent collection.

Args:
  project: the project of the parent collection.
  location: the GCP region of the membership.

Returns:
  the resource name of the parent collection in the format of
  `projects/{project}/locations/{location}`.
zprojects/{}/locations/{})format)projectlocations     r5   	ParentRefrH   m   s     
$	*	*7	==r7   c                  T    [         R                  " [        R                  " 5       5      $ )ziGenerates a UUID to use as the request ID.

Returns:
  string, the 40-character UUID for the request ID.
)six	text_typeuuiduuid4 r7   r5   GenerateRequestIdrO   |   s     
tzz|	$$r7   c                     U[         R                  R                  :w  a  [        USU R                  5      $ [        XU5      $ )z6Parses a mysql_rdbms_file into the MysqlRdbms message.
MysqlRdbms)r
   ReleaseTrackBETAr6   rQ   ParseMysqlRdbmsFileBeta)messagesmysql_rdbms_filerelease_tracks      r5   ParseMysqlRdbmsFilerX      sA     d'',,,(,(;(;  
!]	KKr7   c                     U[         R                  R                  :w  a  [        USU R                  5      $ [        XU5      $ )z8Parses a oracle_rdbms_file into the OracleRdbms message.OracleRdbms)r
   rR   rS   r6   rZ   ParseOracleRdbmsFileBeta)rU   oracle_rdbms_filerW   s      r5   ParseOracleRdbmsFiler]      sA     d'',,,(=(*>*>  
"(}	MMr7   c                 0    [        USU R                  5      $ )z@Parses a postgresql_rdbms_file into the PostgresqlRdbms message.PostgresqlRdbms)r6   r_   )rU   postgresql_rdbms_files     r5   ParsePostgresqlRdbmsFilera      s    	&.0H0H
 r7   c                 0    [        USU R                  5      $ )z>Parses a sqlserver_rdbms_file into the SqlServerRdbms message.SqlServerRdbms)r6   rc   )rU   sqlserver_rdbms_files     r5   ParseSqlServerRdbmsFilere      s    	&,h.E.E
 r7   c                 0    [        USU R                  5      $ )z<Parses a salesforce_org_file into the SalesforceOrg message.SalesforceOrg)r6   rg   )rU   salesforce_org_files     r5   ParseSalesforceOrgFileri      s    	&?H,B,B
 r7   c                 0    [        USU R                  5      $ )z6Parses a mongodb_file into the MongodbCluster message.MongodbCluster)r6   rk   )rU   mongodb_files     r5   ParseMongodbFilerm      s    	&$h&=&=
 r7   c                    [         R                  " U5      nU(       a  [        R                  " X25         [        R
                  " X5      nU$ ! [         a*  n[        R                  " SR                  U5      5      eSnAff = f)a  Create a message from a yaml dict.

Similar to export_util.Import (since we convert to camel case before)
Args:
  message_type: a Datastream message type to create.
  parsed_yaml: dict
  schema_path: str, path to the message schema to validate against.

Returns:
  a Datastream message.
zCannot parse YAML: [{0}]N)
r   ConvertYamlToCamelCaser+   ValidateYAMLapi_encodingPyValueToMessage	Exceptionr   
ParseErrorrE   )r(   r)   r*   converted_yamlr4   es         r5   r1   r1      ss     $::;G.^9F++LIG 
. 
 F


 : A A! D
EEFs   A 
B%A<<Bc                 L    [         R                  U 0 5      R                  X5      $ N!RDBMS_FIELD_NAME_BY_RELEASE_TRACKgetfieldrW   s     r5   GetRDBMSV1alpha1ToV1FieldNamer~      %    	*	.	.ub	9	=	=
 r7   c                 L    [         R                  U 0 5      R                  X5      $ rx   ry   r|   s     r5   _GetRDBMSFieldNamer      r   r7   c                    U R                  UR                  [        SU5      S5      S9nUR                  S5      nUb  XCl        UR                  S5      nUb  XSl        UR                  S5      nUb  Xcl        UR                  S5      nUb  Xsl        UR                  S5      nUb  Xl        UR                  S	5      n	U	b  Xl        U$ )
zAParses a raw mysql column json/yaml into the MysqlColumn message.r#    r#   	data_type	collationlengthnullableordinal_positionprimary_key)	MysqlColumnr{   r   dataTyper   r   r   ordinalPosition
primaryKey)
rU   mysql_column_objectrW   r4   r   r   r   r   r   r   s
             r5   ParseMysqlColumnr      s       $$
X}
5r; ! <' "%%k2) !%%k2)!""8,&N $$Z0((,,-?@!.#''6+$	.r7   c                    / nUR                  S/ 5       H  nUR                  [        XU5      5        M      [        SU5      nUR                  U5      nU(       d  [        R
                  " SU-  5      eU R                  XcS9$ )z?Parses a raw mysql table json/yaml into the MysqlTable message.mysql_columnsr!   $Cannot parse YAML: missing key "%s".)r!   mysqlColumns)r{   appendr   r   ds_exceptionsrt   
MysqlTable)rU   mysql_table_objectrW   mysql_column_msg_listr#   	table_keyr    s          r5   ParseMysqlTabler      s    "&&;f  =9; < !-8)!%%i0*	

"
"#I#,$- . .			 
 
< <r7   c                    / nUR                  S/ 5       H  nUR                  [        XU5      5        M      [        SU5      nUR                  U5      nU(       d  [        R
                  " SU-  5      eU R                  XcS9$ )zEParses a raw mysql database json/yaml into the MysqlDatabase message.mysql_tablesr   r   )r   mysqlTables)r{   r   r   r   r   rt   MysqlDatabase)rU   mysql_database_objectrW   mysql_tables_msg_listr!   database_keyr   s          r5   ParseMysqlDatabaser   
  s    $((<e  79 = $J>,'++L9-	

"
"#I#/$0 1 1			 
  
A Ar7   c                     UR                  S/ 5      n/ nU H  nUR                  [        XU5      5        M      U R                  US9nU$ )zNParses an object of type {mysql_databases: [...]} into the MysqlRdbms message.mysql_databases)mysqlDatabases)r{   r   r   rQ   )rU   mysql_rdbms_datarW   mysql_databases_rawmysql_database_msg_listr   mysql_rdbms_msgs          r5   (ParseMysqlSchemasListToMysqlRdbmsMessager     s`    
 ),,->C#f""8];= $ '', ( ./	r7   c                    U R                  UR                  [        SU5      S5      S9nUR                  S5      nUb  XCl        UR                  S5      nUb  XSl        UR                  S5      nUb  Xcl        UR                  S5      nUb  Xsl        UR                  S5      nUb  Xl        UR                  S	5      n	U	b  Xl        UR                  S
5      n
U
b  Xl	        UR                  S5      nUb  Xl
        U$ )zCParses a raw oracle column json/yaml into the OracleColumn message.r#   r   r   r   r   r   r   r   	precisionr   scale)OracleColumnr{   r   r   r   r   r   r   r   r   r   )rU   oracle_column_objectrW   r4   r   r   r   r   r   r   r   r   s               r5   ParseOracleColumnr   )  s   !!!%%
X}
5r; " <' #&&{3) !%%j1(##H-&N!%%j1()--.@A!."&&{3)!$((7+$

"
"7
+%
M	.r7   c                    / nUR                  S/ 5       H  nUR                  [        XU5      5        M      [        SU5      nUR                  U5      nU(       d  [        R
                  " SU-  5      eU R                  XcS9$ )zAParses a raw oracle table json/yaml into the OracleTable message.oracle_columnsr!   r   )r!   oracleColumns)r{   r   r   r   r   rt   OracleTable)rU   oracle_table_objectrW   oracle_columns_msg_listr#   r   r    s          r5   ParseOracleTabler   I  s    #''(8"=f""(M:< > !-8)"&&y1*	

"
"#I#,$- . .			 
 
? ?r7   c                    / nUR                  S/ 5       H  nUR                  [        XU5      5        M      [        SU5      nUR                  U5      nU(       d  [        R
                  " SU-  5      eU R                  XcS9$ )zCParses a raw oracle schema json/yaml into the OracleSchema message.oracle_tablesr   r   )r   oracleTables)r{   r   r   r   r   rt   OracleSchema)rU   oracle_schema_objectrW   oracle_tables_msg_listr!   
schema_keyr   s          r5   ParseOracleSchemar   X  s    #''<e!!-8: = "(M:*$((4+	

"
"#I#-$. / /			 
 
? ?r7   c                     UR                  S/ 5      n/ nU H  nUR                  [        XU5      5        M      U R                  US9nU$ )zNParses an object of type {oracle_schemas: [...]} into the OracleRdbms message.oracle_schemas)oracleSchemas)r{   r   r   rZ   )rU   oracle_rdbms_datarW   oracle_schemas_raworacle_schema_msg_listr   oracle_rdbms_msgs          r5   *ParseOracleSchemasListToOracleRdbmsMessager   g  sa    
 ),,-=rB"f!!(M:< # ))* * ,	r7   c                    U R                  UR                  SS5      S9nUR                  S5      nUb  X2l        UR                  S5      nUb  XBl        UR                  S5      nUb  XRl        UR                  S5      nUb  Xbl        UR                  S5      nUb  Xrl        UR                  S	5      nUb  Xl        UR                  S
5      n	U	b  Xl        U$ )zKParses a raw postgresql column json/yaml into the PostgresqlColumn message.r#   r   r   r   r   r   r   r   r   r   )	PostgresqlColumnr{   r   r   r   r   r   r   r   )
rU   postgresql_column_objectr4   r   r   r   r   r   r   r   s
             r5   ParsePostgresqlColumnr   w  s    %%%))(B7 & 9'&**;7) #''1&N&**;7)!
"
&
&w
/%
M(,,];+$%))*5(-112DE!.	.r7   c                     / nUR                  S/ 5       H  nUR                  [        X5      5        M     UR                  S5      nU(       d  [        R                  " S5      eU R                  XBS9$ )zIParses a raw postgresql table json/yaml into the PostgresqlTable message.postgresql_columnsr!   z'Cannot parse YAML: missing key "table".)r!   postgresqlColumns)r{   r   r   r   rt   PostgresqlTable)rU   postgresql_table_objectpostgresql_columns_msg_listr#   r    s        r5   ParsePostgresqlTabler     sw     "'++,@"Ef&&'<X'NO F&**73*	

"
"#L
MM		!	! 
" 
G Gr7   c                     / nUR                  S/ 5       H  nUR                  [        X5      5        M     UR                  S5      nU(       d  [        R                  " S5      eU R                  XBS9$ )zKParses a raw postgresql schema json/yaml into the PostgresqlSchema message.postgresql_tablesr   z(Cannot parse YAML: missing key "schema".)r   postgresqlTables)r{   r   r   r   rt   PostgresqlSchema)rU   postgresql_schema_objectpostgresql_tables_msg_listr!   r   s        r5   ParsePostgresqlSchemar     sw    !'++,?De%%&:8&KL E(,,X6+	

"
"#M
NN		"	" 
# 
G Gr7   c                     UR                  S/ 5      n/ nU H  nUR                  [        X5      5        M     U R                  US9nU$ )zVParses an object of type {postgresql_schemas: [...]} into the PostgresqlRdbms message.postgresql_schemas)postgresqlSchemas)r{   r   r   r_   )rU   postgresql_rdbms_datapostgresql_schemas_rawpostgresql_schema_msg_listr   postgresql_rdbms_msgs         r5   2ParsePostgresqlSchemasListToPostgresqlRdbmsMessager     s]     1445I2N!&f%%&;H&MN ' "112 2 4	r7   c                 @    U R                  UR                  SS5      S9$ )zCParses a raw mongodb field json/yaml into the MongodbField message.r}   r   )r}   )MongodbFieldr{   )rU   mongodb_field_objects     r5   ParseMongodbFieldr     s$    			%9%=%=gr%J		KKr7   c                     UR                  S/ 5      n/ nU H  nUR                  [        X5      5        M     U R                  UR                  SS5      US9$ )zKParses a raw mongodb database json/yaml into the MongodbCollection message.fields
collectionr   )r   r   )r{   r   r   MongodbCollection)rU   mongodb_collection_object
fields_rawfields_msg_listr}   s        r5   ParseMongodbCollectionr     sb    (,,Xr:*/e,X=> 		#	#*..|R@ 
$ 
 r7   c                     UR                  S/ 5      n/ nU H  nUR                  [        X5      5        M     U R                  US9$ )zIParses a raw mongodb database json/yaml into the MongodbDatabase message.collections)r   )r{   r   r   MongodbDatabase)rU   mongodb_database_objectcollections_rawcollections_msg_listr   s        r5   ParseMongodbDatabaser     sM    +//rB/#j 6x LM $		!	!.B	!	CCr7   c                     UR                  S/ 5      n/ nU H  nUR                  [        X5      5        M     U R                  US9$ )zGParses a raw mongodb cluster json/yaml into the MongodbCluster message.	databases)r   )r{   r   r   rk   )rU   mongodb_cluster_objectdatabases_rawdatabases_msg_listr   s        r5   ParseMongodbClusterr     sM    (,,["=-h28FG  		 	 +=	 	>>r7   c                     / nU  H]  nSn[          H  nXB;   d  M
  Un  O   U(       a*  UR                  UR                  U[         U   5      5        ML  UR                  U5        M_     U$ )aE  Updates field mask paths according to the v1alpha1 > v1 Datastream API change.

This allows for backwards compatibility with the current client field
mask.

Args:
  field_mask: List[str], list of stream fields to update

Returns:
  updated_field_mask: List[str] field mask with fields translated
    from v1alpha1 API to v1.
N)-_UPDATE_MASK_FIELD_TRANSLATION_V1ALPHA1_TO_V1r   replace)
field_maskupdated_field_maskpathfield_to_translater}   s        r5   UpdateV1alpha1ToV1MaskFieldsr    sv     d>	" ? 
,, ;<NOQ %  
r7   c                    [         R                  " USS9n [        R                  " U5      nUR                  SU5      n[        XU5      $ ! [         a*  n[
        R                  " SR                  U5      5      eSnAff = f)zBParses a mysql_rdbms_file into the MysqlRdbms message. deprecated.Fr&   Cannot parse YAML:[{0}]Nmysql_rdbms)
r   r/   r   r0   rs   r   rt   rE   r{   r   )rU   rV   rW   r3   mysql_rdbms_head_datarv   r   s          r5   rT   rT     s    
 
	'	'(8	G$H IIdO +..* 
2-
  
 H

"
"#<#C#CA#F
GGH   A 
A?%A::A?c                    [         R                  " USS9n [        R                  " U5      nUR                  SU5      n[        XU5      $ ! [         a*  n[
        R                  " SR                  U5      5      eSnAff = f)zDParses a oracle_rdbms_file into the OracleRdbms message. deprecated.Fr&   r  Noracle_rdbms)
r   r/   r   r0   rs   r   rt   rE   r{   r   )rU   r\   rW   r3   oracle_rdbms_head_datarv   r   s          r5   r[   r[     s     
	'	'(9%	H$H!YYt_ -00, 
4=
  
 H

"
"#<#C#CA#F
GGHr  rx   )E__doc__
__future__r   r   r   rL   apitools.base.pyr   rq   googlecloudsdk.api_lib.dataprocr   !googlecloudsdk.api_lib.datastreamr   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   !googlecloudsdk.command_lib.exportr   r+   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   rJ   r.   r-   CAMEL_CASE_CONVERSION_EVENTr   rR   rS   GArz   r6   r:   r>   rC   rH   rO   rX   r]   ra   re   ri   rm   r1   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rT   r[   rN   r7   r5   <module>r     s   & &  '  5 6 > I , ( A ) $ 2 
    /2JJ  ##&A+K1 - 	h
 	j
 	g
 	h
 	/
 	/+% !8& #7 L #7 ; #7 >% /3.?.?.D.D	L 04/@/@/E/E	N ,044<A" <@;L;L.2d @??" >B=N=N04 8	G	G
L
	D?@ /3.?.?.D.D( 04/@/@/E/Er7   