
    mY                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SrS r " S S5      rg)z)Cloud Datastream connection profiles API.    )absolute_import)division)unicode_literals)
exceptions)util)base)labels_util)	resources)yaml)
console_iov1c                 r    [         R                  R                  U R                  SS9nUR	                  5       $ )Nz%datastream.projects.locations.streams)
collection)r
   REGISTRYParseRelativeNamenameSelfLink)resourcestreams     0lib/googlecloudsdk/api_lib/datastream/streams.pyGetStreamURIr       s6    //mm8 0 :& 
	    c                       \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS rSS jrSS jrSrg)StreamsClient'   z&Client for streams service in the API.Nc                     U=(       d    [         R                  " 5       U l        U=(       d    [         R                  " 5       U l        U R                  R
                  U l        [         R                  " 5       U l        g N)	r   GetClientInstance_clientGetMessagesModule	_messagesprojects_locations_streams_serviceGetResourceParser_resource_parser)selfclientmessagess      r   __init__StreamsClient.__init__*   sN    5T335DL9!7!7!9DNLL;;DM 224Dr   c                    UR                   (       aC  U R                  R                  [        R                  " U R                  UR                   U5      S9$ UR
                  (       aC  U R                  R                  [        R                  " U R                  UR
                  U5      S9$ UR                  (       aB  U R                  R                  [        R                  " U R                  UR                  5      S9$ UR                  (       aB  U R                  R                  [        R                  " U R                  UR                  5      S9$ UR                  (       aB  U R                  R                  [        R                  " U R                  UR                  5      S9$ UR                  (       aB  U R                  R                  [        R                  " U R                  UR                  5      S9$ U R                  R                  5       $ )zEGets BackfillAllStrategy message based on Stream objects source type.)oracleExcludedObjects)mysqlExcludedObjects)postgresqlExcludedObjects)sqlServerExcludedObjects)salesforceExcludedObjects)mongodbExcludedObjects)oracle_excluded_objectsr!   BackfillAllStrategyr   ParseOracleRdbmsFilemysql_excluded_objectsParseMysqlRdbmsFilepostgresql_excluded_objectsParsePostgresqlRdbmsFilesqlserver_excluded_objectsParseSqlServerRdbmsFilesalesforce_excluded_objectsParseSalesforceOrgFilemongodb_excluded_objectsParseMongodbFile)r&   release_trackargss      r   _GetBackfillAllStrategy%StreamsClient._GetBackfillAllStrategy0   s   ##^^// $ 9 9nnd::M!K 0 L L 
	$	$^^//#77nnd99= J 0 K K 
	)	)^^//$($A$Annd>>%@ 0 A A 
	(	(^^//#'#?#?nnd==$ 0  
 
	)	)^^//$($?$?nnd>>% 0  
 
	&	&^^//!%!6!6nnd;;" 0  
 >>--//r   c                     U[         R                  R                  :X  a  U R                  X5      $ [        R
                  " USU R                  R                  5      $ )AParses a oracle_sorce_config into the OracleSourceConfig message.OracleSourceConfig)r   ReleaseTrackBETA_ParseOracleSourceConfigBetar   ParseMessageAndValidateSchemar!   rE   )r&   oracle_source_config_filer?   s      r   _ParseOracleSourceConfig&StreamsClient._ParseOracleSourceConfigR   sT    )).....
