o
    i ?                     @   s  d Z ddlmZ G dd deZG dd deZG dd deZG d	d
 d
eZG dd deZG dd deZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZd#S )$z
Datadog API resources.
    )	APIClientc                   @   s   e Zd ZdZedddZdS )CreateableAPIResourcez 
    Creatable API Resource
    FPOSTNc                 K   s   |du ri }| j }t| dd}|dkrtjd||fi |S |du r0tjd|||fd|i|S dj| j |d}tjd|||fd|i|S )ac  
        Create a new API resource object

        :param attach_host_name: link the new resource object to the host name
        :type attach_host_name: bool

        :param method: HTTP method to use to contact API endpoint
        :type method: HTTP method string

        :param id: create a new resource object as a child of the given object
        :type id: id

        :param params: new resource object source
        :type params: dictionary

        :param body: new resource object attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        N_api_versionGETr   attach_host_name{resource_name}/{resource_id}resource_nameresource_id)_resource_namegetattrr   submitformat)clsr   methodidparamsbodypathapi_version r   I/home/ubuntu/.local/lib/python3.10/site-packages/datadog/api/resources.pycreate   s   zCreateableAPIResource.create)Fr   NN)__name__
__module____qualname____doc__classmethodr   r   r   r   r   r          r   c                   @   s   e Zd ZdZedddZdS )SendableAPIResourcezI
    Fork of CreateableAPIResource class with different method names
    FNc                 K   sR   t | dd}|du rtjd| j||||dS dj| j|d}tjd|||||dS )a  
        Create an API resource object

        :param attach_host_name: link the new resource object to the host name
        :type attach_host_name: bool

        :param id: create a new resource object as a child of the given object
        :type id: id

        :param compress_payload: compress the payload using zlib
        :type compress_payload: bool

        :param body: new resource object attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        r   Nr   )r   compress_payloadr   r	   )r   r   r   r   r   )r   r   r   r!   r   r   r   r   r   r   send:   s   	zSendableAPIResource.send)FNF)r   r   r   r   r   r"   r   r   r   r   r    5   r   r    c                   @      e Zd ZdZedddZdS )UpdatableAPIResourcez 
    Updatable API Resource
    Nc                 K   @   |du ri }dj | j|d}t| dd}tjd|||fi |S )"  
        Update an API resource object

        :param params: updated resource object source
        :type params: dictionary

        :param body: updated resource object attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        Nr   r	   r   PUTr   r   r   r   r   r   r   r   r   r   r   r   r   r   updated   
   zUpdatableAPIResource.updateNr   r   r   r   r   r*   r   r   r   r   r$   _   r   r$   c                   @   r#   )CustomUpdatableAPIResourcez6
    Updatable API Resource with custom HTTP Verb
    Nc                 K   sL   |du rd}|du ri }dj | j|d}t| dd}tj||||fi |S )a  
        Update an API resource object

        :param method: HTTP method, defaults to PUT
        :type params: string

        :param params: updatable resource id
        :type params: string

        :param params: updated resource object source
        :type params: dictionary

        :param body: updated resource object attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        Nr'   r   r	   r   r(   )r   r   r   r   r   r   r   r   r   r   r*      s   z!CustomUpdatableAPIResource.update)NNNr-   r   r   r   r   r.   z   r   r.   c                   @      e Zd ZdZedd ZdS )DeletableAPIResourcez 
    Deletable API Resource
    c                 K   2   dj | j|d}t| dd}tjd||fi |S )z
        Delete an API resource object

        :param id: resource object to delete
        :type id: id

        :returns: Dictionary representing the API's JSON response
        r   r	   r   NDELETEr(   r   r   r   r   r   r   r   r   delete   s   
zDeletableAPIResource.deleteN)r   r   r   r   r   r4   r   r   r   r   r0          r0   c                   @   r/   )GetableAPIResourcez
    Getable API Resource
    c                 K   r1   )a+  
        Get information about an API resource object

        :param id: resource object id to retrieve
        :type id: id

        :param params: parameters to filter API resource stream
        :type params: dictionary

        :returns: Dictionary representing the API's JSON response
        r   r	   r   Nr   r(   r3   r   r   r   get   s   zGetableAPIResource.getN)r   r   r   r   r   r7   r   r   r   r   r6      r5   r6   c                   @   r/   )ListableAPIResourcez
    Listable API Resource
    c                 K   $   t | dd}tjd| j|fi |S )z
        List API resource objects

        :param params: parameters to filter API resource stream
        :type params: dictionary

        :returns: Dictionary representing the API's JSON response
        r   Nr   r   r   r   r   r   r   r   r   r   r   get_all      
zListableAPIResource.get_allN)r   r   r   r   r   r<   r   r   r   r   r8      r5   r8   c                   @   r/   )ListableAPISubResourcez#
    Listable API Sub-Resource
    c                 K   s6   dj | j|| jd}t| dd}tjd||fi |S )aC  
        List API sub-resource objects from a resource

        :param id: resource id to retrieve sub-resource objects from
        :type id: id

        :param params: parameters to filter API sub-resource stream
        :type params: dictionary

        :returns: Dictionary representing the API's JSON response
        1{resource_name}/{resource_id}/{sub_resource_name}r
   r   sub_resource_namer   Nr   r   r   _sub_resource_namer   r   r   r3   r   r   r   	get_items   s
   
