
    $                         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
 jrSS jrS rS rS rS rS rg)z1Common utility functions for sql import commands.    )import_util)
operations)validate)base)flags)log)
properties)
console_ioc                    [         R                  R                  U 5        [        R                  " U 5        SnU(       a  US-   n[        R
                  " XR                  US95        U(       a  [        R                  " U S5        gg)a  Adds the base flags for importing data.

Args:
  parser: An argparse parser that you can use to add arguments that go on the
    command line after this command. Positional arguments are allowed.
  filetype: String, description of the file type being imported.
  gz_supported: Boolean, if True then .gz compressed files are supported.
  user_supported: Boolean, if True then a Postgres user can be specified.
Path to the {filetype} file in Google Cloud Storage from which the import is made. The URI is in the form `gs://bucketName/fileName`.0 Compressed gzip files (.gz) are also supported.filetype*PostgreSQL user for this import operation.N)r   
ASYNC_FLAGAddToParserr   AddInstanceArgumentAddUriArgumentformatAddUserparserr   gz_supporteduser_supporteduri_help_texts        1lib/googlecloudsdk/command_lib/sql/import_util.pyAddBaseImportFlagsr      su     //f%F#$ 
 !:M v33X3FG	MM&FG     c                    [         R                  R                  U 5        [        R                  " U 5        SnU(       a  US-   n[        R
                  " XR                  US95        U(       a  [        R                  " U S5        gg)a  Adds the base flags for importing data for bak import.

Args:
  parser: An argparse parser that you can use to add arguments that go on the
    command line after this command. Positional arguments are allowed.
  filetype: String, description of the file type being imported.
  gz_supported: Boolean, if True then .gz compressed files are supported.
  user_supported: Boolean, if True then a Postgres user can be specified.
r   r   r   r   N)r   r   r   r   r   AddBakImportUriArgumentr   r   r   s        r   AddBakImportFlagsr!   9   su     //f%F#$ 
 !:M (<(<h(<(OP	MM&FG r   c                 B   UR                   nUR                  nUR                  UR                  R                  R
                  :H  nUR                  UR                  R                  R                  :H  nU(       a  U R                  OU R                  n[        R                  " U R                  5        U(       a   [        R                  " XpR                  5        UR                  R                  U R                  S[         R"                  R$                  R&                  R(                  0SS9nU(       a?  U R                  (       a.  [*        R,                  " SR/                  U R0                  S9SSS9  O-[*        R,                  " SR/                  XpR                  S	9SSS9  UR3                  UR                  UR&                  UR5                  US
9S9n	UR6                  R9                  U	5      n
UR                  R;                  SU
R<                  UR&                  S9nU R>                  (       a=  UR@                  RC                  URE                  UR&                  URF                  S95      $ SnU(       a  U R                  (       a  Sn[@        RH                  RK                  X;U5        U(       aH  U R                  (       a7  [L        RN                  RQ                  SR/                  U R0                  S95        g[L        RN                  RQ                  SR/                  XS95        g)a`  Imports data into 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.
  import_context: ImportContext; format-specific import metadata.

Returns:
  A dict representing the import 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
collectionz6Bring database [{database}] online with recovery-only.)databaseT)messagedefaultcancel_on_noz3Data from [{uri}] will be imported to [{instance}].)uriinstance)importContext)r+   r#   instancesImportRequestzsql.operations)	operationr#   )r#   r.   z&Importing data into Cloud SQL instancezBring database onlinez7Bring database [{database}] online with recovery-only.
z1Imported data from [{bucket}] into [{instance}].
)r+   bucketN))
sql_clientsql_messagesfileTypeImportContextFileTypeValueValuesEnumBAKTDE	cert_pathr*   r   ValidateInstanceNamer+   ValidateURIrecovery_onlyresource_parserParser	   VALUEScorer#   	GetOrFailr
   PromptContinuer   r&   SqlInstancesImportRequestInstancesImportRequest	instancesImportCreatenameasync_r   GetSqlOperationsGetRequestr.   OperationsV1Beta4WaitForOperationr   statuswrite)argsclientimport_contextr0   r1   is_bak_importis_tde_importimport_sourceinstance_refimport_requestresult_operationoperation_refr'   s                r   RunImportCommandrX   T   s   &   *$$,		#	#	;	;	?	?@ 
 		#	#	;	;	?	?@ 
 %2$..txx-
.(:(:;''--
mm**//77AAB  . , t))DKK L   ELL M 
   99$$"")@@& A  : .  ))00@((// %%"" 0 - 
[[  $$,,!))]5L5L 	- 	
  5't))%G// t))JJBII]] 	J 	
 
 JJ<CC! 	D 	
 
r   c                     [         R                  " UR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  S9n[        XU5      $ )at  Imports data from a SQL dump file into 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 representing the import operation resource, if '--async' is used,
  or else None.
)parallelthreadsclean	if_exists)r   SqlImportContextr1   r*   r&   userrZ   r[   r\   r]   rX   rN   rO   sql_import_contexts      r   RunSqlImportCommandrb      s_     #33
hh
mm
ii}}llJJ	 
$(:	;;r   c                     [         R                  " UR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  5
      n[        XU5      $ )ao  Imports data from a CSV file into 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 representing the import operation resource, if '--async' is used,
  or else None.
)r   CsvImportContextr1   r*   r&   tablecolumnsr_   quoteescapefields_terminated_bylines_terminated_byrX   )rN   rO   csv_import_contexts      r   RunCsvImportCommandrl      sq     #33
hh
mm
jj
ll
ii
jj
kk

 
$(:	;;r   c                 b   [         R                  " UR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      n[        XU5      $ )ao  Imports data from a BAK file into 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 representing the import operation resource, if '--async' is used,
  or else None.
)r   BakImportContextr1   r*   r&   r7   pvk_pathpvk_passwordkeep_encryptedstripedno_recoveryr:   bak_typestop_atstop_at_markrX   r`   s      r   RunBakImportCommandrw      s     #33
hh
mm
nn
mm


ll


mm
ll
 
$(:	;;r   c                     [         R                  " UR                  U R                  U R                  U R
                  U R                  5      n[        XU5      $ )a{  Imports data from a TDE certificate file into 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 representing the import operation resource, if '--async' is used,
  or else None.
)r   TdeImportContextr1   certificater7   ro   rp   rX   )rN   rO   tde_import_contexts      r   RunTdeImportCommandr|     sN     #33

nn
mm
 
$(:	;;r   N)TT)__doc__googlecloudsdk.api_lib.sqlr   r   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   r	   googlecloudsdk.core.consoler
   r   r!   rX   rb   rl   rw   r|    r   r   <module>r      sP    8 3 1 / ( 0 # * 2 9=H:H6hV<2<6<<<r   