
    p                     8   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dl	mZ  ej                  ej                  j                   ej                  j"                  ej                  j$                         G d	 d
ej&                               Zy)zUpdate a key version.    )absolute_import)division)unicode_literals)base)
exceptions)flags)mapsc                   >    e Zd ZdZed        Zd Zd Zd Zd Z	d Z
y)	Updatea  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                     t        j                  | d       t        j                  |        t        j                  |        t        j                  |        y )Nzto describe)r   AddKeyVersionResourceArgumentAddExternalKeyUriFlagAddEkmConnectionKeyPathFlagAddStateFlag)parsers    'lib/surface/kms/keys/versions/update.pyArgszUpdate.ArgsI   s<    	''>	'	%%f-	v    c                     g }|j                   r|j                  d       |j                  r|j                  d       |j                  r|j                  d       |st	        j
                  d      |S )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   ProcessFlagszUpdate.ProcessFlagsP   su    MN##
?Azzg& &&+, , r   c           
      X   t        j                  |      }|j                  |j                         |j	                  t
        j                  j                  |j                        |j                  |j                  |j                                    }dj                  |      |_        |S )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   CreateRequestz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                     |j                   |j                  j                  j                  k7  rt	        j
                  d      y )Nz[External key URI updates are only available for key versions with EXTERNAL protection level)protectionLevelr*   ProtectionLevelValueValuesEnumEXTERNALr   r   r   key_versionr0   s      r   CheckKeyIsExternalzUpdate.CheckKeyIsExternalu   sD    ##!!@@II	J&&+, ,	Jr   c                     |j                   |j                  j                  j                  k7  rt	        j
                  d      y )NzeEkmConnection key path updates are only available for key versions with EXTERNAL_VPC protection level)r5   r*   r6   EXTERNAL_VPCr   r   r8   s      r   CheckKeyIsExternalVpczUpdate.CheckKeyIsExternalVpc|   sD    ##!!@@MM	N&&/0 0	Nr   c                    | j                  |      }t        j                         }t        j                         }t	        j
                  |      }|j                  j                  |j                  |j                                     }|j                  r| j                  ||       |j                  r| j                  ||       | j                  |||      }|j                  j                  |      S )N)r$   )r   cloudkms_baseGetClientInstanceGetMessagesModuler   r'   8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsGetFCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsGetRequestr)   r   r:   r   r=   r3   Patch)r   r   r   clientr0   r1   r9   
update_reqs           r   Runz
Update.Run   s    ((.,,.F..0H11$7K QQUU	O	O))+ 
P 
-.K 
k84##
  h7 ##D(4DEJJJPP r   N)__name__
__module____qualname____doc__staticmethodr   r   r3   r:   r=   rH    r   r   r   r      s5    (T  &$,0r   r   N)rL   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   r?   googlecloudsdk.calliopegooglecloudsdk.command_lib.kmsr   r   r   r	   ReleaseTracksReleaseTrackALPHABETAGAUpdateCommandr   rN   r   r   <module>rY      s~     &  ' A ( G 0 / D%%++T->->-C-C%%((*}T }*}r   