#  --!)) r   c                    [         R                  " USS9n [        R                  " U5      nUR                  S5      nU(       a  UOUnUR                  [        R                  " SU5      0 5      n[        R                  " U R                  X5      n	UR                  [        R                  " SU5      0 5      n
[        R                  " U R                  X5      nU R                  R                  U	US9nUR                  S	5      (       a  UR                  S	5      Ul        U$ ! [        R                   a*  n[
        R                  " SR                  U5      5      eSnAff = f)
rD   FbinaryCannot parse YAML:[{0}]Noracle_source_configinclude_objectsexclude_objectsincludeObjectsexcludeObjectsmax_concurrent_cdc_tasks)r   ReadFromFileOrStdinr   loadYAMLParseErrords_exceptions
ParseErrorformatgetr   GetRDBMSV1alpha1ToV1FieldName*ParseOracleSchemasListToOracleRdbmsMessager!   rE   maxConcurrentCdcTasks)r&   rJ   r?   dataoracle_source_config_head_dataeoracle_sorce_config_data_objectrQ   include_objects_rawinclude_objects_dataexclude_objects_rawexclude_objects_dataoracle_source_config_msgs                r   rH   *StreamsClient._ParseOracleSourceConfigBeta_   sl    ))!%1DJ'+yy$ 'E&H&H'#
 + 	(+  /22**+<mL
  JJ+< /22**+<mL
  JJ+<  $~~@@++  A  
  :;;7K7O7O
$8&4 $#C  J$$%>%E%Ea%HIIJ   D! !E5%EEc                     U[         R                  R                  :X  a  U R                  X5      $ [        R
                  " USU R                  R                  5      $ )z?Parses a mysql_sorce_config into the MysqlSourceConfig message.MysqlSourceConfig)r   rF   rG   _ParseMysqlSourceConfigBetar   rI   r!   rn   )r&   mysql_source_config_filer?   s      r   _ParseMysqlSourceConfig%StreamsClient._ParseMysqlSourceConfig   sT    ))...--
"  -- (( r   c                    [         R                  " USS9n [        R                  " U5      nUR                  S5      nU(       a  UOUnUR                  [        R                  " SU5      0 5      n[        R                  " U R                  X5      n	UR                  [        R                  " SU5      0 5      n
[        R                  " U R                  X5      nU R                  R                  U	US9nUR                  S	5      (       a  UR                  S	5      Ul        U$ ! [        R                   a*  n[
        R                  " SR                  U5      5      eSnAff = f)
zDParses an old mysql_sorce_config into the MysqlSourceConfig message.FrN   rP   Nmysql_source_configrR   rS   rT   rW   )r   rX   r   rY   rZ   r[   r\   r]   r^   r   r_   (ParseMysqlSchemasListToMysqlRdbmsMessager!   rn   ra   )r&   rp   r?   rb   mysql_sorce_config_head_datard   mysql_sorce_config_data_objectrt   rf   rg   rh   ri   mysql_sourec_config_msgs                r   ro   )StreamsClient._ParseMysqlSourceConfigBeta   sk    )) 0DJ%)YYt_" &B%E%E&"
 * 	')  .11**+<mL
  HH+< .11**+<mL
  HH+< #nn>>++ ? 
 9::6I6M6M
$7&3 #"C  J$$%>%E%Ea%HIIJrl   c                 Z    [         R                  " USU R                  R                  5      $ )zIParses a postgresql_sorce_config into the PostgresqlSourceConfig message.PostgresqlSourceConfig)r   rI   r!   r{   )r&   postgresql_source_config_files     r   _ParsePostgresqlSourceConfig*StreamsClient._ParsePostgresqlSourceConfig   *     --% -- r   c                 Z    [         R                  " USU R                  R                  5      $ )zGParses a sqlserver_sorce_config into the SqlServerSourceConfig message.SqlServerSourceConfig)r   rI   r!   r   )r&   sqlserver_source_config_files     r   _ParseSqlServerSourceConfig)StreamsClient._ParseSqlServerSourceConfig   s*     --$,, r   c                 Z    [         R                  " USU R                  R                  5      $ )zIParses a salesforce_sorce_config into the SalesforceSourceConfig message.SalesforceSourceConfig)r   rI   r!   r   )r&   salesforce_source_config_files     r   _ParseSalesforceSourceConfig*StreamsClient._ParseSalesforceSourceConfig   r   r   c                 Z    [         R                  " USU R                  R                  5      $ )zDParses a mongodb_source_config into the MongodbSourceConfig message.MongodbSourceConfig)r   rI   r!   r   )r&   mongodb_source_config_files     r   _ParseMongodbSourceConfig'StreamsClient._ParseMongodbSourceConfig   s*     --"** r   c                     U[         R                  R                  :X  a  U R                  U5      $ [        R
                  " USU R                  R                  5      $ )zDParses a GcsDestinationConfig into the GcsDestinationConfig message.GcsDestinationConfig)r   rF   rG   _ParseGcsDestinationConfigBetar   rI   r!   r   )r&   gcs_destination_config_filer?   s      r   _ParseGcsDestinationConfig(StreamsClient._ParseGcsDestinationConfig   sP    
 ))...001LMM--#++ r   c                    [         R                  " USS9n [        R                  " U5      nUR                  S5      nU(       a  UOUnUR                  SS5      nUR                  S0 5      nUR                  S	0 5      n	U R                  R                  XxU	S
