o
    gZhSW                     @   sH   d dl Zd dlmZ ddlmZ ddlmZmZm	Z	 G dd deZ
dS )    N)ObjectApiResponse   )NamespacedClient)SKIP_IN_PATH_quote_rewrite_parametersc                %   @   s  e Zd Ze dddddddedejejeeje f  deje	 dejejeeje f  deje	 deje	 d	e
ej fd
dZe ddddddedeje	 dejejeeje f  deje	 deje	 d	e
ej fddZe ddddddedeje	 dejejeeje f  deje	 deje	 d	e
ej fddZe ddddddedeje	 dejejeeje f  deje	 deje	 d	e
ej fddZedddddddddddddddddeje dejejeejdef f  dejejeejf  deje	 deje	 dejejeeje f  deje	 deje	 deje	 deje	 dejejeejf  dejejeejf  dejejeejf  d	e
ej fd d!Ze ddddddedeje	 dejejeeje f  deje	 deje	 d	e
ej fd"d#Zedddddddddddddddddd$ded%ejejeejeejf f  d&eje	 d'ejejeejf  deje	 dejejeeje f  deje	 d(eje d)eje d*ejejeejf  d+ejejeejf  deje	 d,eje d-ejejeejf  d.ejejeejf  d/eje d	e
ej f"d0d1Zedd2d3id4dddddddddd5	deje	 dejejeeje f  d3eje deje	 deje	 d6ejejeejf  d7ejejejde	eeeejf   d8eje d9ejejejejeejeejf f  ejeejeejf f f  d	e
ej fd:d;Ze ddddddeje	 dejejeeje f  deje	 deje	 d	e
ej f
d<d=Ze ddddddd>d?ejejejejd@ef  ejd@ef f  dAeje	 deje	 dejejeeje f  deje	 deje	 d	e
ej fdBdCZe ddddddeje	 dejejeeje f  deje	 deje	 d	e
ej f
dDdEZdS )FWatcherClientN)	action_iderror_tracefilter_pathhumanprettywatch_idr	   r
   r   r   r   returnc          
      C   s   |t v rtd|t vr|t vrdt| dt| }n|t vr*dt| d}ntdi }|dur8||d< |dur@||d< |durH||d	< |durP||d
< ddi}	| jd|||	dS )a9  
        Acknowledges a watch, manually throttling the execution of the watch's actions.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-ack-watch.html>`_

        :param watch_id: Watch ID
        :param action_id: A comma-separated list of the action ids to be acked
        +Empty value passed for parameter 'watch_id'/_watcher/watch/z/_ack/z/_ackz-Couldn't find a path for the given parametersNr
   r   r   r   acceptapplication/jsonPUTparamsheadersr   
ValueErrorr   perform_request)
selfr   r	   r
   r   r   r   _WatcherClient__path_WatcherClient__query_WatcherClient__headers r   Y/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/watcher.py	ack_watch   s(   zWatcherClient.ack_watch)r
   r   r   r   c          	      C   ~   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< d	d
i}| jd|||dS )z
        Activates a currently inactive watch.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-activate-watch.html>`_

        :param watch_id: Watch ID
        r   r   z
/_activateNr
   r   r   r   r   r   r   r   r   	r   r   r
   r   r   r   r   r   r   r   r   r    activate_watchD       zWatcherClient.activate_watchc          	      C   r"   )z
        Deactivates a currently active watch.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-deactivate-watch.html>`_

        :param watch_id: Watch ID
        r   r   z/_deactivateNr
   r   r   r   r   r   r   r   r   r#   r   r   r    deactivate_watchf   r%   zWatcherClient.deactivate_watchidc          	      C   |   |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< dd	i}| jd
|||dS )z
        Removes a watch from Watcher.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-delete-watch.html>`_

        :param id: Watch ID
        %Empty value passed for parameter 'id'r   Nr
   r   r   r   r   r   DELETEr   r   	r   r'   r
   r   r   r   r   r   r   r   r   r    delete_watch       zWatcherClient.delete_watchT)body_fields)r'   action_modesalternative_inputdebugr
   r   r   ignore_conditionr   record_executionsimulated_actionstrigger_datawatchr/   zKt.Literal['execute', 'force_execute', 'force_simulate', 'simulate', 'skip']r0   r1   r2   r3   r4   r5   r6   c                C   s  |t vrdt| d}nd}i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d	< |durC||d
< |durK||d< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< |durs||d< |swd}ddi}|durd|d< | jd||||dS )a  
        Forces the execution of a stored watch.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-execute-watch.html>`_

        :param id: Identifier for the watch.
        :param action_modes: Determines how to handle the watch actions as part of the
            watch execution.
        :param alternative_input: When present, the watch uses this object as a payload
            instead of executing its own input.
        :param debug: Defines whether the watch runs in debug mode.
        :param ignore_condition: When set to `true`, the watch execution uses the always
            condition. This can also be specified as an HTTP parameter.
        :param record_execution: When set to `true`, the watch record representing the
            watch execution result is persisted to the `.watcher-history` index for the
            current time. In addition, the status of the watch is updated, possibly throttling
            subsequent executions. This can also be specified as an HTTP parameter.
        :param simulated_actions:
        :param trigger_data: This structure is parsed as the data of the trigger event
            that will be used during the watch execution
        :param watch: When present, this watch is used instead of the one specified in
            the request. This watch is not persisted to the index and record_execution
            cannot be set.
        r   z	/_executez/_watcher/watch/_executeNr/   r0   r1   r
   r   r   r2   r   r3   r4   r5   r6   r   r   content-typer   r   r   bodyr   r   r   )r   r'   r/   r0   r1   r
   r   r   r2   r   r3   r4   r5   r6   r   _WatcherClient__bodyr   r   r   r   r    execute_watch   sJ   4
