
    P              	          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	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\R6                  R8                  S\R6                  R:                  S0\R6                  R8                  S\R6                  R:                  S0\R6                  R8                  S\R6                  R:                  S0\R6                  R8                  S\R6                  R:                  S0\R6                  R8                  S\R6                  R:                  S0\R6                  R8                  S\R6                  R:                  S0S.rS  rS! r \S"4S# jr!\4S$ jr"\4S% jr#S& r$S' r%\R6                  R8                  4S( jr&\R6                  R8                  4S) jr'S* r(S+ r)S, r*S- r+S. r, SES/ jr-S0 r.S1 r/S2 r0S3 r1S4 r2\R6                  R8                  4S5 jr3S6 r4S7 r5S8 r6\R6                  R8                  4S9 jr7S: r8S; r9S< r:S= r;S> r<S? r=S@ r>SA r?SB r@\R6                  R8                  4SC jrA\R6                  R8                  4SD jrBg)FzCloud Datastream API utilities.    N)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                 Z    [         R                  " [        [        USS9n[	        UU US9nU$ )zDParses a config message from a parsed JSON and validates its schema.Ffor_helpmessage_typeparsed_yamlschema_path)export_utilGetSchemaPath_DEFAULT_API_NAME_DEFAULT_API_VERSION$CreateMessageWithCamelCaseConversion)parsed_jsonr   r%   r'   messages        -lib/googlecloudsdk/api_lib/datastream/util.pyParseJsonAndValidateSchemar0   I   s8    ))-{U+ 1' 
.    c                     [         R                  " [        [        USS9n[        R
                  " U SS9n[        R                  " U5      n[        UUUS9nU$ )z=Parses a config message from a file and validates its schema.Fr"   binaryr$   )	r(   r)   r*   r+   r   ReadFromFileOrStdinr
   loadr,   )config_file_pathr   r%   r'   datar&   r.   s          r/   ParseMessageAndValidateSchemar9   X   sX    ))-{U+
 
	'	'(8	G$		$+0' 
.r1   Fc                 ,    [         R                  " SXS9$ )Nr   )no_http)r   GetClientInstance)api_versionr;   s     r/   r<   r<   k   s    			k	KKr1   c                 0    [         R                  " SU 5      $ Nr   )r   GetMessagesModule)r=   s    r/   r@   r@   o   s    			k	::r1   c                 T    [         R                  " 5       nUR                  SU 5        U$ r?   )r	   RegistryRegisterApiByName)r=   resource_parsers     r/   GetResourceParserrE   s   s&    &&(/##L+>	r1   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     r/   	ParentRefrJ   y   s     
$	*	*7	==r1   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 r1   r/   GenerateRequestIdrQ      s     
tzz|	$$r1   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BETAr9   rS   ParseMysqlRdbmsFileBeta)messagesmysql_rdbms_filerelease_tracks      r/   ParseMysqlRdbmsFilerZ      sA     d'',,,(,(;(;  
!]	KKr1   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   rT   rU   r9   r\   ParseOracleRdbmsFileBeta)rW   oracle_rdbms_filerY   s      r/   ParseOracleRdbmsFiler_      sA     d'',,,(=(*>*>  
"(}	MMr1   c                 0    [        USU R                  5      $ )z@Parses a postgresql_rdbms_file into the PostgresqlRdbms message.PostgresqlRdbms)r9   ra   )rW   postgresql_rdbms_files     r/   ParsePostgresqlRdbmsFilerc          	&.0H0H
 r1   c                 0    [        USU R                  5      $ )z>Parses a sqlserver_rdbms_file into the SqlServerRdbms message.SqlServerRdbms)r9   rf   )rW   sqlserver_rdbms_files     r/   ParseSqlServerRdbmsFilerh      s    	&,h.E.E
 r1   c                 0    [        USU R                  5      $ )z<Parses a salesforce_org_file into the SalesforceOrg message.SalesforceOrg)r9   rj   )rW   salesforce_org_files     r/   ParseSalesforceOrgFilerl      s    	&?H,B,B
 r1   c                 0    [        USU R                  5      $ )z:Parses a spanner_rdbms_file into the SpannerRdbms message.SpannerDatabase)r9   rn   )rW   spanner_database_files     r/   ParseSpannerDatabaseFilerp      rd   r1   c                 0    [        USU R                  5      $ )z6Parses a mongodb_file into the MongodbCluster message.MongodbCluster)r9   rr   )rW   mongodb_files     r/   ParseMongodbFilert      s    	&$h&=&=
 r1   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   
ParseErrorrG   )r%   r&   r'   converted_yamlr.   es         r/   r,   r,      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fieldrY   s     r/   GetRDBMSV1alpha1ToV1FieldNamer      %    	*	.	.ub	9	=	=
 r1   c                 L    [         R                  U 0 5      R                  X5      $ r   r   r   s     r/   _GetRDBMSFieldNamer      r   r1   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)
rW   mysql_column_objectrY   r.   r   r   r   r   r   r   s
             r/   ParseMysqlColumnr      s       $$
