
    p                     8   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  \R                  " \R                  R                   \R                  R"                  \R                  R$                  5       " S	 S
\R&                  5      5       rg)zUpdate a key version.    )absolute_import)division)unicode_literals)base)
exceptions)flags)mapsc                   F    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	rg
)Update   a  Update a key version.

{command} can be used to update the key versions. Updates can be made to the
the key versions's state (enabling or disabling it), to its external key
URI (if the key version has protection level EXTERNAL), or to its ekm
connection key path (if the key version has protection level EXTERNAL_VPC).

## EXAMPLES

The following command enables the key version 8 of key `frodo`
within keyring `fellowship` and location `us-east1`:

  $ {command} 8 --location=us-east1 \
                --keyring=fellowship \
                --key=frodo \
                --state=enabled

The following command disables the key version 8 of key `frodo`
within keyring `fellowship` and location `us-east1`:

  $ {command} 8 --location=us-east1 \
                --keyring=fellowship \
                --key=frodo \
                --state=disabled

The following command updates the external key URI of version 8 of key `frodo`
within keyring `fellowship` and location `us-east1`:

  $ {command} 8 --location=us-east1 \
                --keyring=fellowship \
                --key=frodo \
                --external-key-uri=https://example.kms/v0/some/key/path

The following command updates the ekm connection key path of version 8 of key
`bilbo` within keyring `fellowship` and location `us-east1`:

  $ {command} 8 --location=us-east1 \
                --keyring=fellowship \
                --key=bilbo \
                --ekm-connection-key-path=v0/some/key/path
c                     [         R                  " U S5        [         R                  " U 5        [         R                  " U 5        [         R                  " U 5        g )Nzto describe)r   AddKeyVersionResourceArgumentAddExternalKeyUriFlagAddEkmConnectionKeyPathFlagAddStateFlag)parsers    'lib/surface/kms/keys/versions/update.pyArgsUpdate.ArgsI   s<    	''>	'	%%f-	v    c                    / nUR                   (       a  UR                  S5        UR                  (       a  UR                  S5        UR                  (       a  UR                  S5        U(       d  [        R
                  " S5      eU$ )Nz-externalProtectionLevelOptions.externalKeyUriz3externalProtectionLevelOptions.ekmConnectionKeyPathstatez`An error occurred: --external-key-uri or --ekm-connection-key-path or --state must be specified.)external_key_uriappendekm_connection_key_pathr   kms_exceptionsUpdateError)selfargsfields_to_updates      r   ProcessFlagsUpdate.ProcessFlagsP   su    MN##
?Azzg& &&+, , r   c                 H   [         R                  " U5      nUR                  UR                  5       UR	                  [
        R                  R                  UR                  5      UR                  UR                  UR                  S9S9S9nSR                  U5      Ul        U$ )N)externalKeyUriekmConnectionKeyPath)r   externalProtectionLevelOptions)namecryptoKeyVersion,)r   ParseCryptoKeyVersionNameHCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsPatchRequestRelativeNameCryptoKeyVersionr	   CRYPTO_KEY_VERSION_STATE_MAPPERGetEnumForChoicer   ExternalProtectionLevelOptionsr   r   join
updateMask)r   r   messagesr    version_refreqs         r   CreateRequestUpdate.CreateRequestc   s    11$7K

[
[%%'!2266GG

+3++#44%)%A%A , C	 3 D \ EC XX./CNJr   c                     UR                   UR                  R                  R                  :w  a  [        R
                  " S5      eg )Nz[External key URI updates are only available for key versions with EXTERNAL protection level)protectionLevelr-   ProtectionLevelValueValuesEnumEXTERNALr   r   r   key_versionr3   s      r   CheckKeyIsExternalUpdate.CheckKeyIsExternalu   sD    ##!!@@II	J&&+, ,	Jr   c                     UR                   UR                  R                  R                  :w  a  [        R
                  " S5      eg )NzeEkmConnection key path updates are only available for key versions with EXTERNAL_VPC protection level)r9   r-   r:   EXTERNAL_VPCr   r   r<   s      r   CheckKeyIsExternalVpcUpdate.CheckKeyIsExternalVpc|   sD    ##!!@@MM	N&&/0 0	Nr   c                    U R                  U5      n[        R                  " 5       n[        R                  " 5       n[        R
                  " U5      nUR                  R                  UR                  UR                  5       S95      nUR                  (       a  U R                  Xd5        UR                  (       a  U R                  Xd5        U R                  XU5      nUR                  R                  U5      $ )N)r'   )r!   cloudkms_baseGetClientInstanceGetMessagesModuler   r*   8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsGetFCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsGetRequestr,   r   r>   r   rB   r6   Patch)r   r   r    clientr3   r4   r=   
update_reqs           r   Run
Update.Run   s    ((.,,.F..0H11$7K QQUU	O	O))+ 
P 
-.K 
k4##
  7 ##D4DEJJJPP r    N)__name__
__module____qualname____firstlineno____doc__staticmethodr   r!   r6   r>   rB   rN   __static_attributes__rP   r   r   r   r      s5    (T  &$,0r   r   N)rU   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   rE   googlecloudsdk.calliopegooglecloudsdk.command_lib.kmsr   r   r   r	   ReleaseTracksReleaseTrackALPHABETAGAUpdateCommandr   rP   r   r   <module>rb      s|     &  ' A ( G 0 / D%%++T->->-C-C%%((*}T }*}r   