
    9                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ d	 Z	 	 dde
fdZd Zd Zd Zd Zd Zy
)z*Cloud Spanner backup schedules API helper.    )absolute_import)division)unicode_literals)
list_pager)apis)CloudKmsKeyName)timesc                 R    t        j                  t        j                  |             S )N)r	   FormatDurationForJsonParseDuration)retention_durations    6lib/googlecloudsdk/api_lib/spanner/backup_schedules.pyParseAndFormatRetentionDurationr      s    		$	$U%8%89K%L	MM    Nkms_keyc                    |j                  | j                               }|j                  rt        |j                        |_        |s|r]|j                         }|r||_        |r;|j                  r|j                  |_        n|j                  r|j                  |_
        ||_        |j                  r1|j                  |j                  |j                              |_        |S )a  Create a backup schedule message.

  Args:
    backup_schedule_ref: resource argument for a cloud spanner backup schedule.
    args: an argparse namespace. All the arguments that were provided to command
      invocation.
    msgs: contains the definitions of messages for the spanner v1 API.
    encryption_type: encryption type for the backup encryption.
    kms_key: contains the encryption keys for the backup encryption.

  Returns:
    BackupSchedule message.
  name)text)cronSpec)BackupScheduleRelativeNamer   r   retentionDurationCreateBackupEncryptionConfigencryptionTypekms_key_name
kmsKeyNamekms_key_nameskmsKeyNamesencryptionConfigcronBackupScheduleSpecCrontabSpecspec)backup_schedule_refargsmsgsencryption_typer   backup_scheduleencryption_configs          r   CreateBackupScheduleMessager+      s    ( ''-@-M-M-O'P/	(G)O% 99;)8&			'.';';$  (/(=(=%'8O$	YY22!!tyy!1 3 O 
r   c                     t        j                  dd      }t        j                  dd      }|j                  | j	                               }|j
                  j                  |      S )zGet a backup schedule.spannerv1r   )r   GetClientInstanceGetMessagesModule:SpannerProjectsInstancesDatabasesBackupSchedulesGetRequestr   ,projects_instances_databases_backupSchedulesGetr%   clientr'   reqs       r   r3   r3   L   sa    !!)T2&				4	0$GG++- 	H 	# 
	<	<	@	@	EEr   c                     t        j                  dd      }t        j                  dd      }|j                  | j	                               }|j
                  j                  |      S )zDelete a backup schedule.r-   r.   r   )r   r/   r0   =SpannerProjectsInstancesDatabasesBackupSchedulesDeleteRequestr   r2   Deleter4   s       r   r9   r9   V   sa    !!)T2&				4	0$JJ++- 	K 	# 
	<	<	C	CC	HHr   c                    t        j                  dd      }t        j                  dd      }|j                  | j	                         j                               }t        | ||||      |_        |j                  d   dk(  r |j                         |j                  _
        n1|j                  d   dk(  r|j                         |j                  _        | j                         |_        |j                  j!                  |      S )zCreate a new backup schedule.r-   r.   parentr   zfull-backupzincremental-backup)r   r/   r0   =SpannerProjectsInstancesDatabasesBackupSchedulesCreateRequestParentr   r+   backupSchedulebackup_typeFullBackupSpecfullBackupSpecIncrementalBackupSpecincrementalBackupSpecNamebackupScheduleIdr2   Create)r%   r&   r(   r   r5   r'   r6   s          r   rG   rG   `   s     !!)T2&				4	0$JJ '')668 	K 	# 34# 
aM)(,(;(;(=C%22/3/I/I/KC,,113#		<	<	C	CC	HHr   c                     t        j                  dd      }t        j                  dd      }|j                  | j	                               }t        j                  |j                  |dd      S )z&List backup schedules in the database.r-   r.   r;   backupSchedulespageSize)fieldbatch_size_attribute)r   r/   r0   ;SpannerProjectsInstancesDatabasesBackupSchedulesListRequestr   r   YieldFromListr2   )database_refr5   r'   r6   s       r   ListrP   w   so    !!)T2&				4	0$HH&&( 	I 	# 
	!	!99	%	
 r   c                    t        j                  dd      }t        j                  dd      }|j                  | j	                               }t        | ||||      |_        g }|j                  r|j                  d       |j                  r|j                  d       |s|r|j                  d       dj                  |      |_        |j                  j                  |      S )zUpdate a backup schedule.r-   r.   r   zspec.cron_spec.textr   r*   ,)r   r/   r0   <SpannerProjectsInstancesDatabasesBackupSchedulesPatchRequestr   r+   r?   r!   appendr   join
updateMaskr2   Patch)r%   r&   r(   r   r5   r'   r6   update_mask_pathss           r   UpdaterY      s     !!)T2&				4	0$II++- 	J 	# 34# 	YY23	120188-.#.		<	<	B	B3	GGr   )NN)__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   0googlecloudsdk.command_lib.spanner.resource_argsr   googlecloudsdk.core.utilr	   r   r+   r3   r9   rG   rP   rY    r   r   <module>ra      sZ    1 &  ' ' , L *N #*
 *ZFII.Hr   