
    8                      F    d Z d Z	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZd Zd Zy)	zBCommon command-agnostic utility functions for sql export commands.c                     |*| j                   j                  j                  j                  S | j                   j                  j                  j	                  |j                               S )N)ExportContextBakExportOptionsValueBakTypeValueValuesEnumFULLlookup_by_nameupper)sql_messagesbak_types     -lib/googlecloudsdk/api_lib/sql/export_util.pyParseBakTyper      sY    ""88OOTT 
	#	#	9	9	P	P	_	_nn
     Nc	                    |rY| j                  d||xs g || j                   j                  j                  | j                   j                  |xs g ||            S | j                   j                  j	                  ||      }	| j                  d||xs g || j                   j                  j                  | j                   j                  |xs g ||	            S )a7  Generates the ExportContext for the given args, for exporting to SQL.

  Args:
    sql_messages: module, The messages module that should be used.
    uri: The URI of the bucket to export to; the output of the 'uri' arg.
    database: The list of databases to export from; the output of the
      '--database' flag.
    table: The list of tables to export from; the output of the '--table' flag.
    offload: bool, The export offload flag.
    parallel: Whether to use parallel export or not.
    threads: The number of threads to use. Only applicable for parallel export.
    clean: Whether to include SQL statement (DROP <object>) required to drop
    database objects prior to import; corresponds to the clean flag on pg_dump.
    Only applies to PostgreSQL non-parallel exports.
    if_exists: Whether to include SQL statement (IF EXISTS) to each drop
    statement produced by the clean flag; corresponds to the if-exists flag on
    pg_dump. Only applies to PostgreSQL non-parallel exports.


  Returns:
    ExportContext, for use in InstancesExportRequest.exportContext.
  sql#exportContext)tablesparallelthreads)kinduri	databasesoffloadfileTypesqlExportOptions)cleanifExists)r   r   postgresExportOptions)r   FileTypeValueValuesEnumSQLSqlExportOptionsValuePostgresExportOptionsValue)
r	   r   databasetabler   r   r   r   	if_existspostgres_export_optionss
             r   SqlExportContextr$      s    B %% .b++CCGG%33II;B7 J 
 & 	 	 	++,F,F) -G -
  %% .b++CCGG%33II;B"9 J 
 &  r   c	                     | j                  d||xs g || j                   j                  j                  | j                   j                  |||||            S )a  Generates the ExportContext for the given args, for exporting to CSV.

  Args:
    sql_messages: module, The messages module that should be used.
    uri: The URI of the bucket to export to; the output of the 'uri' arg.
    database: The list of databases to export from; the output of the
      '--database' flag.
    query: The query string to use to generate the table; the output of the
      '--query' flag.
    offload: bool, The export offload flag.
    quote: character in Hex. The quote character for CSV format; the output of
      the '--quote' flag.
    escape: character in Hex. The escape character for CSV format; the output of
      the '--escape' flag.
    fields_terminated_by: character in Hex. The fields delimiter character for
      CSV format; the output of the '--fields-terminated-by' flag.
    lines_terminated_by: character in Hex. The lines delimiter character for CSV
      format; the output of the '--lines-terminated-by' flag.

  Returns:
    ExportContext, for use in InstancesExportRequest.exportContext.
  r   )selectQueryquoteCharacterescapeCharacterfieldsTerminatedBylinesTerminatedBy)r   r   r   r   r   csvExportOptions)r   r   CSVCsvExportOptionsValue)	r	   r   r    queryr   quoteescapefields_terminated_bylines_terminated_bys	            r   CsvExportContextr3   ]   sj    > 
	#	#
B))AAEE#11GG 1/ H 1 
$ 
2 2r   c	                 R   | j                   j                         }	|||	_        |||	_        ||	_        t        | |      |	_        ||j                  d      |	_        ||j                  d      |	_	        | j                  d||| j                   j                  j                  |	      S )aa  Generates the ExportContext for the given args, for exporting to BAK.

  Args:
    sql_messages: module, The messages module that should be used.
    uri: The URI of the bucket to export to; the output of the 'uri' arg.
    database: The list of databases to export from; the output of the
      '--database' flag.
    stripe_count: How many stripes to perform the export with.
    striped: Whether the export should be striped.
    bak_type: Type of bak file that will be exported. SQL Server only.
    differential_base: Whether the bak file export can be used as differential
      base for future differential backup. SQL Server only.
    export_log_start_time: start time of the log export. SQL Server only.
    export_log_end_time: end time of the log export. SQL Server only.

  Returns:
    ExportContext, for use in InstancesExportRequest.exportContext.
  z%Y-%m-%dT%H:%M:%S.%fZr   )r   r   r   r   bakExportOptions)r   r   stripedstripeCountdifferentialBaser   bakTypestrftimeexportLogStartTimeexportLogEndTimer   BAK)
r	   r   r    stripe_countr6   r
   differential_baseexport_log_start_timeexport_log_end_timebak_export_optionss
             r   BakExportContextrC      s    : $11GGI!(%1"(9%+L(C&,A,J,J-) $*=*F*F+' 
	#	#
))AAEE) 
$ 
+ +r   c                     | j                   j                  ||||      }| j                  d| j                   j                  j                  |      S )a  Generates the ExportContext for the given args, for exporting to TDE.

  Args:
    sql_messages: module, The messages module that should be used.
    certificate: The certificate name; the output of the
      `--certificate` flag.
    cert_path: The certificate path in Google Cloud Storage; the output of the
      `--cert-path` flag.
    pvk_path: The private key path in Google Cloud Storage; the output of the
      `--pvk-path` flag.
    pvk_password: The password that encrypts the private key; the output
      of the `--pvk-password` or `--prompt-for-pvk-password` flag.

  Returns:
    ExportContext, for use in InstancesImportRequest.exportContext.
  )namecertificatePathprivateKeyPathprivateKeyPasswordr   )r   r   tdeExportOptions)r   TdeExportOptionsValuer   TDE)r	   certificate	cert_pathpvk_pathpvk_passwordtde_export_optionss         r   TdeExportContextrQ      sb    . $11GG%	 H ' 
	#	#))AAEE) 
$ 
+ +r   )NNFFNFF)NNFNNNN)__doc__r   r$   r3   rC   rQ    r   r   <module>rT      sU    I 

>F #" *.)-*2Z5+p +r   