
    v(                     n   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  SS	K	Jr  SS
KJr  \R"                  \R$                  " \R&                  R(                  \R&                  R*                  \R&                  R,                  5       " S S\R.                  5      5       5       rg)zCreate a key.    )absolute_import)division)unicode_literals)base)
exceptions)flags)maps)resource_args)labels_utilc                   4    \ rS rSrSr\S 5       rS rS rSr	g)Create   a  Create a new key.

Creates a new key within the given keyring.

The flag `--purpose` is always required when creating a key.
The flag `--default-algorithm` is required when creating a symmetric signing
key, an asymmetric key, or an external key. Algorithm and purpose should be
compatible.

The optional flags `--rotation-period` and `--next-rotation-time` define a
rotation schedule for the key. A schedule can also be defined
by the `--create-rotation-schedule` command.

The flag `--next-rotation-time` must be in ISO 8601 or RFC3339 format,
and `rotation-period` must be in the form INTEGER[UNIT], where units
can be one of seconds (s), minutes (m), hours (h) or days (d).

The optional flag `--protection-level` specifies the physical environment
where crypto operations with the key happen. The default is ``software''; use
``hsm'' to create a hardware-backed key, ``external'' to create an
externally backed key, or ``external-vpc'' to create an external key over vpc.

The optional flag `--labels` defines a user specified key/value pair for the
given key.

The flag `--skip-initial-version-creation` creates a CryptoKey with no
versions. If you import into the CryptoKey, or create a new version in that
CryptoKey, there will be no primary version until one is set using the
`--set-primary-version` command. You must include
`--skip-initial-version-creation` when creating a CryptoKey with protection
level ``external'' or ``external-vpc''.

The optional flag `--import-only` restricts the key to imported key versions
only. To do so, the flag `--skip-initial-version-creation` must also be set.

The optional flag `--destroy-scheduled-duration` defines the destroy schedule
for the key, and must be in the form INTEGER[UNIT], where units can be one of
seconds (s), minutes (m), hours (h) or days (d).

The flag `--crypto-key-backend` defines the resource name for the
backend where the key resides. Required for ``external-vpc'' keys.

The optional flag `--allowed-access-reasons` defines the Key Access
Justifications Policy for the key, and is specified as a comma separated list
of zero or more justification codes defined in
https://cloud.google.com/assured-workloads/key-access-justifications/docs/justification-codes.
The key must be enrolled in Key Access Justifications to use this flag.

## EXAMPLES

The following command creates a key named ``frodo'' with protection level
``software'' within the keyring ``fellowship'' and location ``us-east1'':

  $ {command} frodo \
      --location=us-east1 \
      --keyring=fellowship \
      --purpose=encryption

The following command creates a key named ``strider'' with protection level
``software'' within the keyring ``rangers'' and location ``global'' with a
specified rotation schedule:

  $ {command} strider \
      --location=global --keyring=rangers \
      --purpose=encryption \
      --rotation-period=30d \
      --next-rotation-time=2017-10-12T12:34:56.1234Z

The following command creates a raw encryption key named ``foo'' with
protection level ``software'' within the keyring ``fellowship'' and location
``us-east1'' with two specified labels:

  $ {command} foo \
      --location=us-east1 \
      --keyring=fellowship \
      --purpose=raw-encryption \
      --default-algorithm=aes-128-cbc
      --labels=env=prod,team=kms

The following command creates an asymmetric key named ``samwise'' with
protection level ``software'' and default algorithm ``ec-sign-p256-sha256''
within the keyring ``fellowship'' and location ``us-east1'':

  $ {command} samwise \
      --location=us-east1 \
      --keyring=fellowship \
      --purpose=asymmetric-signing \
      --default-algorithm=ec-sign-p256-sha256

The following command creates a key named ``gimli'' with protection level
``hsm'' and default algorithm ``google-symmetric-encryption'' within the
keyring ``fellowship'' and location ``us-east1'':

  $ {command} gimli \
      --location=us-east1 \
      --keyring=fellowship \
      --purpose=encryption \
      --protection-level=hsm

The following command creates a key named ``legolas'' with protection level
``external'' and default algorithm ``external-symmetric-encryption'' within
the keyring ``fellowship'' and location ``us-central1'':

  $ {command} legolas \
      --location=us-central1 \
      --keyring=fellowship \
      --purpose=encryption \
      --default-algorithm=external-symmetric-encryption \
      --protection-level=external
      --skip-initial-version-creation

The following command creates a key named ``bilbo'' with protection level
``external-vpc'' and default algorithm ``external-symmetric-encryption'' and
an EkmConnection of ``eagles'' within the keyring ``fellowship'' and location
``us-central1'':

  $ {command} bilbo \
      --location=us-central1 \
      --keyring=fellowship \
      --purpose=encryption \
      --default-algorithm=external-symmetric-encryption \
      --protection-level=external-vpc
      --skip-initial-version-creation
      --crypto-key-backend="projects/$(gcloud config get project)/
      locations/us-central1/ekmConnections/eagles"

