
    8                        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  SSKrSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr! " S S\RD                  5      r# " S S\RD                  5      r$ S;S jr%S<S  jr&S<S! jr'S<S" jr(S=S# jr)S$ r*S% r+S& r,S' r-S=S( jr.S) r/S* r0S+ r1S=S, jr2S- r3S. r4S/ r5S0 r6S1 r7S2 r8S3 r9S4 r:S5 r;S6 r<S7 r=S8 r>S9 r?S: r@g)>z9A library that is used to support Cloud Pub/Sub commands.    )subscriptions)topics)
exceptions)util)log)
properties)	resources)resource_projector)timesNz%Y-%m-%dT%H:%M:%S.%fZzpubsub.projects.topicszpubsub.topics.publishzpubsub.projects.snapshotszpubsub.snapshots.listzpubsub.projects.subscriptionszpubsub.subscriptions.ackzpubsub.subscriptions.listzpubsub.subscriptions.mod_ackzpubsub.subscriptions.mod_configzpubsub.subscriptions.pullzpubsub.subscriptions.seekpubsub.projects.schemasa  Using --push-auth-service-account requires specifying --push-endpoint. This
command will continue to run while ignoring --push-auth-service-account, but
will fail in a future version. To correct a subscription configuration, run:
  $ gcloud pubsub subscriptions update SUBSCRIPTION \
      --push-endpoint=PUSH_ENDPOINT \
      --push-auth-service-account={SERVICE_ACCOUNT_EMAIL} [...]
a  Using --push-auth-token-audience requires specifying both --push-endpoint and
--push-auth-service-account. This command will continue to run while ignoring
--push-auth-token-audience, but will fail in a future version. To correct a
subscription configuration, run:
  $ gcloud pubsub subscriptions update SUBSCRIPTION \
      --push-endpoint={PUSH_ENDPOINT} \
      --push-auth-service-account={SERVICE_ACCOUNT_EMAIL} \
      --push-auth-token-audience={OPTIONAL_AUDIENCE_OVERRIDE} [...]
