
    7                     .   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 dd
lmZ ddlmZ ddlmZ ddiZdddddZdZd Zd Zd Zej6                   ej8                  ej:                  j<                         G d dej>                                      Z  ej8                  ej:                  jB                         G d de              Z" ej8                  ej:                  jF                         G d de"             Z$y)z$Cloud Pub/Sub topics update command.    )absolute_import)division)unicode_literals)topics)base)resource_args)flags)util)labels_util)
exceptions)logEXAMPLESaS            To update existing labels on a Cloud Pub/Sub topic, run:

              $ {command} mytopic --update-labels=KEY1=VAL1,KEY2=VAL2

          To clear all labels on a Cloud Pub/Sub topic, run:

              $ {command} mytopic --clear-labels

          To remove an existing label on a Cloud Pub/Sub topic, run:

              $ {command} mytopic --remove-labels=KEY1,KEY2

          To enable customer-managed encryption for a Cloud Pub/Sub topic by protecting message data with a Cloud KMS CryptoKey, run:

              $ {command} mytopic --topic-encryption-key=projects/PROJECT_ID/locations/KMS_LOCATION/keyRings/KEYRING/cryptoKeys/KEY

          To enable or update retention on a Cloud Pub/Sub topic, run:

              $ {command} mytopic --message-retention-duration=MESSAGE_RETENTION_DURATION

          To disable retention on a Cloud Pub/Sub topic, run:

              $ {command} mytopic --clear-message-retention-duration

          To update a Cloud Pub/Sub topic's message storage policy, run:

              $ {command} mytopic --message-storage-policy-allowed-regions=some-cloud-region1,some-cloud-region2

          To recompute a Cloud Pub/Sub topic's message storage policy based on your organization's "Resource Location Restriction" policy, run:

              $ {command} mytopic --recompute-message-storage-policy

          To enforce both at-rest and in-transit guarantees for messages published to the topic, run:

              $ {command} mytopic --message-storage-policy-allowed-regions=some-cloud-region1,some-cloud-region2 --message-storage-policy-enforce-in-transit
          z--topic-encryption-keyz--topic-encryption-key-keyringz--topic-encryption-key-locationz--topic-encryption-key-project)zkms-keyzkms-keyringzkms-locationzkms-projectad  
The specified Cloud KMS key should have purpose set to "ENCRYPT_DECRYPT".
The service account,
"service-${CONSUMER_PROJECT_NUMBER}@gcp-sa-pubsub.iam.gserviceaccount.com"
requires the IAM cryptoKeyEncrypterDecrypter role for the given Cloud KMS key.
CONSUMER_PROJECT_NUMBER is the project number of the project that is the parent
of the topic being updatedc                     | j                   j                  j                         }|r|j                         S dD ]8  }| j	                  |j                  dd            s%t        j                  d       y)zParses the KMS key resource name from args.

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

  Returns:
    The KMS CryptoKey resource name for the key specified in args, or None.
  )ztopic-encryption-keyztopic-encryption-key-projectztopic-encryption-key-locationztopic-encryption-key-keyring-_z/--topic-encryption-key was not fully specified.N)CONCEPTSkms_keyParseRelativeNameIsSpecifiedreplacecore_exceptionsError)argskms_refkeywords      #lib/surface/pubsub/topics/update.py_GetKmsKeyNameFromArgsr   U   sp     MM!!'')'!!g S12!!
;  
    c                    t        j                  | d       t        j                  |        t        j                  | t        j                  dt        t              g       t        j                  | d       t        j                  | d       t        j                  | d       t        j                  | d       t        j                  | d       y)!Registers flags for this command.z
to update.topic)flag_overridespermission_infoT)	is_updateN)r   AddTopicResourceArgr   AddUpdateLabelsFlagsAddResourceArgskms_resource_argsGetKmsKeyPresentationSpec_KMS_FLAG_OVERRIDES_KMS_PERMISSION_INFOr	   AddTopicMessageRetentionFlags!AddTopicMessageStoragePolicyFlagsAddSchemaSettingsFlagsAddIngestionDatasourceFlagsAddMessageTransformsFlagsparsers    r   _Argsr4   r   s     ##FL9""6*

5
502	 %%f=))&DAv6## !!&D9r   c           
         +, t        j                         + j                  j                  j	                         ,t         dd      }|rt        j                  |      }t         dd      }t        j                   +j                  j                  j                  +,fd      }t         dd      }|r2 j                  j                  j	                         j                         }t         dd      }d}|r|d   }t         d	d      }t         d
d      }d}	t         dd      }
t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }d}|r|d   }t         dd      }|r |j                  d      j!                  d      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         dd      }t         d d      }t         d!d      }t         d"d      } t         d#d      }!t         d$d      }"t         d%d      }#t         d&d      }$t         d'd      }%t         d(d      }&t         d)d      }'t         d*d      }(t         d+d      })	  +j"                  ,|j%                         t'               || j(                   j*                  |fi d|d|d	|d
|d|
d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d |d!|d"| d#|!d$|"d%|#d&|$d'|%d)|'d(|&d*|(d+|)}	t-        j.                  ,j                         d,-       |	S # t         j0                  $ r< g d.}*t3         fd/|*D              s t,        j4                  j7                  d0       Y |	S w xY w)1ab  This 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:
    A serialized object (dict) describing the results of the operation.

  Raises:
    An HttpException if there was a problem calling the
    API topics.Patch command.
  message_retention_durationN clear_message_retention_durationc                  :     j                        j                  S N)Getlabels)client	topic_refs   r   <lambda>z_Run.<locals>.<lambda>   s    

