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

  Args:
    parser: argparse.Parser: Parser object for command line inputs.
  z,Name of the existing backup vault to update.FupdateN)
r   AddBackupVaultResourceArgAddNoAsyncFlagAddEnforcedRetentionAddDescriptionAddEffectiveTime#AddUnlockBackupMinEnforcedRetentionAddForceUpdateFlagAddForceUpdateAccessRestriction'AddBackupVaultAccessRestrictionEnumFlagr	   s    -lib/surface/backup_dr/backup_vaults/update.py_add_common_argsr      s     !!4 vVU+v ++F36"''///A    argsreturnc                 Z   g }| j                  d      r|j                  d       | j                  d      r|j                  d       | j                  d      s| j                  d      r|j                  d       | j                  d      r|j                  d       d	j                  |      S )
zCreates the update mask for the update command.

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

  Returns:
    A string containing the update mask.
  descriptionbackup_min_enforced_retention&backupMinimumEnforcedRetentionDuration$unlock_backup_min_enforced_retentioneffective_timeeffectiveTimeaccess_restrictionaccessRestriction,)IsSpecifiedappendjoin)r   updated_fieldss     r   _add_common_update_maskr)   2   s     .	m$-(	56BC	,()/*	*+-.	.	!!r   c                 v   t        j                  | j                        }| j                  }| j                  r!| j
                  rt        j                  d      | j                  rt        j                         }n t        j                  | j
                  d      }| j                  r| j                  }nd}||||fS )a  Parses the update backup vault arguments.

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

  Returns:
    A tuple containing the backup min enforced retention, description and
    effective time.

  Raises:
    calliope_exceptions.ConflictingArgumentsException: If both
      --unlock-backup-min-enforced-retention and --effective-time are specified.
  zXOnly one of --unlock-backup-min-enforced-retention or --effective-time can be specified.zeffective-timeN)command_utilConvertIntToStrr   r   r   r    calliope_exceptionsConflictingArgumentsExceptionResetEnforcedRetentionVerifyDateInFuturer"   )r   r   r   r    r"   s        r   _parse_update_bvr1   J   s     #/">">
((#   +	..43F3F

;
;	- 
 
..!88:N!44-N 
00 $	
 r   c                    t               }|j                  j                  j                         }|j                  }|j
                  }	 | j                  ||      }| j                  |      }|j                  |||j                  ||      }|rg|j!                  |j#                  |      dj%                  |j'                               d      }
t)        j*                  |j'                         d       |
S t)        j*                  |j'                         ddt        j,                  j%                  |j.                        	       |S # t        j                  $ r)}	t        j                  |	t        j                        d}	~	ww xY w)
aR  Constructs and sends request.

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

  Returns:
    ProcessHttpResponse of the request made.

  Raises:
    exceptions.HttpException: if the http request fails.
  )force_updateupdate_maskforce_update_access_restrictionNzGUpdating backup vault [{}]. (This operation could take up to 1 minute.)F)operation_refmessage
has_resultzbackup vault)kindT)r9   is_asyncdetails)r   CONCEPTSbackup_vaultParseno_asyncr5   ParseUpdateBvGetUpdateMaskUpdater3   apitools_exceptions	HttpErrorr   HttpExceptionr   HTTP_ERROR_FORMATWaitForOperationGetOperationRefformatRelativeNamer   UpdatedResourceASYNC_OPERATION_MESSAGEname)selfr   clientr=   r?   r5   	parsed_bvr4   	operationeresources              r   _runrT   w   s\   " &++113,]]($($H$H!>""40I$$T*K&&(G  I &&,,Y7%%+VL,E,E,G%H ' H 113.IO!**11)..A	 
+ 
	&	& >

"
"1d&<&<
==>s   AE F $E;;F c                       e Zd ZdZdddddZedej                  fd       Zd	ej                  d
e
fdZd	ej                  defdZd Zy)rB   $Update a Backup and DR backup vault.z%Updates a Backup and DR backup vault.z{description}zThis command uses the backupdr/v1 API. The full documentation for this API can be found at: https://cloud.google.com/backup-disaster-recoverya          To update a backup vault BACKUP_VAULT in location MY_LOCATION with one update
        field, run:

        $ {command} BACKUP_VAULT --location=MY_LOCATION --effective-time="2024-03-22"

        To update a backup vault BACKUP_VAULT in location MY_LOCATION with multiple
        update fields, run:

        $ {command} BACKUP_VAULT --location=MY_LOCATION             --backup-min-enforced-retention="400000s" --description="Updated backup vault"
        )BRIEFDESCRIPTIONzAPI REFERENCEEXAMPLESr	   c                     t        |        yzySpecifies additional command flags.

    Args:
      parser: argparse.Parser: Parser object for command line inputs.
    Nr   r   s    r   ArgszUpdate.Args        Vr   r   r   c                     t        |      S zReturns the update mask for the update command.

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

    Returns:
      A string containing the update mask.
    r)   rN   r   s     r   rA   zUpdate.GetUpdateMask   s     #4((r   rO   c                 L    t        |      \  }}}}|j                  ||||      S a8  Parses the update backup vault arguments.

    Args:
      args: argparse.Namespace, An object that contains the values for the
        arguments specified in the .Args() method.
      client: BackupVaultsClient, The client to use to parse the backup vault.

    Returns:
      A parsed backup vault object.
    )r   r   r    r"   r1   ParseUpdaterN   r   rO   r   r   r    r"   s          r   r@   zUpdate.ParseUpdateBv   C      	% &C%-	   r   c                     t        | |      S NrT   rb   s     r   Runz
Update.Run       dr   N)__name__
__module____qualname____doc__detailed_helpstaticmethodargparseArgumentParserr]   	NamespacestrrA   r   r@   rl    r   r   rB   rB      sy     - 7$?-, 8**  
) 2 2 
)s 
) 2 2 <N 2r   rB   c                   n    e Zd ZdZed        Zdej                  defdZ	dej                  de
fdZd Zy	)
UpdateAlpharV   c                     t        |        yr[   r\   r   s    r   r]   zUpdateAlpha.Args  r^   r   r   rO   c                 L    t        |      \  }}}}|j                  ||||      S rd   re   rg   s          r   r@   zUpdateAlpha.ParseUpdateBv  rh   r   r   c                     t        |      }|S r`   ra   )rN   r   masks      r   rA   zUpdateAlpha.GetUpdateMask%  s     #4(DKr   c                     t        | |      S rj   rk   rb   s     r   rl   zUpdateAlpha.Run2  rm   r   N)rn   ro   rp   rq   rs   r]   rt   rv   r   r@   rw   rA   rl   rx   r   r   rz   rz      sO    ,  2 2 <N 2 2 2 s r   rz   )!rq   rt   apitools.base.pyr   rC   googlecloudsdk.api_lib.backupdrr   -googlecloudsdk.api_lib.backupdr.backup_vaultsr   googlecloudsdk.api_lib.utilgooglecloudsdk.callioper   r-   #googlecloudsdk.command_lib.backupdrr   r+   googlecloudsdk.corer   ru   r   rv   rw   r)   r1   rT   ReleaseTracksReleaseTrackGADefaultUniverseOnlyUpdateCommandrB   ALPHArz   rx   r   r   <module>r      s    ,  > 0 L 2 ( E 5 D #BX44 B("("4"4 " "0*8-- *Z8


8v D%%(()HT H  *HV D%%++,3& 3 -3r   