
    K6                     b   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  \	R                   \	R"                  " \	R$                  R&                  \	R$                  R(                  \	R$                  R*                  5       " S S\	R,                  5      5       5       rg)z'logging sinks update' command.    )absolute_import)division)unicode_literals)util)arg_parsers)base)
exceptions)log)
console_ioc                   F    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	rg
)Update   a  Update a sink.

Change the *[DESTINATION]* or *--log-filter* associated with a sink.
The new destination must already exist and Cloud Logging must have
permission to write to it.

Log entries are exported to the new destination immediately.

## EXAMPLES

To only update a sink filter, run:

  $ {command} my-sink --log-filter='severity>=ERROR'

Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/logging-query-language)
c                     U R                  SSS9  U R                  SS[        R                  " SSS9S	9  U R                  S
SS9  U R                  SSSSS9  U R                  SSSSS9  U R                  SSSS9  [        R                  " U S5        U R                  SS9nUR                  SSSS9  U R                  SSSS9  U R                  S[        R                  " 5       SS S!9  U R                  S"S#[        R                  " [        [        [        [        S$.S%S&/S'9S(S)9  U R                  S*S#[        R                  " [        [        [        [        S$.S%/S'9S+S)9  U R                  S,S-S9  U R                  S.SS/S9  g0)1z Register flags for this command.	sink_namezThe name of the sink to update.)helpdestination?zYA new destination for the sink. If omitted, the sink's existing destination is unchanged.z*Some destination types are not supported
.)defaultuniverse_help)nargsr   --log-filterzcA new filter expression for the sink. If omitted, the sink's existing filter (if any) is unchanged.z--include-childrenF
store_truezpWhether to export logs from all child projects and folders. Only applies to sinks for organizations and folders.)requiredactionr   z--intercept-childrenzsWhether to intercept logs from all child projects and folders. Only applies to sinks for organizations and folders.z--custom-writer-identitySERVICE_ACCOUNT_EMAILzWriter identity for the sink. This flag can only be used if the destination is a log bucket in a different project. The writer identity is automatically generated when it is not provided for a sink.)metavarr   zsink to updatez-Settings for sink exporting data to BigQuery.--use-partitioned-tablesa(  If specified, use BigQuery's partitioned tables. By default, Logging creates dated tables based on the log entries' timestamps, e.g. 'syslog_20170523'. Partitioned tables remove the suffix and special query syntax (https://cloud.google.com/bigquery/docs/querying-partitioned-tables) must be used.)r   r   --clear-exclusionsz,Remove all logging exclusions from the sink.--remove-exclusionszEXCLUSION IDz7Specify the name of the Logging exclusion(s) to delete.)typer   r   z--add-exclusionappend)namefilterdescriptiondisabledr"   r#   )specrequired_keysa  Add an exclusion filter for log entries that are not to be routed to the sink' destination. This flag can be repeated.

The ``name'' and ``filter'' attributes are required. The following keys are accepted:

*name*::: Required. An identifier, such as ``load-balancer-exclusion''. Identifiers are limited to 100 characters and can include only letters, digits, underscores, hyphens, and periods.

*description*::: Optional. A description of this exclusion.

*filter*::: Required. Entries that match this advanced log filter will be excluded. Filter cannot be empty.

*disabled*::: Optional. By default, an exclusion is not disabled. To disable an exclusion, include this key and specify any value.

)r   r    r   --update-exclusiona  Update an exclusion filter for a log entry that is not to be exported. This flag can be repeated.

The ``name'' attribute is required. The following keys are accepted:

*name*::: Required. An identifier, such as ``load-balancer-exclusion''. Identifiers are limited to 100 characters and can include only letters, digits, underscores, hyphens, and periods.

*description*::: Optional. A description of this exclusion.

*filter*::: Optional. Entries that match this advanced log filter will be excluded. Filter cannot be empty.

*disabled*::: Optional. To disable an exclusion, include this key and specify any value. To enable a disabled exclusion, include this key, but do not specify any value. Do not include this key unless you want to change its value.

z--descriptionzDescription of the sink.z
--disabledzDisable the sink. Disabled sinks do not route logs to the sink destination. Specify --no-disabled to enable a disabled sink. If this flag is not specified, the value will not be updated.N)
add_argumentr   UniverseHelpTextr   AddParentArgsadd_argument_groupArgListArgDictstrbool)parserbigquery_groups     #lib/surface/logging/sinks/update.pyArgsUpdate.Args4   s*    *KL
))6 H
  
 O  Q C   C   "'	  	 	v/0..< / >N";   = <  ?   "G	  J
   " 	 "8,.  !4   " 	 "($B  D6 .HI
N  P    c           	          [         R                  " 5       R                  R                  [         R                  " 5       R                  [         R                  " USUR                  5      S95      $ )z*Returns a sink specified by the arguments.sinks)sinkName)r   	GetClientprojects_sinksGetGetMessagesLoggingProjectsSinksGetRequestCreateResourceNamesinksId)selfparentsink_refs      r3   GetSinkUpdate.GetSink   s\    >>**..99,,VW-5-=-=? 	: 	@A Ar6   c           
         [         R                  " 5       n[         R                  " 5       R                  R	                  UR                  [         R                  " USUS   5      UR                  " S0 UD6SSR                  U5      US95      $ )z*Patches a sink specified by the arguments.r8   r"   T,)r9   logSinkuniqueWriterIdentity
updateMaskcustomWriterIdentity )	r   r=   r:   r;   Patch LoggingProjectsSinksPatchRequestr?   LogSinkjoin)rA   rB   	sink_dataupdate_maskcustom_writer_identitymessagess         r3   	PatchSinkUpdate.PatchSink   s    !H>>**0011,,VW-6v->@$$1y1!%xx,!7 	2 	9: :r6   c                    [         R                  " UR                  U5      nU R                  [         R                  " U5      U5      nSUR
                  0n/ nUR                  S5      (       a   UR                  US'   UR                  S5        UR                  S5      (       ai  UR                  US'   UR                  S5        UR                  (       a8  UR                  (       d'  UR                  (       d  [        R                  " S5        UR                  S5      (       ai  UR                  US'   UR                  S5        UR                  (       a8  UR                  (       d'  UR                  (       d  [        R                  " S5        UR                  S	5      (       a   UR                  US
'   UR                  S
5        SS/nUR!                  SS/5        UR                  S5      (       a&  0 nUR"                  US'   XtS'   UR                  S5        UR                  S5      (       a   UR$                  US'   UR                  S5        UR                  S5      (       a   UR&                  US'   UR                  S5        UR                  S5      (       dC  UR                  S5      (       d-  UR                  S5      (       d  UR                  S5      (       Ga	  / US'   UR                  S5        UR                  S5      (       a  UR(                  O/ nUR                  S5      (       a  UR*                  O/ n	UR,                   H  n
U
R.                  U;   a  UR1                  U
R.                  5        M0  [3        [5        U	5      5       Hl  nU
R.                  X   S   :X  d  M  X   R7                  5        H+  u  pUS:X  a  Xl        US
:X  a  Xl        US:X  d  M%  Xl        M-     U	R;                  U5          O   US   R                  U
5        M     U(       a5  [<        R>                  " SSRA                  SRC                  U5      5      5      eU	(       aH  [<        R>                  " SSRA                  SRC                  U	 V
s/ s H  oS   PM	     sn
5      5      5      eUR                  S5      (       a  / US'   UR                  S5      (       a  US==   URD                  -  ss'   S nUR                  S5      (       a  URF                  nUR!                  S/5        U(       d  [<        RH                  " US 5      eURJ                  (       a&  S!URJ                  ;   a  [L        RN                  " S"S#S$S%9  U RQ                  [         R                  " U5      XEU5      n[        RR                  " U5        UR                  S5      (       a"  UR                  U l*        URJ                  U l+        U$ s  sn
f )&Nr"   r   include_childrenincludeChildrenzQinclude-children only has an effect for sinks at the folder or organization levelintercept_childreninterceptChildrenzSintercept-children only has an effect for sinks at the folder or organization level
log_filterr#   z[destination]r   r   r   use_partitioned_tablesusePartitionedTablesbigqueryOptionsz'bigquery_options.use_partitioned_tablesr$   r%   clear_exclusionsremove_exclusionsadd_exclusionupdate_exclusion
exclusionsr   zExclusions {0} do not existrG   r(   rS   z--custom_writer_identityz.Please specify at least one property to updatezcloud-logs@a  This update will create a new writerIdentity (service account) for the sink. In order for the sink to continue working, grant that service account correct permission on the destination. The service account will be displayed after a successful update operation.TF)cancel_on_nor   ),r   GetSinkReferencer   rD   GetParentFromArgsr@   IsSpecifiedr   r!   rX   organizationfolderr
   warningrZ   r\   extendr]   r$   r%   ra   rc   rd   r"   removerangelenitemsr#   popcalliope_exceptionsInvalidArgumentExceptionformatrP   rb   rS   MinimumArgumentExceptionwriterIdentityr   PromptContinuerU   UpdatedResource_epilog_result_destination_epilog_writer_identity)rA   argsrC   sinkrQ   rR   parameter_namesbigquery_optionsexclusions_to_removeexclusions_to_update	exclusionikeyvaluerS   results                   r3   _RunUpdate._Run   sB   $$T^^T:H<<..t4h?D))*IK&&!%!1!1i'*++%)%:%:i!"+,			(9(9T[[$	

 ,--'+'>'>i#$-.		 	 $*;*;t{{$	

 %% OOi"&7O68LMN011151L1L-.%5!"BC&&!%!1!1i'
##"mmi
$+,,,--))+,, "i& 122 
 
 8:  $(#3#34F#G#G$

R )>>11

%
%inn
5123a~~!5!8!@@ 4 7 = = ?*#-'*/'(?%*"*$',$ !@ #&&q) 4 L
!
(
(
3 '" 
!::!#@#G#G-.$01 	1 
!:: "?"F"Fsxx4HI4Hy6"4HIHK #LM 	M 
		,	-	-"$	,			/	*	*,4#5#55!011#::89:88
KM M
 }0C0CCK  ^^t$i F !&&(.(:(:d%%+%:%:d"MI Js   >W%c                 $    U R                  U5      $ )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 sink with its new destination.
)r   )rA   r{   s     r3   Run
Update.RunG  s     99T?r6   c                 ~    [        U S5      (       a,  [        R                  " U R                  U R                  5        g g )Nry   )hasattrr   PrintPermissionInstructionsry   rz   )rA   unused_resources_were_displayeds     r3   EpilogUpdate.EpilogS  s5    t122
&&t'F'F'+'C'CE 3r6   )ry   rz   N)__name__
__module____qualname____firstlineno____doc__staticmethodr4   rD   rU   r   r   r   __static_attributes__rL   r6   r3   r   r      s=    
$ AP APFA
:zx
Er6   r   N)r   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   r   r	   rr   googlecloudsdk.corer
   googlecloudsdk.core.consoler   UniverseCompatibleReleaseTracksReleaseTrackGABETAALPHAUpdateCommandr   rL   r6   r3   <module>r      s    & &  ' / / ( E # 2 $++00$2C2C2I2IuET uE uEr6   