
    0                     R   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lmZ ddlmZ ddlmZ dddddZdZd Zd ZddZd Zej>                   ej@                  ejB                  jD                         G d dejF                                      Z$ ej@                  ejB                  jJ                         G d de$             Z& ej@                  ejB                  jN                         G d de&             Z(y) z$Cloud Pub/Sub topics create command.    )absolute_import)division)unicode_literals)
exceptions)topics)base)resource_args)flags)util)labels_util)log)
propertiesz--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 createdc                  B    t        j                  dt        t              S )Ntopic)flag_overridespermission_info)kms_resource_argsGetKmsKeyPresentationSpec_KMS_FLAG_OVERRIDES_KMS_PERMISSION_INFO     #lib/surface/pubsub/topics/create.py_GetKmsKeyPresentationSpecr   2   s    		4	4(*
 r   c                  2    t        j                  ddd      S )Nz
to create.T)
positionalplural)r	   CreateTopicResourceArgr   r   r   _GetTopicPresentationSpecr   :   s    		-	-tD
 r   c           	   #   	  K   t        j                         }t        j                  | |j                  j
                  j                        }d}| j                  j                  j                         }|r|j                         }n=dD ]8  }| j                  |j                  dd            s%t        j                  d       t        | dd      }| j                  d      rt!        j"                  |      }| j$                  }t        | dd      }	t        | dd      }
d}d}|
rL| j                  j&                  j                         j                         }
t        | d	d      }t        | d
d      }t        | dd      }d}|r|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-        j.                  | |j                  j
                  j0                        }+g },| j                  j2                  j                         D ]  }-	  |j4                  |-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'|(d(|)d)|*d-|+}.|rt!        jL                  |.      }.t?        j@                  |-j                         d.0       |.  |,rt!        jN                  |,d1      y# t6        j8                  $ r}/t;        j<                  |/      }0t?        j@                  |-j                         d.t!        jB                  |0jD                  jF                        /       |,jI                  |-jJ                         Y d}/~/ud}/~/ww xY ww)2zCreates one or more topics.N)ztopic-encryption-keyztopic-encryption-key-projectztopic-encryption-key-locationztopic-encryption-key-keyring-_z/--topic-encryption-key was not fully specified.message_retention_duration)message_storage_policy_enforce_in_transitschemafirst_revision_idlast_revision_idmessage_encodingr   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message_transforms_filelabelskms_key&message_storage_policy_allowed_regionstagsr   )kindfailed)rH   create)(r   TopicsClientr   ParseCreateArgsmessagesTopicLabelsValueCONCEPTSrE   ParseRelativeNameIsSpecifiedreplacecore_exceptionsErrorgetattrr   FormatDurationrF   r%   encodedecoder
   GetTagsMessage	TagsValuer   Createapi_ex	HttpErrorr   HttpExceptionr   CreatedResourceCreateFailureErrorMessagepayloadstatus_messageappendtopicsIdTopicDisplayDictRequestsFailedError)1argslegacy_outputclientrD   rE   kms_refkeywordretention_durationrF   r$   r%   r&   r'   message_encoding_listr(   r)   r*   r+   r,   r-   )cloud_storage_ingestion_input_format_listr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rG   rI   	topic_refresulterrorexcs1                                                    r   _Runru   @   s     &&&tV__-B-B-N-NO&'MM!!'')'""$G 
		'//#s3	4##=
 	
 t%A4H	23,,-?@ 11 ) /6
7/+ 44(&]]!!'')668F&94@t%7>!$(:DA,Q/!(
*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#D*CTJ			dFOO$9$9$C$C	D$&==&&,,.i1v}}
'' ' &8	'
 2X' 5^' ' ,' .' ,' (D' *H' &@' -N' *H'  0T!'" 2X#'$ >p%'& .P''( 5^)'* 0T+', 0T-'. 0T/'0 0T1'2 6`3'4 6`5'6 )F7'8 #:9': *H;'< -N='> 6`?'@ 0TA'B +JC'D 6`E'F 5^G'H "8I'J #:K'L M'fd $$V,f	..0w?
Lo /r 

"
"68
44   $$U+c	

 
 
"//0J0JK
 mmI&&'s:   B(S#+J>S#*B Q*AS#S A=SS#S  S#c                 `   t        j                  | t               t               g       t	        j
                  | d       t	        j                  | d       t        j                  |        t	        j                  | d       t	        j                  | d       t	        j                  |        y)zGCustom args implementation.

  Args:
    parser: The current parser.
  F)	is_updateN)r	   AddResourceArgsr   r   r
   AddSchemaSettingsFlagsAddIngestionDatasourceFlagsr   AddCreateLabelsFlagsAddTopicMessageRetentionFlags!AddTopicMessageStoragePolicyFlagsAddMessageTransformsFlagsparsers    r   _Argsr     s     )+-F-HI v7##
 ""6*%%f>))&EB!!&)r   c                   .    e Zd ZdZddiZed        Zd Zy)r]   )Creates one or more Cloud Pub/Sub topics.EXAMPLESzR          To create a Cloud Pub/Sub topic, run:

              $ {command} mytopicc                     t        |        y Nr   r   s    r   ArgszCreate.Args,      	r   c                     t        |      S r   )ru   )selfri   s     r   Runz
Create.Run2  s    :r   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r   r   r   r   r]   r]   "  s/     2  % &-
  
r   r]   c                   &    e Zd ZdZed        Zd Zy)
CreateBetar   c                     t        |        y r   r   r   s    r   r   zCreateBeta.Args:  r   r   c                     t         j                  j                  j                  j	                         }t        ||      S )N)rj   )r   VALUESpubsubrj   GetBoolru   )r   ri   rj   s      r   r   zCreateBeta.Run@  s/    %%,,::BBDMM22r   N)r   r   r   r   r   r   r   r   r   r   r   r   6  s    1 
3r   r   c                   ,     e Zd ZdZe fd       Z xZS )CreateAlphar   c                 ^    t         t        t          |        t        j                  |        y r   )superr   r   r
   AddTagsFlag)r   	__class__s    r   r   zCreateAlpha.ArgsI  s     	+{(0	fr   )r   r   r   r   r   r   __classcell__)r   s   @r   r   r   E  s    1 r   r   N)F))r   
__future__r   r   r   apitools.base.pyr   r^   googlecloudsdk.api_lib.pubsubr   googlecloudsdk.api_lib.utilgooglecloudsdk.callioper   googlecloudsdk.command_lib.kmsr	   r   !googlecloudsdk.command_lib.pubsubr
   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corerU   r   r   r   r   r   r   ru   r   UniverseCompatibleReleaseTracksReleaseTrackGACreateCommandr]   BETAr   ALPHAr   r   r   r   <module>r      s   + &  ' 1 0 2 ( M 3 ; 2 < = # * (353	  E5P*4 D%%(()T  * $ D%%**+3 3 ,3 D%%++,*  -r   