9 5 < <r   )orig_labels_thunkschemamessage_encodingr   first_revision_idlast_revision_idclear_schema_settings)message_storage_policy_enforce_in_transitkinesis_ingestion_stream_arnkinesis_ingestion_consumer_arnkinesis_ingestion_role_arn!kinesis_ingestion_service_accountcloud_storage_ingestion_bucket$cloud_storage_ingestion_input_format&cloud_storage_ingestion_text_delimiterzutf-8zunicode-escape2cloud_storage_ingestion_minimum_object_create_time"cloud_storage_ingestion_match_glob)azure_event_hubs_ingestion_resource_group$azure_event_hubs_ingestion_namespace$azure_event_hubs_ingestion_event_hub$azure_event_hubs_ingestion_client_id$azure_event_hubs_ingestion_tenant_id*azure_event_hubs_ingestion_subscription_id*azure_event_hubs_ingestion_service_accountaws_msk_ingestion_cluster_arnaws_msk_ingestion_topicaws_msk_ingestion_aws_role_arn!aws_msk_ingestion_service_account*confluent_cloud_ingestion_bootstrap_server$confluent_cloud_ingestion_cluster_idconfluent_cloud_ingestion_topic*confluent_cloud_ingestion_identity_pool_id)confluent_cloud_ingestion_service_accountingestion_log_severity$clear_ingestion_data_source_settingsmessage_transforms_fileclear_message_transformsr"   )kind)clear_labelsupdate_labelsremove_labels recompute_message_storage_policy&message_storage_policy_allowed_regionsc              3   @   K   | ]  }j                  |        y wr9   )r   ).0argr   s     r   	<genexpr>z_Run.<locals>.<genexpr>L  s     ;
t$
s   zNo update to perform.)r   TopicsClientr   r"   r   getattrr
   FormatDurationr   ProcessUpdateArgsLazymessagesTopicLabelsValuer@   r   encodedecodePatch	GetOrNoner   rg   rh   r   UpdatedResourceNoFieldsSpecifiedErroranystatusPrint)-r   r6   r7   labels_updater@   message_encoding_listrA   rB   rC   resultrD   rE   rF   rG   rH   rI   rJ   )cloud_storage_ingestion_input_format_listrK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   
operationsr<   r=   s-   `                                          @@r   _Runr      s     &mm!!''))&t-I4P!%!4!45O!P%,
.&" 33
oo''<- 44(&]]!!'')668F!$(:DA,Q/d$7>T#5t<&!$(?F.5
7/+ ")
*D" $+
,d$   't-I4P&-
/'# $+
,d$  /6
2D/+ *.&.1!4 ) ,3
4d,( , 	/55g>EE	
 +
 8?
@$84 (/
0$($ /6
7/+ *1
2D*& *1
2D*& *1
2D*& *1
2D*& 07
8$0, 07
8$0, #*
+T# $D*CTJ#*
,d$  '.
/'# 07
8$0, *1
2D*& %,
-t%! 07
8$0, /6
7/+ #4)A4H)0
2D*& $D*CTJ$T+EtL9@V\\!t$"(--331+ + *+ ,+ *+ 4+ &B+ (F+  $>!+" +L#+$ (F%+& .R'+( 0V)+* <n++, ,N-+. 3\/+0 .R1+2 .R3+4 .R5+6 .R7+8 4^9+: 4^;+< 'D=+> !8?+@ (FA+B +LC+D 4^E+F .RG+H )HI+J 4^K+L 3\M+N .RO+P  6Q+R !8S+T ":U+Fp 	..0w?	- 
	&	& 
.J ;
;;JJ,- 
-
.s   B)N) )AO87O8c                   *    e Zd ZdZeZed        Zd Zy)Update(Updates an existing Cloud Pub/Sub topic.c                     t        |        y)r!   Nr4   r2   s    r   ArgszUpdate.Args[  s     
r   c                     t        |      S r9   r   selfr   s     r   Runz
Update.Runb      :r   N)	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr   r    r   r   r   r   T  s#     1- r   r   c                   &    e Zd ZdZed        Zd Zy)
UpdateBetar   c                     t        |        y r9   r   r2   s    r   r   zUpdateBeta.Argsj      	r   c                     t        |      S r9   r   r   s     r   r   zUpdateBeta.Runp  r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   f  s    0 
r   r   c                        e Zd ZdZed        Zy)UpdateAlphar   c                     t        |        y r9   r   r2   s    r   r   zUpdateAlpha.Argsx  r   r   N)r   r   r   r   r   r   r   r   r   r   r   t  s    0 r   r   N)%r   
__future__r   r   r   googlecloudsdk.api_lib.pubsubr   googlecloudsdk.callioper   googlecloudsdk.command_lib.kmsr   r)   !googlecloudsdk.command_lib.pubsubr	   r
   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   r   r+   r,   r   r4   r   UniverseCompatibleReleaseTracksReleaseTrackGAUpdateCommandr   BETAr   ALPHAr   r   r   r   <module>r      s   + &  ' 0 ( M 3 ; 2 < = # $ $N (353	  ::8CL D%%(()T  *   D%%**+
 
 ,
 D%%++,*  -r   