
    a                         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  G d	 d
ej                        Zy)z''logging cmek-settings update' command.    )absolute_import)division)unicode_literals)util)base)resource_args)
completersc                   &    e Zd ZdZed        Zd Zy)Updatea  Update the CMEK settings for the Cloud Logging Logs Router.

  Use this command to update the *--kms-key-name* associated with the
  Cloud Logging Logs Router.

  The Cloud KMS key must already exist and Cloud Logging must have
  permission to access it.

  Customer-managed encryption keys (CMEK) for the Logs Router can currently
  only be configured at the organization-level and will apply to all projects
  in the organization.

  ## EXAMPLES

  To enable CMEK for the Logs Router for an organization, run:

    $ {command} --organization=[ORGANIZATION_ID]
    --kms-key-name='projects/my-project/locations/my-location/keyRings/my-keyring/cryptoKeys/key'

  To disable CMEK for the Logs Router for an organization, run:

    $ {command} --organization=[ORGANIZATION_ID] --clear-kms-key
  c                     | j                  dddt        j                  d       | j                  d      }t	        j
                  |ddd	
       |j                  ddd       y)z Register flags for this command.z--organizationTORGANIZATION_IDz5Organization to update Logs Router CMEK settings for.)requiredmetavar	completerhelp)r   z5logs being processed by the Cloud Logging Logs RouterzqThe Cloud KMS CryptoKey Encrypter/Decryper role must be assigned to the Cloud Logging Logs Router service accountz--kms-key-name)resourcepermission_infonamez--clear-kms-key
store_trueziDisable CMEK for the Logs Router by clearing out Cloud KMS cryptokey in the organization's CMEK settings.)actionr   N)add_argumentr	   OrganizationCompleteradd_mutually_exclusive_groupkms_resource_argsAddKmsKeyResourceArg)parsergroups     +lib/surface/logging/cmek_settings/update.pyArgszUpdate.Args7   s     !22D  F ///>E**H#  
@  B    c           
         i }|j                  d      r5|j                  j                  j                         j	                         |d<   |j                  d      rd|d<   t        j                  |      }t        j                         j                  j                  t        j                         j                  | t        j                         j                  di |d            S )zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The updated CMEK settings.
    kms_key_name
kmsKeyNameclear_kms_key )r   cmekSettings
updateMask )IsSpecifiedCONCEPTSr"   ParseRelativeNamer   GetParentFromArgs	GetClientorganizationsUpdateCmekSettingsGetMessages-LoggingOrganizationsUpdateCmekSettingsRequestCmekSettings)selfargscmek_settingsparent_names       r   Runz
Update.RunQ   s     M'
--
$
$
*
*
,
9
9
; L! ($&mL!((.K>>))<<HH8))+88I=I% 	I 	'( (r    N)__name__
__module____qualname____doc__staticmethodr   r8   r(   r    r   r   r      s"    0 B B2(r    r   N)r<   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   googlecloudsdk.command_lib.kmsr   r   +googlecloudsdk.command_lib.resource_managerr	   Commandr   r(   r    r   <module>rD      s3     . '  ' / ( M BK(T\\ K(r    