9n
SU;   a!  U R                  R                  5       U
l        U
$ SU;   aP  UR                  S5      nU R                  R                  UR                  S5      UR                  S5      S9U
l        U
$ [
        R                  " S5      e! [        R                   a*  n[
        R                  " SR                  U5      5      eSnAff = f)zFParses a gcs_destination_config into the GcsDestinationConfig message.FrN   rP   Ngcs_destination_configpath file_rotation_mbfile_rotation_interval)r   fileRotationMbfileRotationIntervalavro_file_formatjson_file_formatcompressionschema_file_format)r   schemaFileFormatz'Cannot parse YAML: missing file format.)r   rX   r   rY   rZ   r[   r\   r]   r^   r!   r   AvroFileFormatavroFileFormatJsonFileFormatjsonFileFormat)r&   r   rb    gcs_destination_head_config_datard   "gcs_destination_config_data_objectgcs_destination_config_datar   r   r   gcs_dest_config_msgjson_file_format_datas               r   r   ,StreamsClient._ParseGcsDestinationConfigBeta   s   ))#E3DJ)-4& *J)M)M *&
 . 	+-   '**626D2667I2N8<< "&..==3 > 5 88+/>>+H+H+J(  
:	:9==
+/>>+H+H+//>0445IJ ,I ,L(  $$
35 59  J$$%>%E%Ea%HIIJs   D, ,E* %E%%E*c                 Z    [         R                  " USU R                  R                  5      $ )zNParses a BigQueryDestinationConfig into the BigQueryDestinationConfig message.BigQueryDestinationConfig)r   rI   r!   r   )r&   config_files     r   _ParseBigqueryDestinationConfig-StreamsClient._ParseBigqueryDestinationConfig  s(    --#00 r   c                    [         R                  " X0R                  R                  R                  5      nU R                  R                  XUR
                  S9nU[        R                  R                  :X  a%  UR                  R                  R                  5       nO$UR                  R                  R                  5       nU R                  R                  5       nUR                  5       Ul        UR                   (       a"  U R#                  UR                   U5      Ul        OUR&                  (       a"  U R)                  UR&                  U5      Ul        OUR,                  (       a!  U R/                  UR,                  5      Ul        OUR2                  (       a!  U R5                  UR2                  5      Ul        OcUR8                  (       a!  U R;                  UR8                  5      Ul        O1UR>                  (       a   U RA                  UR>                  5      Ul!        Xul"        U[        R                  R                  :X  a%  UR                  RF                  R                  5       nO$UR                  RH                  R                  5       nU R                  RK                  5       n	UR                  5       U	l&        URN                  (       a"  U RQ                  URN                  U5      U	l)        O1URT                  (       a   U RW                  URT                  5      U	l,        Xl-        UR\                  (       a!  U R                  R_                  5       Ul0        U$ URb                  (       a  U Re                  X#5      n
Xl3        U$ )zReturns a stream object.)r   labelsdisplayName)4r	   ParseCreateArgsr!   StreamLabelsValuedisplay_namer   rF   rG   CONCEPTSsource_nameParsesourceSourceConfigRelativeNamesourceConnectionProfilerQ   rK   oracleSourceConfigrt   rq   mysqlSourceConfigpostgresql_source_configr}   postgresqlSourceConfigsqlserver_source_configr   sqlServerSourceConfigsalesforce_source_configr   salesforceSourceConfigmongodb_source_configr   mongodbSourceConfigsourceConfigdestination_namedestinationDestinationConfigdestinationConnectionProfiler   r   gcsDestinationConfigbigquery_destination_configr   bigqueryDestinationConfigdestinationConfigbackfill_noneBackfillNoneStrategybackfillNonebackfill_allrA   backfillAll)r&   	stream_idr?   r@   r   
stream_objsource_connection_profile_refstream_source_config"destination_connection_profile_refstream_destination_configbackfill_all_strategys              r   
_GetStreamStreamsClient._GetStream"  s   ((nn##//1F&&43D3D ' FJ ))...&*mm&?&?&E&E&G#&*mm&:&:&@&@&B#>>668%224 0  040M0M

#
#]14-		!	!/3/K/K

"
"M03,		&	&

+
+D,I,I
J 1 
	%	%

*
*4+G+G
H 0 
	&	&

+
+D,I,I
J 1 
	#	#151O1O

$
$2. 3 ))...+/==+I+I+O+O ,( ,0==+D+D+J+J+L( $ @ @ B*779 :""

)
)))=  4
 
	)	)

