
    %                     V   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  \	R                  \	R                  " \	R                   R"                  \	R                   R$                  \	R                   R&                  5       " S
 S\	R(                  5      5       5       rg)z'logging sinks create' command.    )absolute_import)division)unicode_literals)util)arg_parsers)base)log)
console_ioc                   @    \ rS rSrSr\S 5       rS rS rS r	S r
Srg	)
Create   aP  Create a log sink.

Create a log sink used to route log entries to a destination. The sink routes
all log entries that match its *--log-filter* flag.

An empty filter matches all logs.

Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/logging-query-language)

The sink's destination can be a Cloud Logging log bucket, a Cloud Storage
bucket, a BigQuery dataset, a Cloud Pub/Sub topic, or a Google Cloud project.

The destination must already exist.

If creating a log sink to route logs to a destination outside of Cloud Logging
or to a Cloud Logging log bucket in another project, the log sink's service
account must be granted permission to write to the destination.

For more information about destination permissions, see:
https://cloud.google.com/logging/docs/export/configure_export_v2#dest-auth

Matching log entries are routed to the destination after the sink is created.

## EXAMPLES

To route all Google Compute Engine logs to BigQuery, run:

  $ {command} my-bq-sink
  bigquery.googleapis.com/projects/my-project/datasets/my_dataset --log-filter='resource.type="gce_instance"'

To route "syslog" from App Engine Flexible to a Cloud Storage bucket, run:

  $ {command} my-gcs-sink storage.googleapis.com/my-bucket --log-filter='logName="projects/my-project/appengine.googleapis.com%2Fsyslog"'

To route Google App Engine logs with ERROR severity, run:

  $ {command} my-error-logs
  bigquery.googleapis.com/projects/my-project/datasets/my_dataset --log-filter='resource.type="gae_app" AND severity=ERROR'

To route all logs to a log bucket in a different project, run:

  $ {command} my-sink
  logging.googleapis.com/projects/my-central-project/locations/global/buckets/my-central-bucket

To route all logs to another project, run:

  $ {command} my-sink
  logging.googleapis.com/projects/my-destination-project
c                 V   U R                  SSS9  U R                  S[        R                  " SSS9S9  U R                  S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  U R                  SS9nUR                  SS	SSS9  U R                  SS[        R                  " [
        [
        [
        [        S.SS/S9SS 9  U R                  S!S"S9  U R                  S#SS$S%9  [        R                  " U S&5        U R                  R                  S'5        g')(z Register flags for this command.	sink_namezThe name for the sink.)helpdestinationzThe destination for the sink.z*Some destination types are not supported
.)defaultuniverse_helpz--log-filterFz_A filter expression for the sink. If present, the filter specifies which log entries to export.)requiredr   z--include-children
store_truezpWhether to export logs from all child projects and folders. Only applies to sinks for organizations and folders.)r   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-Settings for sink exporting data to BigQuery.z--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.z--exclusionappend)namedescriptionfilterdisabledr   r   )specrequired_keysaD  Specify an exclusion filter for a log entry that is not to be exported. This flag can be repeated.

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

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

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

*filter*::: An advanced log filter that matches the log entries to be excluded.

*disabled*::: If this exclusion should be disabled and not exclude the log entries.)r   typer   z--descriptionzDescription of the sink.z
--disabledz9Sink will be disabled. Disabled sinks do not export logs.)r   r   zsink to createN)add_argumentr   UniverseHelpTextadd_argument_groupArgDictstrboolr   AddParentArgsdisplay_infoAddCacheUpdater)parserbigquery_groups     #lib/surface/logging/sinks/create.pyArgsCreate.ArgsV   s    *BC
))3G
   7  9
 E	  G C   "'	  	 ..< / >N";	   	=   " 	 "8,.)  +0 .HI
I  L
 	v/0
''-    c           
          [         R                  " 5       n[         R                  " 5       R                  R	                  UR                  UUR                  " S0 UD6SUS95      $ )z-Creates a v2 sink specified by the arguments.T)parentlogSinkuniqueWriterIdentitycustomWriterIdentity )r   GetMessages	GetClientprojects_sinksr   !LoggingProjectsSinksCreateRequestLogSink)selfr1   	sink_datacustom_writer_identitymessagess        r,   
CreateSinkCreate.CreateSink   s]    !H>>**1122$$1y1!%!7	 	3 	9: :r/   c                    UR                   (       d  [        R                  " SSS9  UR                  (       d_  UR                  (       dN  UR
                  (       a  [        R                  " S5        UR                  (       a  [        R                  " S5        [        R                  " UR                  U5      nUR                  UR                  S.nUR                  S5      (       a  UR
                  US'   UR                  S	5      (       a  UR                  US
'   UR                  S5      (       a  UR                   US'   UR                  S5      (       a  0 nUR                  US'   XCS'   UR                  S5      (       a  UR                   US'   UR                  S5      (       a  UR"                  US'   UR                  S5      (       a  UR$                  US'   S nUR                  S5      (       a  UR&                  nU R)                  [        R*                  " U5      X55      n[        R,                  " U5        UR                  U l        UR0                  U l        U$ )Nz+Sink with empty filter matches all entries.T)cancel_on_nozQinclude-children only has an effect for sinks at the folder or organization levelzSintercept-children only has an effect for sinks at the folder or organization level)r   r   include_childrenincludeChildrenintercept_childreninterceptChildren
log_filterr   use_partitioned_tablesusePartitionedTablesbigqueryOptions	exclusion
exclusionsr   r   r=   )rG   r
   PromptContinueorganizationfolderrC   r	   warningrE   r   GetSinkReferencer   sinksIdr   IsSpecifiedrH   rK   r   r   r=   r?   GetParentFromArgsCreatedResource_epilog_result_destinationwriterIdentity_epilog_writer_identity)r;   argssink_refr<   bigquery_optionsr=   results          r,   _RunCreate._Run   s   ??
7dL 			$	
 
	 	 $	

 $$T^^T:H   ''I
 *++%)%:%:i!",--'+'>'>i#$%% OOi011151L1L-.%5!"$$ $i&&!%!1!1i
##"mmi
!011#::__t$iIF !&,&8&8D##)#8#8D Mr/   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 created sink with its destination.
)r]   )r;   rY   s     r,   Run
Create.Run   s     99T?r/   c                 Z    [         R                  " U R                  U R                  5        g )N)r   PrintPermissionInstructionsrV   rX   )r;   unused_resources_were_displayeds     r,   EpilogCreate.Epilog   s"    $$T%D%D%)%A%ACr/   )rV   rX   N)__name__
__module____qualname____firstlineno____doc__staticmethodr-   r?   r]   r`   re   __static_attributes__r5   r/   r,   r   r      s5    1h T. T.l:9v
Cr/   r   N)rk   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   r   googlecloudsdk.corer	   googlecloudsdk.core.consoler
   UniverseCompatibleReleaseTracksReleaseTrackGABETAALPHACreateCommandr   r5   r/   r,   <module>rz      s    & &  ' / / ( # 2 $++00$2C2C2I2I`CT `C `Cr/   