The following command creates a key named ``arwen'' with protection level
``software'' within the keyring ``fellowship'' and location ``us-east1'' with
a Key Access Justifications policy that allows access reasons
``customer-initiated-access'' and ``google-initiated-system-operation'':

  $ {command} arwen \
      --location=us-east1 \
      --keyring=fellowship \
      --purpose=encryption \
      --allowed-access-reasons=customer-initiated-access,google-initiated-system-operation
c                    [         R                  " U SS5        [        R                  " U 5        [        R                  " U 5        [        R
                  " U 5        [        R                  " U 5        U R                  S[        [        R                  R                  5       5      SSS9  U R                  R                  [        R                  5        [        R                   " U 5        [        R"                  " U 5        [        R$                  " U 5        [        R&                  " U 5        [        R(                  " U 5        [        R*                  " U 5        g )NTkeyz	--purposezThe "purpose" of the key.)choicesrequiredhelp)r
   AddKmsKeyResourceArgForKMSr   AddRotationPeriodFlagAddNextRotationTimeFlag!AddSkipInitialVersionCreationFlagr   AddCreateLabelsFlagsadd_argumentsortedr	   PURPOSE_MAPkeysdisplay_infoAddCacheUpdaterKeyRingCompleterAddProtectionLevelFlagAddDefaultAlgorithmFlagAddImportOnlyFlagAddDestroyScheduledDurationFlagAddCryptoKeyBackendFlagAddAllowedAccessReasonsFlag)parsers    lib/surface/kms/keys/create.pyArgsCreate.Args   s    ,,VT5A	'	!!&)	++F3$$V,
t'',,./(	  *
 ''(>(>?	  (	!!&)	F#	))&1	!!&)	%%f-    c                 (   [         R                  " 5       n[        R                  UR                     n[        R
                  U   nUR                  (       dV  UR                  S:w  a?  [        R                  " SR                  UR                  SR                  U5      5      5      eSUl        UR                  U;  a?  [        R                  " SR                  UR                  SR                  U5      5      5      eUR                  R                  R                  5       nUR                  5       nUR                  UR!                  5       UR#                  5       UR%                  UUR'                  [        R(                  R+                  UR,                  5      [        R.                  R+                  UR                  5      S9[0        R2                  " UUR$                  R4                  5      UR6                  UR8                  S9UR:                  S9n[<        R>                  " XR@                  5        [<        RB                  " XR@                  5        [<        RD                  " XR@                  5        [<        RF                  " XR@                  5        U$ )	N
encryptionzm--default-algorithm needs to be specified when creating a key with --purpose={}. The valid algorithms are: {}z, zgoogle-symmetric-encryptionzbDefault algorithm and purpose are incompatible. Here are the valid algorithms for --purpose={}: {})protectionLevel	algorithm)purposeversionTemplatelabels
importOnlycryptoKeyBackend)parentcryptoKeyId	cryptoKeyskipInitialVersionCreation)$cloudkms_baseGetMessagesModuler	   r   r/   VALID_ALGORITHMS_MAPdefault_algorithmkms_exceptionsArgumentErrorformatjoinCONCEPTSr   ParseParent8CloudkmsProjectsLocationsKeyRingsCryptoKeysCreateRequestRelativeNameName	CryptoKeyCryptoKeyVersionTemplatePROTECTION_LEVEL_MAPPERGetEnumForChoiceprotection_levelALGORITHM_MAPPERr   ParseCreateArgsLabelsValueimport_onlycrypto_key_backendskip_initial_version_creationr   SetNextRotationTimer6   SetRotationPeriodSetDestroyScheduledDuration SetKeyAccessJustificationsPolicy)selfargsmessagesr/   valid_algorithmscrypto_key_ref
parent_refreqs           r'   _CreateRequestCreate._CreateRequest   s   ..0Ht||,G009
 !!		%**::@&dii(89;;< 	<  =d %55((,,2F4<<3799=M3N-PQ Q
 ]]&&,,.N&&(J

K
K&&("'')$$$== $ < < M M))!+//@@**, > -
 ..t/7/A/A/M/MO''!44 % 
6 $(#E#E L GC  
dMM2	D--0	%%dMM:	**4?Jr*   c                     [         R                  " 5       nUR                  R                  U R	                  U5      5      $ )N)r8   GetClientInstance&projects_locations_keyRings_cryptoKeysr   r\   )rU   rV   clients      r'   Run
Create.Run   s7    ,,.F88??D!# #r*    N)
__name__
__module____qualname____firstlineno____doc__staticmethodr(   r\   rb   __static_attributes__rd   r*   r'   r   r      s(    
HT . .&.`#r*   r   N)ri   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   r8   googlecloudsdk.calliopegooglecloudsdk.command_lib.kmsr   r<   r   r	   r
   $googlecloudsdk.command_lib.util.argsr   UniverseCompatibleReleaseTracksReleaseTrackALPHABETAGACreateCommandr   rd   r*   r'   <module>rx      s     &  ' A ( G 0 / 8 < T..33T5F5F5I5IR#T R# R#r*   