c                       \ rS rSrSrSrg)InvalidArgumentErrorG   z$The user provides invalid arguments. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       -lib/googlecloudsdk/command_lib/pubsub/util.pyr   r   G   s    ,r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )RequestsFailedErrorK   z4Indicates that some requests to the API have failed.c                 f   > [         [        U ]  SR                  USR	                  U5      S95        g )Nz/Failed to {action} the following: [{requests}].,)actionrequests)superr   __init__formatjoin)selfr   r   	__class__s      r   r!   RequestsFailedError.__init__N   s5    	
t-9@@CHHX$6 	A 	89r   r   )r   r   r   r   r   r!   r   __classcell__)r%   s   @r   r   r   K   s    <9 9r   r   c                     U (       a  U $ U$ Nr   )original_messagedefault_messages     r   CreateFailureErrorMessager,   T   s     .	B?Br   c                 b    [        U5      n[        R                  R                  U SU0[        S9$ N
projectsIdparams
collection)_GetProjectr	   REGISTRYParseSNAPSHOTS_COLLECTION)snapshot_name
project_ids     r   ParseSnapshotr9   Z   s9    :&*				!	!-*6
)C-A 
" 
C Cr   c                 b    [        U5      n[        R                  R                  U SU0[        S9$ r.   )r3   r	   r4   r5   SUBSCRIPTIONS_COLLECTION)subscription_namer8   s     r   ParseSubscriptionr=   a   s:    :&*				!	!"3*6
)C-E 
" 
G Gr   c                 b    [        U5      n[        R                  R                  U SU0[        S9$ r.   )r3   r	   r4   r5   TOPICS_COLLECTION)
topic_namer8   s     r   
ParseTopicrA   h   s9    :&*				!	!**6
)C-> 
" 
@ @r   c                 D    [        U 5      n [        R                  " U 5      $ r)   )r3   projects_utilParseProjectr8   s    r   rD   rD   o   s    :&*		#	#J	//r   c                 v    U =(       d1    [         R                  R                  R                  R	                  SS9$ )NTrequiredr   VALUEScoreprojectGetrE   s    r   r3   r3   t   s-    		Hz((--559949HHr   c                 n    [        U [        5      (       a  U S   nOU n[        U5      R                  5       $ )Nname)
isinstancedictr9   SelfLink)snapshotrO   s     r   SnapshotUriFuncrT   x   s2    $FDD	t		%	%	''r   c                     S n[        U [        5      (       a  U S   nU S   nO$[        U [        5      (       a  U nOU R                  n[	        X!5      R                  5       $ )NsubscriptionId	projectId)rP   rQ   strrO   r=   rR   )subscriptionrL   rO   s      r   SubscriptionUriFuncrZ      sZ    'd##()D;'G,$$DD	4	)	2	2	44r   c                     [        U [        5      (       a  U S   nOU R                  n[        U5      R	                  5       $ )NtopicId)rP   rQ   rO   rA   rR   )topicrO   s     r   TopicUriFuncr^      s6    tD::D	D		"	"	$$r   c                    U R                   n[        U SS5      n[        U SS5      nUbB  Ub  Uc<  [        R                  " [        R                  U=(       d    SU=(       d    SUS95        O-Ub*  Uc'  [        R                  " [        R                  US95        Uc  [        U 5      (       a  [        S5      egU=(       d    [        R                  " 5       nSnUb  UR                  R                  X4S9nSn[        U 5      (       a&  [        U S	S
5      nUR                  R                  US9nUR                  R                  X%US9$ )z.Parses configs of push subscription from args.SERVICE_ACCOUNT_EMAILNOPTIONAL_AUDIENCE_OVERRIDEPUSH_ENDPOINT)rb   r`   ra   )r`   z>argument --push-no-wrapper: --push-endpoint must be specified.)serviceAccountEmailaudiencepush_no_wrapper_write_metadataF)writeMetadata)pushEndpoint	oidcToken	noWrapper)push_endpointgetattrr   warning7PUSH_AUTH_TOKEN_AUDIENCE_MISSING_REQUIRED_FLAGS_WARNINGr"   2PUSH_AUTH_SERVICE_ACCOUNT_MISSING_ENDPOINT_WARNINGHasNoWrapperr   r   SubscriptionsClientmessages	OidcToken	NoWrapper
PushConfig)argsclientrj   service_account_emailrd   
oidc_token
no_wrapperwrite_metadatas           r   ParsePushConfigr{      sf   $$-!$(?FT7>( 4<KK?FF':?"7 #'&'/	 	G 	
 (]-BKK:AA"7 	B 	
 D 
J  8]668&* &**1 + FJ *$T#CUKN***HJ		#	# * 
$ 
N Nr   c                     [        U SS5      $ )Npush_no_wrapperF)rk   )ru   s    r   ro   ro      s    	(%	00r   c                 R    [         R                  " U [        [         R                  S9$ )N)fmttzinfo)r   FormatDateTimeSEEK_TIME_FORMATUTC)times    r   FormatSeekTimer      s    			d(8	KKr   c                 4    [         R                  " U 5      S-   $ )zFormats a duration argument to be a string with units.

Args:
  duration (int): The duration in seconds.
Returns:
  unicode: The formatted duration.
s)six	text_type)durations    r   FormatDurationr      s     
x	 3	&&r   c                 
   U=(       d    [         R                  " 5       n/ nU (       a[  [        [        R                  " U 5      5       H8  u  p4UR                  UR                  R                  R                  UUS95        M:     U$ )a  Parses attribute_dict into a list of AdditionalProperty messages.

Args:
  attribute_dict (Optional[dict]): Dict containing key=value pairs
    to parse.
  messages (Optional[module]): Module containing pubsub proto messages.
Returns:
  list: List of AdditionalProperty messages.
)keyvalue)	r   GetMessagesModulesortedr   	iteritemsappendPubsubMessageAttributesValueAdditionalProperty)attribute_dictrq   
attributesr   r   s        r   ParseAttributesr      su     3113(*S]]>:;


 
 
0
0
C
C D  <
 
r   c                 V    [         R                  " U 5      nU R                  US'   US	 U$ )zCreates a serializable from a Cloud Pub/Sub Topic operation for display.

Args:
  topic: (Cloud Pub/Sub Topic) Topic to be serialized.
Returns:
  A serialized object representing a Cloud Pub/Sub Topic
  operation (create, delete).
r\   rO   )r
   MakeSerializablerO   )r]   topic_display_dicts     r   TopicDisplayDictr      s2     *::5A"'**Y 	r   c           	      2   SnSnU R                   (       a3  U R                   R                  (       a  U R                   R                  nSnU R                  U R                  UUU R                  [        U R                  5      U R                  U R                  S.$ )a  Creates a serializable from a Cloud Pub/Sub Subscription op for display.

Args:
  subscription: (Cloud Pub/Sub Subscription) Subscription to be serialized.
Returns:
  A serialized object representing a Cloud Pub/Sub Subscription
  operation (create, delete, update).
 pullpush)rV   r]   typerg   ackDeadlineSecondsretainAckedMessagesmessageRetentionDurationenableExactlyOnceDelivery)	
