
    "                     B    d Z d Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZd Zd Zy)	zBCommon command-agnostic utility functions for sql import commands.c                     |*| j                   j                  j                  j                  S | j                   j                  j                  j	                  |j                               S )N)ImportContextBakImportOptionsValueBakTypeValueValuesEnumFULLlookup_by_nameupper)sql_messagesbak_types     -lib/googlecloudsdk/api_lib/sql/import_util.pyParseBakTyper      sY    ""88OOTT 
	#	#	9	9	P	P	_	_nn
     Nc                    |r~d}|s|r'| j                   j                  j                  ||      }| j                  d||| j                   j                  j                  || j                   j                  |||            S | j                  d||| j                   j                  j                  || j                   j                  |            S )a(  Generates the ImportContext for the given args, for importing from SQL.

  Args:
    sql_messages: module, The messages module that should be used.
    uri: The URI of the bucket to import from; the output of the 'uri' arg.
    database: The database to import to; the output of the '--database' flag.
    user: The Postgres user to import as; the output of the '--user' flag.
    parallel: Whether to use parallel import or not; the output of the
      '--parallel' flag.
    threads: The number of threads to use; the output of the '--threads' flag.
      Only applicable for parallel import.
    clean: Clean (DROP) database objects before recreating them. Corresponds to
      the --clean flag on pg_restore. Only applies if --parallel is set.
      PostgreSQL only.
    if_exists: Include SQL statement (IF EXISTS) with each
      DROP statement produced by --clean; Corresponds to the --if-exists  flag
      on pg_restore. Only applies if --parallel is set. PostgreSQL only.

  Returns:
    ImportContext, for use in InstancesImportRequest.importContext.
  N)cleanifExistssql#importContext)parallelthreadspostgresImportOptions)kinduridatabasefileType
importUsersqlImportOptions)r   )r   SqlImportOptionsValuePostgresImportOptionsValueFileTypeValueValuesEnumSQL)	r	   r   r   userr   r   r   	if_existspostgres_import_optionss	            r   SqlImportContextr"      s    > "	

$
$
:
:%%  &   %% ++CCGG%33II"9 J 
 &   %% ++CCGG%33II J 
 & 	 	r   c
                     | j                  d| j                   j                  |xs g |||||	      ||| j                   j                  j                  |      S )a[  Generates the ImportContext for the given args, for importing from CSV.

  Args:
    sql_messages: module, The messages module that should be used.
    uri: The URI of the bucket to import from; the output of the 'uri' arg.
    database: The database to import into; the output of the '--database' flag.
    table: The table to import into; the output of the '--table' flag.
    columns: The CSV columns to import form; the output of the '--columns' flag.
    user: The Postgres user to import as; the output of the '--user' 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:
    ImportContext, for use in InstancesImportRequest.importContext.
  r   )columnstablequoteCharacterescapeCharacterfieldsTerminatedBylinesTerminatedBy)r   csvImportOptionsr   r   r   r   )r   CsvImportOptionsValuer   CSV)
r	   r   r   r%   r$   r   quoteescapefields_terminated_bylines_terminated_bys
             r   CsvImportContextr1   _   sn    > 
	#	##11GG-Ru 1/ H 1 ))AAEE 
$ 
 r   c                    d}|rZ|rX|rV| j                   j                  | j                   j                  j                  |||            }|r,||j                  _        n| j                   j                         }|r||_        ||_        |	|_        t        | |
      |_	        ||j                  d      |_        ||_        | j                  d||| j                   j                  j                  |      S )a  Generates the ImportContext for the given args, for importing from BAK.

  Args:
    sql_messages: module, The messages module that should be used.
    uri: The URI of the bucket to import from; the output of the `uri` arg.
    database: The database to import to; the output of the `--database` flag.
    cert_path: The certificate used for encrypted .bak; the output of the
      `--cert-path` flag.
    pvk_path: The private key used for encrypted .bak; the output of the
      `--pvk-path` flag.
    pvk_password: The private key password used for encrypted .bak; the output
      of the `--pvk-password` or `--prompt-for-pvk-password` flag.
    keep_encrypted: Whether or not to decrypt the imported encrypted BAK file.
    striped: Whether or not the import is striped.
    no_recovery: Whether the import executes with NORECOVERY keyword.
    recovery_only: Whether the import skip download and bring database online.
    bak_type: Type of the bak file.
    stop_at: Equivalent to SQL Server STOPAT keyword.
    stop_at_mark: Equivalent to SQL Server STOPATMARK keyword.

  Returns:
    ImportContext, for use in InstancesImportRequest.importContext.
  N)certPathpvkPathpvkPassword)encryptionOptionsz%Y-%m-%dT%H:%M:%S.%fZr   )r   r   r   r   bakImportOptions)r   r   EncryptionOptionsValuer6   keepEncryptedstriped
noRecoveryrecoveryOnlyr   bakTypestrftimestopAt
stopAtMarkr   BAK)r	   r   r   	cert_pathpvk_pathpvk_passwordkeep_encryptedr:   no_recoveryrecovery_onlyr
   stop_atstop_at_markbak_import_optionss                 r   BakImportContextrK      s   L 8%33II&44JJ		$ 
  

 J  ;I**8%33IIK!("-$1!+L(C ' 0 01H I".		#	#
))AAEE) 
$ 
+ +r   c                     | j                   j                  ||||      }| j                  d| j                   j                  j                  |      S )a  Generates the ImportContext for the given args, for importing from 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:
    ImportContext, for use in InstancesImportRequest.importContext.
  )namecertificatePathprivateKeyPathprivateKeyPasswordr   )r   r   tdeImportOptions)r   TdeImportOptionsValuer   TDE)r	   certificaterB   rC   rD   tde_import_optionss         r   TdeImportContextrV      sb    . $11GG%	 H ' 
	#	#))AAEE) 
$ 
+ +r   )NNFNFF)NNNNNN)__doc__r   r"   r1   rK   rV    r   r   <module>rY      sQ    I 	
@N " *.)-*ZC+L +r   