.
...0  9 $=  $ C C Ej
 	 
		"::=O4r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )N)r   )r!   ,DatastreamProjectsLocationsStreamsGetRequestr#   Get)r&   r   get_reqs      r   _GetExistingStream StreamsClient._GetExistingStreamh  s6    nnII J 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 stream.)	additionssubtractionsclearN)r	   GetUpdateLabelsDictFromArgsGetRemoveLabelsListFromArgsr!   r   r   Diffclear_labelsApplyr   needs_update)r&   r   r@   
add_labelsremove_labels
value_typeupdate_results          r   _UpdateLabelsStreamsClient._UpdateLabelsn  s    88>J;;DAM&&22J$$" eJ&	 
 !!#**fm "r   c                     U Vs/ s H  nUR                  U5      (       d  M  X4-   PM!     nnU Vs/ s H  ofR                  U5      (       a  M  UPM     nnUR                  U5        U$ s  snf s  snf )z?Returns an updated list of field masks with necessary prefixes.)
startswithextend)r&   update_fieldsprefix_to_checkprefix_to_addfieldtemp_fieldsxs          r    _UpdateListWithFieldNamePrefixes.StreamsClient._UpdateListWithFieldNamePrefixes{  s~    
 #"EO, 	"   ! ao)F=   %
s   A)A)A.A.c                    / nUR                   =(       d    SnUR                  S5      nU[        R                  R                  :X  a  [
        R                  " U5      nUR                  U5        UR                  S5      (       a  UR                  Ul
        U[        R                  R                  :X  a'  UR                  R                  R                  5       nSnO&UR                  R                  R                  5       nSnUR                  U5      (       aF  UR                  5       UR                   l        X;   a"  UR%                  U5        UR'                  S5        UR                  S5      (       a@  U R)                  UR*                  U5      UR                   l        U R/                  USS5      nGOPUR                  S	5      (       a?  U R1                  UR2                  U5      UR                   l        U R/                  US	S5      nOUR                  S
5      (       a>  U R7                  UR8                  5      UR                   l        U R/                  US
S5      nOUR                  S5      (       a>  U R=                  UR>                  5      UR                   l         U R/                  USS5      nOSUR                  S5      (       a=  U RC                  URD                  5      UR                   l#        U R/                  USS5      nU[        R                  R                  :X  a'  UR                  RH                  R                  5       n	Sn
O&UR                  RJ                  R                  5       n	Sn
UR                  U
5      (       aF  U	R                  5       URL                  l'        X;   a"  UR%                  U
5        UR'                  S5        UR                  S5      (       a?  U RQ                  URR                  U5      URL                  l*        U R/                  USS5      nOSUR                  S5      (       a=  U RW                  URX                  5      URL                  l-        U R/                  USS5      nUR                  S5      (       a2  U R\                  R_                  5       Ul0         URc                  S5        O?UR                  S5      (       a)  U Rg                  X#5      nXl4         URc                  S5        UR                  S5      (       aB  U R\                  Rj                  Rm                  URn                  Rq                  5       5      Ul7        U Rs                  X5        X4$ ! [d         a     Nxf = f! [d         a     Nf = f)zReturns updated stream.r   ,r   r   r   z'source_config.source_connection_profilerQ   zsource_config.rt   r   r   r   r   r   z1destination_config.destination_connection_profiler   zdestination_config.r   r   r   r   r   state):update_masksplitr   rF   rG   r   UpdateV1alpha1ToV1MaskFieldsr   IsSpecifiedr   r   r   r   r   r   r   r   r   removeappendrK   rQ   r   r   rq   rt   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r   resetAttributeErrorrA   r   r   StateValueValuesEnumr  upperr   )r&   r   r?   r@   r   user_update_maskuser_update_mask_listr   source_field_namer   destination_field_namer   s               r   _GetUpdatedStreamStreamsClient._GetUpdatedStream  s	    M''-2,2237))..."??
! ./'',,f ))...&*mm&?&?&E&E&G#'&*mm&:&:&@&@&B#")**
'
4
4
6 1		+./FG.///3/L/L

#
#]04f, ;;
/1ACm 
		/	0	0.2.J.J

"
"M/3f+;;
.0@Bm 
		4	5	5

+
+D,I,I
J 0 ;;
35EGm 
		3	4	4

*
*4+G+G
H / ;;
24Dm 
		4	5	5

+
+D,I,I
J 0 ;;
35Em
 ))...
--
(
(
.
.
0 )1,0MM,E,E,K,K,M(,.//
,
9
9
; ;		034?	A 011

)
)))= 3
 ;;