pushConfigrg   rO   r]   r   boolr   r   r   )rY   rj   subscription_types      r   SubscriptionDisplayDictr      s     -++"--::m  %))!!#(;;!,"B"BC"."G"G#/#I#I	
 	r   c                 J    U R                   U R                  U R                  S.$ )zCreates a serializable from a Cloud Pub/Sub Snapshot operation for display.

Args:
  snapshot: (Cloud Pub/Sub Snapshot) Snapshot to be serialized.

Returns:
  A serialized object representing a Cloud Pub/Sub Snapshot operation (create,
  delete).
)
snapshotIdr]   
expireTime)rO   r]   r   )rS   s    r   SnapshotDisplayDictr     s%     MM~~''
 r   c                 $   [         R                  " U 5      nU R                  R                  (       a  SOSUS'   [	        U R
                  5      nUR                  US'   UR                  US'   [        U R                  5      nUR                  US'   U$ )z3Returns a subscription dict with additional fields.PUSHPULLr   rW   rV   r\   )r
   r   r   rg   r=   rO   r/   subscriptionsIdrA   r]   topicsId)rY   resultsubscription_ref
topic_infos       r   ListSubscriptionDisplayDictr   ,  s    ..|<&)44AA6v&.&|'8'89(33&-==&	,,,-* ))&	-r   c                     [         R                  " U 5      n[        U R                  5      nU R                  US'   UR                  US'   US	 U$ )Nr]   r\   rO   )r
   r   rA   rO   r   )r]   
topic_dict	topic_refs      r   ListTopicDisplayDictr   8  sL    !2259*$)

*W#,,*Y	r   c                     [         R                  " SU 05      n[        U 5      nUR                  US'   UR                  US'   U$ )z9Returns a topic_subscription dict with additional fields.rY   rW   rV   )r
   r   r=   r/   r   )topic_subscriptionr   r   s      r    ListTopicSubscriptionDisplayDictr   A  sO    ..)*,& ''9:(33&-==&		-r   c                     [         R                  " U 5      n[        U R                  5      nUR                  US'   UR
                  US'   [        U R                  5      nUR                  US'   U R                  US'   U$ )z/Returns a snapshot dict with additional fields.rW   r   r\   r   )
r
   r   r9   rO   r/   snapshotsIdrA   r]   r   r   )rS   r   snapshot_refr   s       r   ListSnapshotDisplayDictr   L  ss    ..x8&x}}-,$//&%11&()((&!,,&	-r   c                  d    [         R                  R                  R                  R	                  SS9$ )zReturns the value of the core/project config property.

