
    #                     b   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"                   e	j$                  e	j&                  j(                  e	j&                  j*                  e	j&                  j,                         G d de	j.                                      Zy)z"'logging settings update' command.    )absolute_import)division)unicode_literals)util)arg_parsers)base)
exceptions)resource_args)
completersc                   &    e Zd ZdZed        Zd Zy)Updatea  Update the settings for the Cloud Logging Logs Router.

  Use this command to update the *--kms-key-name, --storage-location,
  --disable-default-sink* and --analytics-mode associated with the Cloud Logging
  Logs Router.

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

  The storage location must be allowed by Org Policy.

  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

  To update storage location for the Logs Router for an organization, run:

    $ {command} --organization=[ORGANIZATION_ID]
    --storage-location=[LOCATION_ID]

  To update storage location for the Logs Router for a folder, run:

    $ {command} --folder=[FOLDER_ID] --storage-location=[LOCATION_ID]

  To disable default sink for the Logs Router for an organization, run:

    $ {command} --organization=[ORGANIZATION_ID] --disable-default-sink=true

  To enable default sink for the Logs Router for an organization, run:

    $ {command} --organization=[ORGANIZATION_ID] --disable-default-sink=false

  To enable analytics for the log buckets under an organization, run:

    $ {command} --organization=[ORGANIZATION_ID] --disable-default-sink=false
    --analytics-mode=required
  c           
         | j                  d      }|j                  dddt        j                  d       |j                  ddd	d
       | j                  ddd       | j                  ddd       | j                  dddg dt	        j
                  dd             | j                  d      }t        j                  |ddd       |j                  ddd       y) z Register flags for this command.T)requiredz--organizationFORGANIZATION_IDz0Organization to update Logs Router settings for.)r   metavar	completerhelpz--folder	FOLDER_IDz*Folder to update Logs Router settings for.)r   r   r   --storage-locationzUpdate the storage location for ```_Default``` bucket and ```_Required``` bucket. Note: It only applies to the newly created projects and will not affect the projects created before.)r   r   --disable-default-sink
store_truezEnable or disable ```_Default``` sink for the ```_Default``` bucket. Specify --no-disable-default-sink to enable a disabled ```_Default``` sink. Note: It only applies to the newly created projects and will not affect the projects created before.)actionr   z--analytics-mode)r   optionalunspecifiedzxUpdate the analytics mode for newly-created project buckets. Changing this setting does not modify any existing buckets.zThis is not available.
)defaultuniverse_help)r   hiddenchoicesr   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-keyziDisable CMEK for the Logs Router by clearing out Cloud KMS cryptokey in the organization's CMEK settings.N)add_mutually_exclusive_groupadd_argumentr   OrganizationCompleterr   UniverseHelpTextkms_resource_argsAddKmsKeyResourceArg)parserparent_groupgroups      &lib/surface/logging/settings/update.pyArgszUpdate.ArgsV   s4    666EL!22?  A 9	  ; D  E  D  E 7))N 5
   ///?E**H#  
@  B    c           
         i }g }g d}|j                  d      rF|j                  j                  j                         j	                         |d<   |j                  d       |j                  d      rd|d<   |j                  d       |j                  d      r |j                  |d<   |j                  d       |j                  d      r |j                  |d	<   |j                  d       |j                  d
      r|j                  d
       |j                  dk(  r6t        j                         j                  j                  j                  |d<   nz|j                  dk(  r6t        j                         j                  j                  j                  |d<   n5t        j                         j                  j                  j                  |d<   |st!        j"                  |d      t        j$                  |      }t        j&                         j(                  j+                  t        j                         j-                  | t        j                         j                  di |dj/                  |                  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 settings.
    )z --kms-key-name | --clear-kms-keyr   r   kms_key_name
kmsKeyNameclear_kms_key storage_locationstorageLocationdisable_default_sinkdisableDefaultSinkanalytics_moder   analyticsModer   z/Please specify at least one property to update.,)r!   settings
updateMask )IsSpecifiedCONCEPTSr/   ParseRelativeNameappendr3   r5   r7   r   GetMessagesSettingsAnalyticsModeValueValuesEnumANALYTICS_REQUIREDANALYTICS_OPTIONALANALYTICS_MODE_UNSPECIFIEDcalliope_exceptionsMinimumArgumentExceptionGetParentFromArgs	GetClientv2UpdateSettingsLoggingUpdateSettingsRequestjoin)selfargsr:   update_maskparameter_namesparent_names         r+   Runz
Update.Run   s/    HKO
 '
--
$
$
*
*
,
9
9
; |((!h|(*+$($9$9h !+,./'+'@'@h#$/0())*			
	*''DDWW 	! *,''DDWW 	!
 ''DD__ 	! 88
LN N ((.K>>--770T%%'00<8<xx, 	8 	./ /r-   N)__name__
__module____qualname____doc__staticmethodr,   rU   r<   r-   r+   r   r      s$    /b ;B ;Bz:/r-   r   N)rY   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   r   r	   rH   googlecloudsdk.command_lib.kmsr
   r&   +googlecloudsdk.command_lib.resource_managerr   UniverseCompatibleReleaseTracksReleaseTrackALPHABETAGACommandr   r<   r-   r+   <module>rg      s     ) '  ' / / ( E M B T..33T5F5F5I5Ik/T\\ k/ k/r-   