
                            d Z ddlmZ ddlmZ ddlmZ ddl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dlmZ dej*                  fdZdefdZej2                   ej4                  ej6                  j8                         G d dej:                                      Z ej4                  ej6                  j>                         G d de             Z y)zUpdates a Backup and DR Backup.    )absolute_import)division)unicode_literalsN)
exceptions)util)BackupsClient)base)flags)logparserc                     t         j                  j                  |        t         j                  j                  | d       t	        j
                  | d       t	        j                  |        y)zsSpecifies additional command flags.

  Args:
    parser: argparse.Parser: Parser object for command line inputs.
  TzName of the backup to update.N)r	   
ASYNC_FLAGAddToParser
SetDefaultr
   AddBackupResourceArgAddUpdateBackupFlagsr   s    'lib/surface/backup_dr/backups/update.py_add_common_argsr      sN     //f%//VT*% V$    returnc                     g }| j                  d      r|j                  d       | j                  d      r|j                  d       dj                  |      S )Nenforced_retention_end_timeenforcedRetentionEndTimeexpire_time
expireTime,)IsSpecifiedappendjoin)argsupdated_fieldss     r   _add_common_update_maskr#   .   sP    .	3445	m$,'	.	!!r   c                   X    e Zd ZdZddddZedej                  fd       Zd Z	d	 Z
d
 Zy)UpdateUpdate the specified Backup.zUpdates a specific backupz{description}a|          To update the enforced retention of a backup sample-backup in backup vault sample-vault, data source
        sample-ds, project sample-project and location us-central1, run:

          $ {command} sample-backup --backup-vault=sample-vault --data-source=sample-ds --project=sample-project --location=us-central1 --enforced-retention-end-time="2025-02-14T01:10:20Z"
        )BRIEFDESCRIPTIONEXAMPLESr   c                     t        |        y Nr   r   s    r   ArgszUpdate.ArgsG   
    Vr   c                     t        j                  |j                  d      }t        j                  |j                  d      }|j	                  ||      }|S Nzenforced-retention-end-timezexpire-timecommand_utilVerifyDateInFuturer   r   ParseUpdateselfr!   clientupdated_enforced_retentionr   parsed_backups         r   r4   zUpdate.ParseUpdateK   W    !-!@!@((*G" 11-K &&'A;OMr   c                     t        |      S r+   r#   r6   r!   s     r   GetUpdateMaskzUpdate.GetUpdateMaskX       "4((r   c                    t               }|j                  }|j                  j                  j	                         }	 | j                  ||      }| j                  |      }|j                  |||      }|rPt        j                  |j!                         ddt        j"                  j%                  |j&                               |S |j)                  |j+                  |      dj%                  |j!                               d      }	t        j                  |j!                         d	       |	S # t        j                  $ r)}t        j                  |t        j                        d}~ww xY w)
zConstructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
        arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    )update_maskNbackupT)kindis_asyncdetailszHUpdating backup [{}]. (This operation usually takes less than 1 minute.)F)operation_refmessage
has_result)rC   )r   async_CONCEPTSrB   Parser4   r>   r%   apitools_exceptions	HttpErrorr   HttpExceptionr   HTTP_ERROR_FORMATr   UpdatedResourceRelativeNameASYNC_OPERATION_MESSAGEformatnameWaitForOperationGetOperationRef)
r6   r!   r7   rD   rB   r9   rA   	operationeresponses
             r   Runz
Update.Run[   sF    _F{{H]]!!'')F@&&tV4m&&t,k--

!   i 	



..55innE	 &&,,Y7v2245 ' H ++-H=O- (( @$$Q(>(>??@s   7D, ,E(?$E##E(N)__name__
__module____qualname____doc__detailed_helpstaticmethodargparseArgumentParserr-   r4   r>   rZ    r   r   r%   r%   7   sK     % +$	- 8**  )-r   r%   c                   F    e Zd ZdZedej                  fd       Zd Zd Z	y)UpdateAlphar&   r   c                     t        |        y r+   r,   r   s    r   r-   zUpdateAlpha.Args   r.   r   c                     t        j                  |j                  d      }t        j                  |j                  d      }|j	                  ||      }|S r0   r1   r5   s         r   r4   zUpdateAlpha.ParseUpdate   r:   r   c                     t        |      S r+   r<   r=   s     r   r>   zUpdateAlpha.GetUpdateMask   r?   r   N)
r[   r\   r]   r^   r`   ra   rb   r-   r4   r>   rc   r   r   re   re      s.    $8**  )r   re   )!r^   
__future__r   r   r   ra   apitools.base.pyr   rL   googlecloudsdk.api_lib.backupdrr   'googlecloudsdk.api_lib.backupdr.backupsr   googlecloudsdk.api_lib.utilgooglecloudsdk.callioper	   #googlecloudsdk.command_lib.backupdrr
   r2   googlecloudsdk.corer   rb   r   strr#   DefaultUniverseOnlyReleaseTracksReleaseTrackGAUpdateCommandr%   ALPHAre   rc   r   r   <module>rx      s    & &  '  > 0 A 2 ( 5 D #%X44 %"S " D%%(()OT O * Od D%%++,)& ) -)r   