
                             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 dd	lmZ ej                    G d
 dej"                               Zy)zCreate a key handle.    )absolute_import)division)unicode_literals)base)waiter)flags)log)	resourcesc                   &    e Zd ZdZed        Zd Zy)Createa|  Create a new KeyHandle.

  Creates a new KeyHandle, triggering the provisioning of a new CryptoKey for
  CMEK use with the given resource type in the configured key project and the
  same location

  ## EXAMPLES

  The following command creates a KeyHandle named `my-key-handle` within the
  location `global` for the resource type `compute.googleapis.com/Disk`:

    $ {command} --key-handle-id=my-key-handle --my-key-handle --location=global
    --resource-type=compute.googleapis.com/Disk

  In case we want to generate a random KeyHandle id, we can use the
  `--generate-key-handle-id` flag instead of the `--key-handle-id` flag.
  c                     t        j                  |        | j                  j                  t         j                         y )N)r   AddCreateKeyHandleFlagsdisplay_infoAddCacheUpdaterKeyHandleCompleter)parsers    %lib/surface/kms/key_handles/create.pyArgszCreate.Args1   s,     
!!&)
''(@(@A    c                 v   t        j                         }t        j                         }|j                  j                  j                         }|j                  rG|j                  |j                         |j                  |j                  |j                              }n;|j                  |j                         |j                  |j                              }|j                  j                  |      }t        j                  j                  |j                   d      }t#        j$                  t#        j&                  |j                  |j(                        |d      }t+        j,                  |j                   d       t*        j.                  j1                  d	j3                  |j4                               |S )
N)resourceTypeSelector)parentkeyHandleId	keyHandle)r   r   z&cloudkms.projects.locations.operations)
collectionz$Waiting for KeyHandle to be created.	KeyHandle)kindz#The corresponding CryptoKey is: {0})cloudkms_baseGetClientInstanceGetMessagesModuleCONCEPTSlocationParsekey_handle_id0CloudkmsProjectsLocationsKeyHandlesCreateRequestRelativeNamer   resource_typeprojects_locations_keyHandlesr   r
   REGISTRYParseRelativeNamenamer   WaitForCloudOperationPollerprojects_locations_operationsr	   CreatedResourcestatusPrintformatkmsKey)	selfargsclientmessageslocation_refreq	operationoperation_refcreated_key_handles	            r   Runz
Create.Run7   sz   ,,.F..0H==))//1LEE**,((&&D<N<N&O F c EE**,&&D<N<N&O F c
 44;;C@I&&88#K 9 M  ##0000	
 	. *//kBJJ-445G5N5NO r   N)__name__
__module____qualname____doc__staticmethodr   r=    r   r   r   r      s"    $ B B
#r   r   N)rA   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.calliopegooglecloudsdk.command_lib.kmsr   googlecloudsdk.corer	   r
   UniverseCompatibleCreateCommandr   rC   r   r   <module>rL      sL     &  ' A . ( 0 # ) <T < <r   