
                         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Create a new version.    )absolute_import)division)unicode_literals)base)
exceptions)flags)logc                       e Zd ZdZ ej
                         j                  j                  j                  ZdZ	e
d        Zd Zd Zy)Createa  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                     t        j                  |        t        j                  |        t        j                  |        | j	                  ddd       y )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ArgszCreate.ArgsO   sK    	f%	'	%%f-
F	      c           	         t        j                         }t        j                  |      }|j                  r!|j
                  rt        j                  d      |j                  s|j
                  rV|j                  |j                         |j                  |j                  |j                  |j
                                    S |j                  |j                               S )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   _CreateCreateCKVRequestzCreate._CreateCreateCKVRequest]   s    ..0H--d3N!=!=(('( (  < <__,,.#44-5--!%!6!6'+'C'C . E 5 F ` G G ]]**, ^ . .r   c                 h   t        j                         }|j                  }|j                  | j	                  |            }|j
                  r|j                  j                  d      d   }t        j                  |      }t        j                         }|j                  |j                         |j                  |            }|j                  j                  |       |j                   | j"                  k(  r9t$        j&                  j)                  | j*                  j-                  |             |S )N/)cryptoKeyVersionId)name$updateCryptoKeyPrimaryVersionRequest)version)r   GetClientInstance8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsr   r-   primaryr2   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   Runz
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____doc__r   r   r'   AlgorithmValueValuesEnumr>   rA   staticmethodr   r-   rH    r   r   r   r      sW    #L &m%%'88QQmm 
4    .,r   r   N)rL   
__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   rO   r   r   <module>r[      s~     &  ' A ( G 0 # D%%++T->->-C-C%%((*kT k*kr   