o
    lqi"                     @   sz   d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
mZmZ ddlmZ ddlmZ G dd	 d	ejZdS )
z-
This module provides a client class for CA.
    N)bce_base_clientcompat)bce_v1_signer)handlerbce_http_clienthttp_methods)
ca_handler)requiredc                   @   s   e Zd ZdZdZdZdZdZd"ddZd"d	d
Z		d#ddZ
d"ddZ		d$ddZdd Zdd Zd%ddZd&ddZ		d&ddZd%ddZ		d'ddZd(d d!ZdS ))CaClientz
    CA base sdk client
    s   /v1s   content-types   application/json;charset=UTF-8s   x-bce-request-idNc                 C   s   t j| | d S N)r   BceBaseClient__init__)selfconfig r   e/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/baidubce/services/ca/ca_client.pyr      s   zCaClient.__init__c                 C   s(   |d u r| j S t| j }|| |S r   )r   copyZmerge_non_none_values)r   r   Z
new_configr   r   r   _merge_config   s
   
zCaClient._merge_configc              
   C   sx   |  |}|d u rtj}|d u ri }| j|vr| j|| j< | j|vr)t || j< t	|t
jtj|g|tj| |||S r   )r   r   Z
parse_jsoncontent_type_header_keycontent_type_header_valuerequest_id_header_keyuuiduuid4r   send_requestr   signr   Zparse_errorr
   version)r   Zhttp_methodpathbodyheadersparamsr   Zbody_parserr   r   r   _send_request$   s   


zCaClient._send_requestc                 C   s$   d}d|i}| j tj|t|dS )zy
        Batch get agent info

        :param instance_list:
         Instance List
        :type instance: dict
        s   /ca/agent/batchhostsr   r    r   POSTjsondumps)r   Zinstance_listr   r   r   r   r   batch_get_agent4   s   zCaClient.batch_get_agentc           
      C   s0   d}|||||||d}	| j tj|t|	dS )ap  
        create execution
        :param execution:
        execution info
        :type execution: string

        :param user_id:
        user_id
        :type user_id: string

        :param action:
        action info
        :type action: dict

        :param targets:
        targets info
        :type targets:list

        :param parameters:
        parameters info
        :type parameters:dict

        :param target_selector:
        target_selector info
        :type target_selector:dict

        :param target_selector_type:
        target_selector_type info
        :type target_selector_type:string

        
   /ca/action)	executionactiontargetsuserId
parameterstargetSelectortargetSelectorTyper"   r#   )
r   r)   user_idr*   r+   r-   target_selectortarget_selector_typer   r   r   r   r   create_actionB   s   !	zCaClient.create_actionc                 C   s    t |}d| }| tj|S )zn
        Delete action
        :param id: The ID of the execution to be deleted
        :type id: str
        s   /ca/action/%s)r   Zconvert_to_bytesr    r   DELETE)r   idr   r   r   r   delete_actiono   s   
zCaClient.delete_actionc                 C   s    d}||d}| j tj||dS )z
        Query id
        :param id: The ID of the execution to be queried
        :type id: str

        Query user_id
        :param user_id: user_id
        :type user_id: str

        r(   r,   r5   r   r    r   GET)r   r5   r0   r   r   r   r   r   
get_actiony   s
   zCaClient.get_actionc                 C   s&   d}||d}| j tj|t|dS )z
        :param action:
        action info
        :type action: dict

        :param execution
        execution info
        :type execution: string
        r(   )r*   r)   r"   )r    r   PUTr%   r&   )r   r*   r)   r   r   r   r   r   update_action   s
   
zCaClient.update_actionc           	      C   s.   d}||||||d}| j tj|t|dS )a  
        :param action:
        action info
        :type action: dict

        :param page_no:
        page number
        :type page_no: int

        :param page_size:
        page number
        :type page_size: int

        :param sort:
        sort order
        :type sort: str

        :param ascending:
        ascending order
        :type ascending: bool

        :param user_id:
        :type user_id: str
        s   /ca/action/list)r*   pageNopageSizesort	ascendingr,   r"   r#   )	r   r*   page_no	page_sizer@   rA   r0   r   r   r   r   r   action_list   s   zCaClient.action_listc           	      C   s0   d}||||||dd}| j tj|t|dS )a  
        :param action:
        action info
        :type action: dict

        :param parameters:
        :param target_selector_type:map

        :param user_id:
        :type user_id: str

        target selector type
        :type target_selector_type: str

        :param targets:
        :type targets: list

        :param target_selector:
        :type target_selector: dict
           /ca/actionRunZRUN)r*   r-   r/   r+   r.   r,   r)   r"   r#   )	r   r*   r-   r0   r2   r+   r1   r   r   r   r   r   
action_run   s   	zCaClient.action_runc                 C   s    ||d}d}| j tj||dS )z
        Query id
        :param id: The ID of the execution to be queried
        :type id: str

        user_id
        :user_id id: str
        r7   rE   r8   r9   )r   r5   r0   r   r   r   r   r   get_action_run   s
   
zCaClient.get_action_runFc                 C   s:   |||||||||	|
||d}d}| j tj|t|dS )ak  
        :param action:
        action info
        :type action: dict

        :param page_no:
        page number
        :type page_no: int

        :param page_size:
        page number
        :type page_size: int

        :param sort:
        sort order
        :type sort: str

        :param ascending:
        ascending order
        :type ascending: bool

        :param user_id:
        :type user_id: str

        :param start_time:
        start time
        :type start_time:

        :param end_time:
        end time
        :type end_time:

        :param keyword:
        keyword type
        :type keyword: str

        :param keyword_type:
        keyword type
        :type keyword_type: str

        :param run_id:
        run id
        :type run_id: str

        :param is_inited:
        is inited or not inited
        :type is_inited: bool
        )r*   r>   r?   r@   rA   r,   Z	startTimeZendTimekeywordkeyword_typerunIdZisIniteds   /ca/actionRun/listr"   r#   )r   r*   rB   rC   r@   rA   r0   
start_timeend_timerH   rI   run_idZ	is_initedr   r   r   r   r   action_run_list   s   3zCaClient.action_run_listc                 C   s(   |||d}d}| j tj|t|dS )z
        :param run_id:
        :type run_id: str

        :param child_id:
        :type child_id: str

        :param cursor:
        :type cursor: int
        )rJ   ZchildIdcursors   /ca/logr"   r#   )r   rM   Zchild_idrO   r   r   r   r   r   
action_log5  s   zCaClient.action_logr   )NNNNN)NNNNNNN)NN)NNNNNN)NNNNNNNNNNNF)NNN)__name__
__module____qualname____doc__r   r   r   r   r   r   r    r'   r3   r6   r;   r=   rD   rF   rG   rN   rP   r   r   r   r   r
      s4    

	


-


$

"
Cr
   )rT   r   r%   r   Zbaidubcer   r   Zbaidubce.authr   Zbaidubce.httpr   r   r   Zbaidubce.services.car   Zbaidubce.utilsr	   r   r
   r   r   r   r   <module>   s    