13HJm			7	8	8

.
...0 8 ;;
68MOm (( NN??Af]# 
		.	)	)"::=O0^$   ^^**??::


 fl 	v$  +   	   	s$   'U$ 'U4 $
U10U14
V Vc           	         U R                  X#U5      nUR                  nUR                  n[        R                  " 5       nU R
                  R                  n	U	" UUR                  UUUUS9n
U R                  R                  U
5      $ )a  Creates a stream.

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

Returns:
  Operation: the operation for creating the stream.
)r   streamIdparent	requestIdvalidateOnlyforce)
r   validate_onlyr  r   GenerateRequestIdr!   /DatastreamProjectsLocationsStreamsCreateRequestr   r#   Create)r&   
parent_refr   r?   r@   r   r  r  
request_idcreate_req_type
create_reqs              r   r  StreamsClient.Create  s|     __Yt<F&&MJJE'')JnnTTO "J ==
++r   c                 ~   UR                   nUR                  nU R                  U5      nU R                  XbU5      u  px[        R
                  " 5       n	U R                  R                  n
U
" UUR                  U	UUS9nUR                  (       a  SR                  U5      Ul        U R                  R                  U5      $ )aC  Updates a stream.

Args:
  name: str, the reference of the stream to
      update.
  release_track: Some arguments are added based on the command release
    track.
  args: argparse.Namespace, The arguments that this command was
      invoked with.

Returns:
  Operation: the operation for updating the connection profile.
)r   r   r  r  r  r  )r  r  r   r  r   r  r!   .DatastreamProjectsLocationsStreamsPatchRequestr   r  join
updateMaskr#   Patch)r&   r   r?   r@   r  r  current_streamupdated_streamr   r  update_req_type
update_reqs               r   UpdateStreamsClient.Update$  s     &&MJJE,,T2N$($:$:t%-!N '')JnnSSO   "J !hh}5j==z**r   )r   r!   r%   r#   )NNr   )__name__
__module____qualname____firstlineno____doc__r)   rA   rK   rH   rq   ro   r}   r   r   r   r   r   r   r   r   r   r   r  r  r,  __static_attributes__ r   r   r   r   '   sq    .5 0D)$V)#V$LDL&+z!x,>"+r   r   N)r2  
__future__r   r   r   !googlecloudsdk.api_lib.datastreamr   r[   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.util.argsr	   googlecloudsdk.corer
   r   googlecloudsdk.core.consoler   _DEFAULT_API_VERSIONr   r   r4  r   r   <module>r<     s?    0 &  ' I 2 ( < ) $ 2 _+ _+r   