Config properties can be overridden with command line flags. If the --project
flag was provided, this will return the value provided with the flag.
TrG   rI   r   r   r   
GetProjectr   X  s*     
					'	'	+	+T	+	::r   c                 h    [         R                  R                  U S[        0SS9R	                  5       $ )zParses a schema name using configuration properties for fallback.

Args:
  schema: str, the schema's ID, fully-qualified URL, or relative name

Returns:
  str: the relative name of the schema resource
r/   r   r0   )r	   r4   r5   r   RelativeName)schemas    r   ParseSchemaNamer   a  s;     
			!	!

- 
" 
/ 0<|~>r   c                 B    [         R                  R                  S5        g)z1Logs a message indicating that a schema is valid.zSchema is valid.Nr   statusPrintunused_responseunused_argss     r   OutputSchemaValidatedr   p  s    **%&r   c                 B    [         R                  R                  S5        g)z2Logs a message indicating that a message is valid.zMessage is valid.Nr   r   s     r   OutputMessageValidatedr   u  s    **&'r   c                 v    U  Vs/ s H  o"S   PM	     nnU Vs/ s H  oDU;  d  M
  UPM     nnX54$ s  snf s  snf )NAckIdr   )ack_ids_and_failure_reasonsack_idsackfailed_ack_idsack_idsuccessfully_processed_ack_idss         r   'ParseExactlyOnceAckIdsAndFailureReasonsr   z  sQ    ,GH,GSL,G.H"$"N&Bf7 ! $ 
	77	 I$s   1	66c                     [         R                  " U 5      n[        UR                  R                  5      nU(       d  U eU$ r)   )excHttpExceptionParseExactlyOnceErrorInfopayloaddetails)errorer   s      r   HandleExactlyOnceDeliveryErrorr     s7    	! 9!)):K:K L 
%
K	$$r   c                 0   / nU  H  nSU;  d	  SUS   ;  a  M  SU;  d  [        US   [        5      (       d  M4  US   R                  5        HB  u  p4SU;   d  SU;   d  M  [        R                  " 0 5      nX5S'   XES'   UR                  U5        MD     M     U$ )zParses error metadata for exactly once ack/modAck failures.

Args:
  error_metadata: error metadata as dict of format ack_id -> failure_reason.

Returns:
  list: error metadata with only exactly once failures.
reasonEXACTLY_ONCEmetadataPERMANENT_FAILURETEMPORARY_FAILUREr   FailureReason)rP   rQ   itemsr
   r   r   )error_metadatar   error_mdr   failure_reasonr   s         r   r   r     s     !# hx>(9K#K!HZ4H$)O)O"*:"6"<"<">		.3F6D4E#44R8 w"0#**62 #? ! 
%$r   )zInternal Error)r   r)   )Ar   googlecloudsdk.api_lib.pubsubr   r   googlecloudsdk.api_lib.utilr   r   #googlecloudsdk.command_lib.projectsr   rC   googlecloudsdk.corer   r   r	   googlecloudsdk.core.resourcer
   googlecloudsdk.core.utilr   r   r   r?   TOPICS_PUBLISH_COLLECTIONr6   SNAPSHOTS_LIST_COLLECTIONr;   SUBSCRIPTIONS_ACK_COLLECTIONSUBSCRIPTIONS_LIST_COLLECTION SUBSCRIPTIONS_MOD_ACK_COLLECTION#SUBSCRIPTIONS_MOD_CONFIG_COLLECTIONSUBSCRIPTIONS_PULL_COLLECTIONSUBSCRIPTIONS_SEEK_COLLECTIONSCHEMAS_COLLECTIONrn   rm   Errorr   r   r,   r9   r=   rA   rD   r3   rT   rZ   r^   r{   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      sM    @ 8 0 9 E * # * ) ; * 
 +  - 3 2 3 : 9  ; #A  &G # ;  ; . 6 2	; 7-:++ -9*** 9 '7CCG@0
I(	5%/Nd1L', 8"		;>'
(
8%%r   