
    '                         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
\R                  4S jrS rS rS rS rS rg)z1Common utility functions for sql export commands.    )export_util)
operations)validate)base)flags)log)
propertiesTFc                     [         R                  R                  U 5        [        R                  " U 5        SnU(       a  US-   n[        R
                  " X5        [        R                  " XU5        g)aR  Adds the base export flags to the parser.

Args:
  parser: The current argparse parser to add these flags to.
  gz_supported: Boolean, specifies whether gz compression is supported.
  database_required: Boolean, specifies whether the database flag is required.
  database_help_text: String, specifies the help text for the database flag.
zThe path to the file in Google Cloud Storage where the export will be stored. The URI is in the form gs://bucketName/fileName. If the file already exists, the operation fails.z< If the filename ends with .gz, the contents are compressed.N)r   
ASYNC_FLAGAddToParserr   AddInstanceArgumentAddUriArgumentAddDatabaseList)parsergz_supporteddatabase_requireddatabase_help_texturi_help_texts        1lib/googlecloudsdk/command_lib/sql/export_util.pyAddBaseExportFlagsr      s`     //f%F#&- ! &@ AMv-4EF    c                    UR                   nUR                  n[        R                  " U R                  5        UR
                  R                  U R                  S[        R                  R                  R                  R                  0SS9nUR                  UR                  UR                  UR                  US9S9nUR                  R                  U5      nUR
                  R!                  SUR"                  UR                  S9nU R$                  (       a=  UR&                  R)                  UR+                  UR                  UR,                  S95      $ UR.                  UR0                  R2                  R4                  :H  n	U	(       a  U R6                  OU R8                  n
[&        R:                  R=                  X8S	5        [>        R@                  RC                  S
RE                  XZS95        g)a`  Exports data from a Cloud SQL instance.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  client: SqlClient instance, with sql_client and sql_messages props, for use
    in generating messages and making API calls.
  export_context: ExportContext; format-specific export metadata.

Returns:
  A dict representing the export operation resource, if '--async' is used,
  or else None.

Raises:
  HttpException: An HTTP error response was received while executing API
      request.
  ToolException: An error other than HTTP error occurred while executing the
      command.
projectzsql.instances)params
collection)exportContext)instancer   instancesExportRequestzsql.operations)	operationr   )r   r   zExporting Cloud SQL instancez%Exported [{instance}] to [{bucket}].
)r   bucketN)#
sql_clientsql_messagesr   ValidateInstanceNamer   resource_parserParser	   VALUEScorer   	GetOrFailSqlInstancesExportRequestInstancesExportRequest	instancesExportCreatenameasync_r   GetSqlOperationsGetRequestr   fileTypeExportContextFileTypeValueValuesEnumTDE	cert_pathuriOperationsV1Beta4WaitForOperationr   statuswriteformat)argsclientexport_contextr!   r"   instance_refexport_requestresult_operationoperation_refis_tde_exportexport_dests              r   RunExportCommandrF   6   s   &   *$$,
.''--
mm**//77AAB  . ",
  99$$"")@@& A ( : ).  ))00@((// %%"" 0 $-
 
[[  $$,,!))]5L5L 	- 	NO O
 		#	#	;	;	?	?@ 
 #0TXX+//
0NP **;BB C 1 2 
r   c                 f   [         R                  " UR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9	nU R                  (       a  [        R                  R                  S5        [        XU5      $ )a  Exports data from a Cloud SQL instance to a MySQL dump file.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  client: SqlClient instance, with sql_client and sql_messages props, for use
    in generating messages and making API calls.

Returns:
  A dict object representing the operations resource describing the export
  operation if the export was successful.
)offloadparallelthreadsclean	if_existspServerless exports cost extra. See the pricing page for more information: https://cloud.google.com/sql/pricing.
)r   SqlExportContextr"   r7   databasetablerH   rI   rJ   rK   rL   r   r:   r;   rF   r=   r>   sql_export_contexts      r   RunSqlExportCommandrS   t   s     #33
hh
mm
jjll}}llJJ
 
\\JJ{ 
$(:	;;r   c                 f   [         R                  " UR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9	nU R                  (       a  [        R                  R                  S5        [        XU5      $ )a  Exports data from a Cloud SQL instance to a CSV file.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  client: SqlClient instance, with sql_client and sql_messages props, for use
    in generating messages and making API calls.

Returns:
  A dict object representing the operations resource describing the export
  operation if the export was successful.
)rH   quoteescapefields_terminated_bylines_terminated_byrM   )r   CsvExportContextr"   r7   rO   queryrH   rU   rV   rW   rX   r   r:   r;   rF   )r=   r>   csv_export_contexts      r   RunCsvExportCommandr\      s     #33
hh
mm
jjllJJ[[4422	4 
\\JJ{ 
$(:	;;r   c                 
   [         R                  " UR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  5	      n[        XU5      $ )a  Export data from a Cloud SQL instance to a SQL Server BAK file.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  client: SqlClient instance, with sql_client and sql_messages props, for use
    in generating messages and making API calls.

Returns:
  A dict object representing the operations resource describing the export
  operation if the export was successful.
)r   BakExportContextr"   r7   rO   stripe_countstripedbak_typedifferential_baseexport_log_start_timeexport_log_end_timerF   rQ   s      r   RunBakExportCommandre      sn     #33
hh
mm

ll
mm

  

 
$(:	;;r   c                     [         R                  " UR                  U R                  U R                  U R
                  U R                  5      n[        XU5      $ )a  Export TDE certificate from a Cloud SQL instance.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  client: SqlClient instance, with sql_client and sql_messages props, for use
    in generating messages and making API calls.

Returns:
  A dict object representing the operations resource describing the export
  operation if the export was successful.
)r   TdeExportContextr"   certificater6   pvk_pathpvk_passwordrF   )r=   r>   tde_export_contexts      r   RunTdeExportCommandrl      sN     #33

nn
mm
 
$(:	;;r   N)__doc__googlecloudsdk.api_lib.sqlr   r   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   r	   &DEFAULT_DATABASE_LIST_EXPORT_HELP_TEXTr   rF   rS   r\   re   rl    r   r   <module>rt      sR    8 3 1 / ( 0 # *
 CC	G6;|<<<:<4<r   