zWatcherClient.execute_watchc          	      C   r(   )z
        Retrieves a watch by its ID.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-get-watch.html>`_

        :param id: Watch ID
        r)   r   Nr
   r   r   r   r   r   GETr   r   r+   r   r   r    	get_watch  r-   zWatcherClient.get_watch)actionsactive	conditionr
   r   r   if_primary_term	if_seq_noinputmetadatar   throttle_period	transformtriggerversionr?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   c                C   sJ  |t v rtddt| }i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< |durs||d< |dur{||d< |dur||d< |dur||d< |sd}ddi}|durd|d< | jd||||dS )a*  
        Creates a new watch, or updates an existing one.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-put-watch.html>`_

        :param id: Watch ID
        :param actions:
        :param active: Specify whether the watch is in/active by default
        :param condition:
        :param if_primary_term: only update the watch if the last operation that has
            changed the watch has the specified primary term
        :param if_seq_no: only update the watch if the last operation that has changed
            the watch has the specified sequence number
        :param input:
        :param metadata:
        :param throttle_period:
        :param transform:
        :param trigger:
        :param version: Explicit version number for concurrency control
        r)   r   Nr?   r@   rA   r
   r   r   rB   rC   rD   rE   r   rF   rG   rH   rI   r   r   r7   r   r8   r   )r   r'   r?   r@   rA   r
   r   r   rB   rC   rD   rE   r   rF   rG   rH   rI   r   r;   r   r   r   r   r    	put_watch'  sV   +
zWatcherClient.put_watchfromfrom_)r.   Zparameter_aliases)	r
   r   rL   r   r   querysearch_aftersizesortrM   rN   rO   rP   c       	         C   s(  d}
i }i }|	dur2t |	trd|	v s,t |	ttfr2tdd |	D r2tdd |	D r2|	|d< d}	|dur:||d< |durB||d	< |durJ||d
< |durR||d< |durZ||d< |durb||d< |durj||d< |durr||d< |	durz|	|d< |s~d}ddi}|durd|d< | jd|
|||dS )u"  
        Retrieves stored watches.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-query-watches.html>`_

        :param from_: The offset from the first result to fetch. Needs to be non-negative.
        :param query: Optional, query filter watches to be returned.
        :param search_after: Optional search After to do pagination using last hit’s
            sort values.
        :param size: The number of hits to return. Needs to be non-negative.
        :param sort: Optional sort definition.
        z/_watcher/_query/watchesN:c                 s   s    | ]}t |tV  qd S )N)
isinstancestr.0Z_xr   r   r    	<genexpr>  s    z.WatcherClient.query_watches.<locals>.<genexpr>c                 s   s    | ]}d |v V  qdS )rQ   Nr   rT   r   r   r    rV     s    rP   r
   r   rK   r   r   rM   rN   rO   r   r   r7   POSTr8   )rR   rS   listtupleallanyr   )r   r
   r   rL   r   r   rM   rN   rO   rP   r   r   r;   r   r   r   r    query_watches~  sR   $
zWatcherClient.query_watchesc                C   b   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< ddi}| j d	|||d
S )z
        Starts Watcher if it is not already running.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-start.html>`_
        z/_watcher/_startNr
   r   r   r   r   r   rW   r   r   r   r
   r   r   r   r   r   r   r   r   r    start     zWatcherClient.start)metricemit_stacktracesr
   r   r   r   rb   zIt.Literal['_all', 'current_watches', 'pending_watches', 'queued_watches']rc   c          
      C   s   |t vrdt| }nd}i }|dur||d< |dur ||d< |dur(||d< |dur0||d< |dur8||d< d	d
i}	| jd|||	dS )ai  
        Retrieves the current Watcher metrics.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-stats.html>`_

        :param metric: Defines which additional metrics are included in the response.
        :param emit_stacktraces: Defines whether stack traces are generated for each
            watch that is running.
        z/_watcher/stats/z/_watcher/statsNrc   r
   r   r   r   r   r   r=   r   r:   )
r   rb   rc   r
   r   r   r   r   r   r   r   r   r    stats  s$   !zWatcherClient.statsc                C   r]   )z
        Stops Watcher if it is running.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/watcher-api-stop.html>`_
        z/_watcher/_stopNr
   r   r   r   r   r   rW   r   r^   r_   r   r   r    stop  ra   zWatcherClient.stop)__name__
__module____qualname__r   rS   tOptionalUnionSequenceboolr   Anyr!   r$   r&   r,   Mappingr<   r>   intrJ   floatr\   r`   rd   re   r   r   r   r    r      st   	(!!!	X!	
T	I4r   )typingri   Zelastic_transportr   _baser   utilsr   r   r   r   r   r   r   r    <module>   s
   