
    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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\	RL                  5      r' " S  S!\	RL                  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) r0S* r1S@S+ jr2S, r3S- r4S. r5S@S/ jr6S0 r7S1 r8S2 r9S3 r:S4 r;S5 r<S6 r=S7 r>S8 r?S9 r@S: rAS; rBS< rCS= rDg)Az9A library that is used to support Cloud Pub/Sub commands.    )absolute_import)division)unicode_literals)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)InvalidArgumentErrorJ   z$The user provides invalid arguments. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       -lib/googlecloudsdk/command_lib/pubsub/util.pyr   r   J   s    ,r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )RequestsFailedErrorN   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__Q   s5    	
t-9@@CHHX$6 	A 	89r   r   )r   r   r   r   r   r$   r   __classcell__)r(   s   @r   r   r   N   s    <9 9r   r   c                     U (       a  U $ U$ Nr   )original_messagedefault_messages     r   CreateFailureErrorMessager/   W   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   ParseSnapshotr<   ]   s9    :&*				!	!-*6
)C-A 
" 
C Cr   c                 b    [        U5      n[        R                  R                  U SU0[        S9$ r1   )r6   r   r7   r8   SUBSCRIPTIONS_COLLECTION)subscription_namer;   s     r   ParseSubscriptionr@   d   s:    :&*				!	!"3*6
)C-E 
" 
G Gr   c                 b    [        U5      n[        R                  R                  U SU0[        S9$ r1   )r6   r   r7   r8   TOPICS_COLLECTION)
topic_namer;   s     r   
ParseTopicrD   k   s9    :&*				!	!**6
)C-> 
" 
@ @r   c                 D    [        U 5      n [        R                  " U 5      $ r,   )r6   projects_utilParseProjectr;   s    r   rG   rG   r   s    :&*		#	#J	//r   c                 v    U =(       d1    [         R                  R                  R                  R	                  SS9$ )NTrequiredr   VALUEScoreprojectGetrH   s    r   r6   r6   w   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dictr<   SelfLink)snapshotrR   s     r   SnapshotUriFuncrW   {   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)rS   rT   strrR   r@   rU   )subscriptionrO   rR   s      r   SubscriptionUriFuncr]      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)rS   rT   rR   rD   rU   )topicrR   s     r   TopicUriFuncra      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)re   rc   rd   )rc   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clientrm   service_account_emailrg   
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)rn   )rx   s    r   rr   rr      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_dictrt   
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_   rR   )r   MakeSerializablerR   )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)rY   r`   typerj   ackDeadlineSecondsretainAckedMessagesmessageRetentionDurationenableExactlyOnceDelivery)	
pushConfigrj   rR   r`   r   boolr   r   r   )r\   rm   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)rR   r`   r   )rV   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   rZ   rY   r_   )r   r   r   rj   r@   rR   r2   subscriptionsIdrD   r`   topicsId)r\   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_   rR   )r   r   rD   rR   r   )r`   
topic_dict	topic_refs      r   ListTopicDisplayDictr   ;  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.r\   rZ   rY   )r   r   r@   r2   r   )topic_subscriptionr   r   s      r    ListTopicSubscriptionDisplayDictr   D  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.rZ   r   r_   r   )
r   r   r<   rR   r2   snapshotsIdrD   r`   r   r   )rV   r   snapshot_refr   s       r   ListSnapshotDisplayDictr   O  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.
TrJ   rL   r   r   r   
GetProjectr   [  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
r2   r   r3   )r   r7   r8   r   RelativeName)schemas    r   ParseSchemaNamer   d  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   s  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   x  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   }  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)rS   rT   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,   )Er   
__future__r   r   r   googlecloudsdk.api_lib.pubsubr   r   googlecloudsdk.api_lib.utilr   r   #googlecloudsdk.command_lib.projectsr	   rF   googlecloudsdk.corer
   r   r   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   r   r   rB   TOPICS_PUBLISH_COLLECTIONr9   SNAPSHOTS_LIST_COLLECTIONr>   SUBSCRIPTIONS_ACK_COLLECTIONSUBSCRIPTIONS_LIST_COLLECTION SUBSCRIPTIONS_MOD_ACK_COLLECTION#SUBSCRIPTIONS_MOD_CONFIG_COLLECTIONSUBSCRIPTIONS_PULL_COLLECTIONSUBSCRIPTIONS_SEEK_COLLECTIONSCHEMAS_COLLECTIONrq   rp   Errorr   r   r/   r<   r@   rD   rG   r6   rW   r]   ra   r~   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r     sT    @ &  ' 7 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   