z ListableAPISubResource.get_itemsN)r   r   r   r   r   rD   r   r   r   r   r>      r5   r>   c                   @   r#   )AddableAPISubResourcez"
    Addable API Sub-Resource
    Nc                 K   D   |du ri }dj | j|| jd}t| dd}tjd|||fi |S )a|  
        Add new API sub-resource objects to a resource

        :param id: resource id to add sub-resource objects to
        :type id: id

        :param params: request parameters
        :type params: dictionary

        :param body: new sub-resource objects attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        Nr?   r@   r   r   rB   r)   r   r   r   	add_items      
zAddableAPISubResource.add_itemsr,   )r   r   r   r   r   rG   r   r   r   r   rE      r   rE   c                   @   r#   )UpdatableAPISubResourcez$
    Updatable API Sub-Resource
    Nc                 K   rF   )  
        Update API sub-resource objects of a resource

        :param id: resource id to update sub-resource objects from
        :type id: id

        :param params: request parameters
        :type params: dictionary

        :param body: updated sub-resource objects attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        Nr?   r@   r   r'   rB   r)   r   r   r   update_items  rH   z$UpdatableAPISubResource.update_itemsr,   )r   r   r   r   r   rK   r   r   r   r   rI     r   rI   c                   @   r#   )DeletableAPISubResourcez$
    Deletable API Sub-Resource
    Nc                 K   rF   )a  
        Delete API sub-resource objects from a resource

        :param id: resource id to delete sub-resource objects from
        :type id: id

        :param params: request parameters
        :type params: dictionary

        :param body: deleted sub-resource objects attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        Nr?   r@   r   r2   rB   r)   r   r   r   delete_items?  rH   z$DeletableAPISubResource.delete_itemsr,   )r   r   r   r   r   rM   r   r   r   r   rL   :  r   rL   c                   @   r/   )SearchableAPIResourcezG
    Fork of ListableAPIResource class with different method names
    c                 K   r9   )z
        Query an API resource stream

        :param params: parameters to filter API resource stream
        :type params: dictionary

        :returns: Dictionary representing the API's JSON response
        r   Nr   r:   r;   r   r   r   _search_  r=   zSearchableAPIResource._searchN)r   r   r   r   r   rO   r   r   r   r   rN   Z  r5   rN   c                   @   s,   e Zd ZdZedddZedddZdS )	ActionAPIResourcez!
    Actionable API Resource
    Nc                 K   h   |du ri }t | dd}|du rdj| j|d}n	dj| j||d}|dkr(d}tj||||fi |S )a  
        Trigger an action

        :param method: HTTP method to use to contact API endpoint
        :type method: HTTP method string

        :param action_name: action name
        :type action_name: string

        :param id: trigger the action for the specified resource object
        :type id: id

        :param params: action parameters
        :type params: dictionary

        :param body: action body
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        Nr   {resource_name}/{action_name}r
   action_namez+{resource_name}/{resource_id}/{action_name}r
   r   rT   r   r   r   r   r   r   )r   r   rT   r   r   r   r   r   r   r   r   _trigger_class_actions     z'ActionAPIResource._trigger_class_actionc                 K   sN   t | dd}|du rt||||S dj||d}|dkrd}t||||S )a  
        Trigger an action

        :param method: HTTP method to use to contact API endpoint
        :type method: HTTP method string

        :param name: action name
        :type name: string

        :param id: trigger the action for the specified resource object
        :type id: id

        :param body: action body
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        r   Nz{action_name}/{resource_id})rT   r   r   )r   r   r   r   )r   r   namer   r   r   r   r   r   r   _trigger_action  s   z!ActionAPIResource._trigger_actionNNr,   )r   r   r   r   r   rW   rZ   r   r   r   r   rP   n  s    %rP   c                   @   r#   )!UpdatableAPISyntheticsSubResourcez(
    Update Synthetics sub resource
    Nc                 K   rF   )rJ   Nz7{resource_name}/tests/{resource_id}/{sub_resource_name}r@   r   r'   rB   r)   r   r   r   update_synthetics_items  rH   z9UpdatableAPISyntheticsSubResource.update_synthetics_itemsr,   )r   r   r   r   r   r]   r   r   r   r   r\     r   r\   c                   @   r#   )UpdatableAPISyntheticsResourcez$
    Update Synthetics resource
    Nc                 K   r%   )r&   Nz#{resource_name}/tests/{resource_id}r	   r   r'   r(   r)   r   r   r   update_synthetics  r+   z0UpdatableAPISyntheticsResource.update_syntheticsr,   )r   r   r   r   r   r_   r   r   r   r   r^     r   r^   c                   @   r#   )ActionAPISyntheticsResourcez,
    Actionable Synthetics API Resource
    Nc                 K   rQ   )a  
        Trigger an action

        :param method: HTTP method to use to contact API endpoint
        :type method: HTTP method string

        :param name: action name
        :type name: string

        :param id: trigger the action for the specified resource object
        :type id: id

        :param params: action parameters
        :type params: dictionary

        :param body: action body
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        Nr   rR   rS   z+{resource_name}/{action_name}/{resource_id}rU   r   rV   )r   r   rY   r   r   r   r   r   r   r   r    _trigger_synthetics_class_action  rX   z<ActionAPISyntheticsResource._trigger_synthetics_class_actionr[   )r   r   r   r   r   ra   r   r   r   r   r`     r   r`   N)r   datadog.api.api_clientr   objectr   r    r$   r.   r0   r6   r8   r>   rE   rI   rL   rN   rP   r\   r^   r`   r   r   r   r   <module>   s$   **$   I 