
                         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Create a new version.    )absolute_import)division)unicode_literals)base)
exceptions)flags)logc                       \ rS rSrSr\R                  " 5       R                  R                  R                  r	Sr
\S 5       rS rS rSrg)	Create   aX  Create a new version.

Creates a new version within the given key.

## EXAMPLES

The following command creates a new version within the `frodo`
key, `fellowship` keyring, and `global` location and sets it as
the primary version:

  $ {command} --location=global \
      --keyring=fellowship \
      --key=frodo --primary

The following command creates a new version within the `legolas`
key, `fellowship` keyring, `us-central1` location,
`https://example.kms/v0/some/key/path` as the address for its external key,
and sets it as the key's primary version:

  $ {command} --location=us-central1 \
      --keyring=fellowship \
      --key=legolas \
      --external-key-uri=https://example.kms/v0/some/key/path \
      --primary

The following command creates a new version within the `bilbo`
key, `fellowship` keyring, `us-central1` location,
`v0/some/key/path` as the ekm connection key path for its external key,
and sets it as the key's primary version:

  $ {command} --location=us-central1 \
      --keyring=fellowship \
      --key=bilbo \
      --ekm-connection-key-path=v0/some/key/path \
      --primary
aF  Successfully created key version [{version}] and set it as the primary version. Future encryption requests will use [{version}] until the next key rotation. Data that was encrypted with an older key version can still be decrypted, and Cloud KMS will automatically choose the correct key for decryption based on the ciphertext.c                     [         R                  " U 5        [         R                  " U 5        [         R                  " U 5        U R	                  SSSS9  g )Nz	--primary
store_truezpIf specified, immediately makes the new version primary. This should only be used with the `encryption` purpose.)actionhelp)r   AddKeyResourceFlagsAddExternalKeyUriFlagAddEkmConnectionKeyPathFlagadd_argument)parsers    'lib/surface/kms/keys/versions/create.pyArgsCreate.ArgsO   sK    	f%	'	%%f-
F	      c           
         [         R                  " 5       n[        R                  " U5      nUR                  (       a'  UR
                  (       a  [        R                  " S5      eUR                  (       d  UR
                  (       aM  UR                  UR                  5       UR                  UR                  UR                  UR
                  S9S9S9$ UR                  UR                  5       S9$ )NzFCan not specify both --external-key-uri and --ekm-connection-key-path.)externalKeyUriekmConnectionKeyPath)externalProtectionLevelOptions)parentcryptoKeyVersion)r   )cloudkms_baseGetMessagesModuler   ParseCryptoKeyNameexternal_key_uriekm_connection_key_pathkms_exceptionsArgumentErrorICloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsCreateRequestRelativeNameCryptoKeyVersionExternalProtectionLevelOptions)selfargsmessagescrypto_key_refs       r   _CreateCreateCKVRequestCreate._CreateCreateCKVRequest]   s    ..0H--d3N!=!=(('( (  < <__,,.#44-5--!%!6!6'+'C'C . E 5 F ` G G ]]**, ^ . .r   c                 h   [         R                  " 5       nUR                  nUR                  U R	                  U5      5      nUR
                  (       a  UR                  R                  S5      S   n[        R                  " U5      n[         R                  " 5       nUR                  UR                  5       UR                  US9S9nUR                  R                  U5        UR                   U R"                  :X  a6  [$        R&                  R)                  U R*                  R-                  US95        U$ )N/)cryptoKeyVersionId)name$updateCryptoKeyPrimaryVersionRequest)version)r    GetClientInstance8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsr   r/   primaryr5   splitr   r"   r!   FCloudkmsProjectsLocationsKeyRingsCryptoKeysUpdatePrimaryVersionRequestr(   $UpdateCryptoKeyPrimaryVersionRequest&projects_locations_keyRings_cryptoKeysUpdatePrimaryVersion	algorithmGOOGLE_SYMMETRIC_ENCRYPTIONr	   errPrintSYMMETRIC_NEW_PRIMARY_MESSAGEformat)	r+   r,   clientckvnew_ckv
version_idr.   r-   reqs	            r   Run
Create.Runs   s   ,,.F

I
ICjj55d;<G||<<%%c*2.j//5n002h[[**,;;%/ < 1 \ 3c
 33HHM			d>>	>..55j5I	K Nr    N)__name__
__module____qualname____firstlineno____doc__r    r!   r)   AlgorithmValueValuesEnumrA   rD   staticmethodr   r/   rK   __static_attributes__rM   r   r   r   r      sU    #L %%'88QQmm 
4    .,r   r   N)rR   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   r    googlecloudsdk.calliopegooglecloudsdk.command_lib.kmsr   r%   r   googlecloudsdk.corer	   ReleaseTracksReleaseTrackALPHABETAGACreateCommandr   rM   r   r   <module>ra      s|     &  ' A ( G 0 # D%%++T->->-C-C%%((*kT k*kr   