X}
5r; ! <' "%%k2) !%%k2)!""8,&N $$Z0((,,-?@!.#''6+$	.r1   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_exceptionsr{   
MysqlTable)rW   mysql_table_objectrY   mysql_column_msg_listr    	table_keyr   s          r/   ParseMysqlTabler     s    "&&;f  =9; < !-8)!%%i0*	

"
"#I#,$- . .			 
 
< <r1   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   r{   MysqlDatabase)rW   mysql_database_objectrY   mysql_tables_msg_listr   database_keyr   s          r/   ParseMysqlDatabaser     s    $((<e  79 = $J>,'++L9-	

"
"#I#/$0 1 1			 
  
A Ar1   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   rS   )rW   mysql_rdbms_datarY   mysql_databases_rawmysql_database_msg_listr   mysql_rdbms_msgs          r/   (ParseMysqlSchemasListToMysqlRdbmsMessager   ,  s`    
 ),,->C#f""8];= $ '', ( ./	r1   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   )rW   oracle_column_objectrY   r.   r   r   r   r   r   r   r   r   s               r/   ParseOracleColumnr   <  s   !!!%%
X}
5r; " <' #&&{3) !%%j1(##H-&N!%%j1()--.@A!."&&{3)!$((7+$

"
"7
+%
M	.r1   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   r{   OracleTable)rW   oracle_table_objectrY   oracle_columns_msg_listr    r   r   s          r/   ParseOracleTabler   \  s    #''(8"=f""(M:< > !-8)"&&y1*	

"
"#I#,$- . .			 
 
? ?r1   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   r{   OracleSchema)rW   oracle_schema_objectrY   oracle_tables_msg_listr   
schema_keyr   s          r/   ParseOracleSchemar   k  s    #''<e!!-8: = "(M:*$((4+	

"
"#I#-$. / /			 
 
? ?r1   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   r\   )rW   oracle_rdbms_datarY   oracle_schemas_raworacle_schema_msg_listr   oracle_rdbms_msgs          r/   *ParseOracleSchemasListToOracleRdbmsMessager   z  sa    
 ),,-=rB"f!!(M:< # ))* * ,	r1   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   )
rW   postgresql_column_objectr.   r   r   r   r   r   r   r   s
             r/   ParsePostgresqlColumnr     s    %%%))(B7 & 9'&**;7) #''1&N&**;7)!
"
&
&w
/%
M(,,];+$%))*5(-112DE!.	.r1   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   r{   PostgresqlTable)rW   postgresql_table_objectpostgresql_columns_msg_listr    r   s        r/   ParsePostgresqlTabler     sw     "'++,@"Ef&&'<X'NO F&**73*	

"
"#L
MM		!	! 
" 
G Gr1   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   r{   PostgresqlSchema)rW   postgresql_schema_objectpostgresql_tables_msg_listr   r   s        r/   ParsePostgresqlSchemar     sw    !'++,?De%%&:8&KL E(,,X6+	

"
"#M
NN		"	" 
# 
G Gr1   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   ra   )rW   postgresql_rdbms_datapostgresql_schemas_rawpostgresql_schema_msg_listr   postgresql_rdbms_msgs         r/   2ParsePostgresqlSchemasListToPostgresqlRdbmsMessager     s]     1445I2N!&f%%&;H&MN ' "112 2 4	r1   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   )rW   mongodb_field_objects     r/   ParseMongodbFieldr     s$    			%9%=%=gr%J		KKr1   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)rW   mongodb_collection_object
fields_rawfields_msg_listr   s        r/   ParseMongodbCollectionr     sb    (,,Xr:*/e,X=> 		#	#*..|R@ 
$ 
 r1   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)rW   mongodb_database_objectcollections_rawcollections_msg_listr   s        r/   ParseMongodbDatabaser     sM    +//rB/#j 6x LM $		!	!.B	!	CCr1   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   rr   )rW   mongodb_cluster_objectdatabases_rawdatabases_msg_listr   s        r/   ParseMongodbClusterr    sM    (,,["=-h28FG  		 	 +=	 	>>r1   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        r/   UpdateV1alpha1ToV1MaskFieldsr
    sv     d>	" ? 
,, ;<NOQ %  
r1   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.Fr3   Cannot parse YAML:[{0}]Nmysql_rdbms)
r   r5   r
   r6   rz   r   r{   rG   r   r   )rW   rX   rY   r8   mysql_rdbms_head_datar}   r   s          r/   rV   rV     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.Fr3   r  Noracle_rdbms)
r   r5   r
   r6   rz   r   r{   rG   r   r   )rW   r^   rY   r8   oracle_rdbms_head_datar}   r   s          r/   r]   r]      s     
	'	'(9%	H$H!YYt_ -00, 
4=
  
 H

"
"#<#C#CA#F
GGHr  r   )C__doc__rN   apitools.base.pyr   rx   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   rL   r+   r*   CAMEL_CASE_CONVERSION_EVENTr  rT   rU   GAr   r0   r9   r<   r@   rE   rJ   rQ   rZ   r_   rc   rh   rl   rp   rt   r,   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  rV   r]   rP   r1   r/   <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r1   