예제 #1
0
    def create(cls, attach_host_name=False, method='POST', id=None, params=None, **body):
        """
        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: JSON response from HTTP API request
        """
        if params is None:
            params = {}
        if method == 'GET':
            return APIClient.submit('GET', cls._class_url, **body)
        if id is None:
            return APIClient.submit('POST', cls._class_url, body,
                                    attach_host_name=attach_host_name, **params)
        else:
            return APIClient.submit('POST', cls._class_url + "/" + str(id), body,
                                    attach_host_name=attach_host_name, **params)
예제 #2
0
    def _trigger_action(cls, method, name, id=None, **body):
        """
        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
        """
        api_version = getattr(cls, '_api_version', None)
        if id is None:
            return APIClient.submit(method, name, api_version, body)

        path = '{action_name}/{resource_id}'.format(action_name=name,
                                                    resource_id=id)
        if method == "GET":
            # Do not add body to GET requests, it causes 400 Bad request responses on EU site
            body = None
        return APIClient.submit(method, path, api_version, body)
예제 #3
0
    def _trigger_class_action(cls, method, name, id=None, params=None, **body):
        """
        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
        """
        if params is None:
            params = {}

        if id is None:
            path = '{resource_name}/{action_name}'.format(
                resource_name=cls._resource_name, action_name=name)
            return APIClient.submit(method, path, body, **params)

        path = '{resource_name}/{resource_id}/{action_name}'.format(
            resource_name=cls._resource_name, resource_id=id, action_name=name)
        return APIClient.submit(method, path, body, **params)
예제 #4
0
    def send(cls, attach_host_name=False, id=None, **body):
        """
        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 body: new resource object attributes
        :type body: dictionary

        :returns: JSON response from HTTP API request
        """
        if id is None:
            return APIClient.submit('POST',
                                    cls._class_url,
                                    body,
                                    attach_host_name=attach_host_name)
        else:
            return APIClient.submit('POST',
                                    cls._class_url + "/" + str(id),
                                    body,
                                    attach_host_name=attach_host_name)
예제 #5
0
    def create(cls, attach_host_name=False, method='POST', id=None, params=None, **body):
        """
        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
        """
        if params is None:
            params = {}
        if method == 'GET':
            return APIClient.submit('GET', cls._class_url, **body)
        if id is None:
            return APIClient.submit('POST', cls._class_url, body,
                                    attach_host_name=attach_host_name, **params)
        else:
            return APIClient.submit('POST', cls._class_url + "/" + str(id), body,
                                    attach_host_name=attach_host_name, **params)
예제 #6
0
    def send(cls, attach_host_name=False, id=None, **body):
        """
        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 body: new resource object attributes
        :type body: dictionary

        :returns: Dictionary representing the API's JSON response
        """
        api_version = getattr(cls, '_api_version', None)

        if id is None:
            return APIClient.submit('POST',
                                    cls._resource_name,
                                    api_version,
                                    body,
                                    attach_host_name=attach_host_name)

        path = '{resource_name}/{resource_id}'.format(
            resource_name=cls._resource_name, resource_id=id)
        return APIClient.submit('POST',
                                path,
                                api_version,
                                body,
                                attach_host_name=attach_host_name)
예제 #7
0
    def create(cls,
               attach_host_name=False,
               method='POST',
               id=None,
               params=None,
               **body):
        """
        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
        """
        if params is None:
            params = {}

        path = cls._resource_name
        api_version = getattr(cls, '_api_version', None)

        if method == 'GET':
            return APIClient.submit('GET', path, api_version, **body)
        if id is None:
            return APIClient.submit('POST',
                                    path,
                                    api_version,
                                    body,
                                    attach_host_name=attach_host_name,
                                    **params)

        path = '{resource_name}/{resource_id}'.format(
            resource_name=cls._resource_name, resource_id=id)
        return APIClient.submit('POST',
                                path,
                                api_version,
                                body,
                                attach_host_name=attach_host_name,
                                **params)
예제 #8
0
    def update_synthetics_items(cls, id, params=None, **body):
        """
        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
        """
        if params is None:
            params = {}

        path = '{resource_name}/tests/{resource_id}/{sub_resource_name}'.format(
            resource_name=cls._resource_name,
            resource_id=id,
            sub_resource_name=cls._sub_resource_name)
        api_version = getattr(cls, '_api_version', None)

        return APIClient.submit('PUT', path, api_version, body, **params)
예제 #9
0
    def update(cls, method=None, id=None, params=None, **body):
        """
        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
        """

        if method is None:
            method = 'PUT'
        if params is None:
            params = {}

        path = '{resource_name}/{resource_id}'.format(
            resource_name=cls._resource_name, resource_id=id)
        api_version = getattr(cls, '_api_version', None)

        return APIClient.submit(method, path, api_version, body, **params)
예제 #10
0
    def delete_items(cls, id, params=None, **body):
        """
        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
        """
        if params is None:
            params = {}

        path = "{resource_name}/{resource_id}/{sub_resource_name}".format(
            resource_name=cls._resource_name,
            resource_id=id,
            sub_resource_name=cls._sub_resource_name)
        api_version = getattr(cls, "_api_version", None)

        return APIClient.submit("DELETE", path, api_version, body, **params)
예제 #11
0
파일: logs.py 프로젝트: tonyakwei/datadogpy
    def list(cls, data):
        path = "{resource_name}/list".format(
            resource_name=cls._resource_name,
        )
        api_version = getattr(cls, "_api_version", None)

        return APIClient.submit("POST", path, api_version, data)
예제 #12
0
    def add_items(cls, id, params=None, **body):
        """
        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
        """
        if params is None:
            params = {}

        path = '{resource_name}/{resource_id}/{sub_resource_name}'.format(
            resource_name=cls._resource_name,
            resource_id=id,
            sub_resource_name=cls._sub_resource_name)
        api_version = getattr(cls, '_api_version', None)

        return APIClient.submit('POST', path, api_version, body, **params)
예제 #13
0
    def get_all(cls, **params):
        """
        List API resource objects

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

        :returns: JSON response from HTTP API request
        """
        return APIClient.submit('GET', cls._class_url, **params)
예제 #14
0
    def _search(cls, **params):
        """
        Query an API resource stream

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

        :returns: JSON response from HTTP API request
        """
        return APIClient.submit('GET', cls._class_url, **params)
예제 #15
0
    def get_all(cls, **params):
        """
        List API resource objects

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

        :returns: Dictionary representing the API's JSON response
        """
        return APIClient.submit('GET', cls._class_url, **params)
예제 #16
0
    def get_all(cls, **params):
        """
        List API resource objects

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

        :returns: JSON response from HTTP API request
        """
        return APIClient.submit('GET', cls._class_url, **params)
예제 #17
0
    def _search(cls, **params):
        """
        Query an API resource stream

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

        :returns: Dictionary representing the API's JSON response
        """
        return APIClient.submit('GET', cls._class_url, **params)
예제 #18
0
    def _search(cls, **params):
        """
        Query an API resource stream

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

        :returns: JSON response from HTTP API request
        """
        return APIClient.submit('GET', cls._class_url, **params)
예제 #19
0
    def delete(cls, id, **params):
        """
        Delete an API resource object

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

        :returns: JSON response from HTTP API request
        """
        return APIClient.submit('DELETE', cls._class_url + "/" + str(id), **params)
예제 #20
0
    def _search(cls, **params):
        """
        Query an API resource stream

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

        :returns: Dictionary representing the API's JSON response
        """
        return APIClient.submit('GET', cls._resource_name, **params)
예제 #21
0
    def get_all(cls, **params):
        """
        List API resource objects

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

        :returns: Dictionary representing the API's JSON response
        """
        return APIClient.submit('GET', cls._resource_name, **params)
예제 #22
0
    def delete(cls, id, **params):
        """
        Delete an API resource object

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

        :returns: Dictionary representing the API's JSON response
        """
        return APIClient.submit('DELETE', cls._class_url + "/" + str(id), **params)
예제 #23
0
    def send(cls,
             attach_host_name=False,
             id=None,
             compress_payload=False,
             **body):
        """
        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
        """
        api_version = getattr(cls, "_api_version", None)

        if id is None:
            return APIClient.submit(
                "POST",
                cls._resource_name,
                api_version,
                body,
                attach_host_name=attach_host_name,
                compress_payload=compress_payload,
            )

        path = "{resource_name}/{resource_id}".format(
            resource_name=cls._resource_name, resource_id=id)
        return APIClient.submit("POST",
                                path,
                                api_version,
                                body,
                                attach_host_name=attach_host_name,
                                compress_payload=compress_payload)
예제 #24
0
    def delete(cls, id, **params):
        """
        Delete an API resource object

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

        :returns: JSON response from HTTP API request
        """
        return APIClient.submit('DELETE', cls._class_url + "/" + str(id),
                                **params)
예제 #25
0
    def send(cls, attach_host_name=False, id=None, **body):
        """
        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 body: new resource object attributes
        :type body: dictionary

        :returns: JSON response from HTTP API request
        """
        if id is None:
            return APIClient.submit('POST', cls._class_url, body,
                                    attach_host_name=attach_host_name)
        else:
            return APIClient.submit('POST', cls._class_url + "/" + str(id), body,
                                    attach_host_name=attach_host_name)
예제 #26
0
    def delete(cls, id, **params):
        """
        Delete an API resource object

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

        :returns: Dictionary representing the API's JSON response
        """
        path = '{resource_name}/{resource_id}'.format(
            resource_name=cls._resource_name, resource_id=id)
        return APIClient.submit('DELETE', path, **params)
예제 #27
0
    def get(cls, id, **params):
        """
        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
        """
        return APIClient.submit('GET', cls._class_url + "/" + str(id), **params)
예제 #28
0
    def _trigger_class_action(cls, method, name, id=None, **params):
        """
        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

        :returns: Dictionary representing the API's JSON response
        """
        if id is None:
            return APIClient.submit(method, cls._class_url + "/" + name, params)
        else:
            return APIClient.submit(method, cls._class_url + "/" + str(id) + "/" + name, params)
예제 #29
0
    def get(cls, id, **params):
        """
        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: JSON response from HTTP API request
        """
        return APIClient.submit('GET', cls._class_url + "/" + str(id), **params)
예제 #30
0
    def _trigger_action(cls, method, name, id=None, **params):
        """
        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

        :returns: JSON response from HTTP API request
        """
        if id is None:
            return APIClient.submit(method, name, params)
        else:
            return APIClient.submit(method, name + "/" + str(id), params)
예제 #31
0
    def _trigger_action(cls, method, name, id=None, **params):
        """
        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

        :returns: JSON response from HTTP API request
        """
        if id is None:
            return APIClient.submit(method, name, params)
        else:
            return APIClient.submit(method, name + "/" + str(id), params)
예제 #32
0
    def _search(cls, **params):
        """
        Query an API resource stream

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

        :returns: Dictionary representing the API's JSON response
        """
        api_version = getattr(cls, "_api_version", None)

        return APIClient.submit("GET", cls._resource_name, api_version,
                                **params)
예제 #33
0
    def delete(cls, id, **params):
        """
        Delete an API resource object

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

        :returns: Dictionary representing the API's JSON response
        """
        path = "{resource_name}/{resource_id}".format(
            resource_name=cls._resource_name, resource_id=id)
        api_version = getattr(cls, "_api_version", None)

        return APIClient.submit("DELETE", path, api_version, **params)
예제 #34
0
    def unassign_permission(cls, id, **body):
        """
        Unassign permission from a role

        :param id: uuid of the role to unassign permission from
        :param body: dict with "type": "permissions" and uuid of permission to unassign
        :returns: Dictionary representing the API's JSON response
        """
        params = {}
        path = "{resource_name}/{resource_id}/permissions".format(
            resource_name=cls._resource_name, resource_id=id)
        api_version = getattr(cls, "_api_version", None)

        return APIClient.submit("DELETE", path, api_version, body, **params)
예제 #35
0
    def assign_permission(cls, id, **body):
        """
        Assign permission to a role

        :param id: uuid of the role to assign permission to
        :param body: dict with "type": "permissions" and uuid of permission to assign
        :returns: Dictionary representing the API's JSON response
        """
        params = {}
        path = '{resource_name}/{resource_id}/permissions'.format(
            resource_name=cls._resource_name, resource_id=id)
        api_version = getattr(cls, '_api_version', None)

        return APIClient.submit("POST", path, api_version, body, **params)
예제 #36
0
    def update(cls, id, params=None, **body):
        """
        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
        """
        if params is None:
            params = {}
        return APIClient.submit('PUT', cls._class_url + "/" + str(id), body, **params)
예제 #37
0
    def update(cls, id, params=None, **body):
        """
        Update an API resource object

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

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

        :returns: JSON response from HTTP API request
        """
        if params is None:
            params = {}
        return APIClient.submit('PUT', cls._class_url + "/" + str(id), body, **params)
예제 #38
0
    def get(cls, id, **params):
        """
        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
        """
        path = '{resource_name}/{resource_id}'.format(
            resource_name=cls._resource_name, resource_id=id)
        return APIClient.submit('GET', path, **params)
예제 #39
0
    def get(cls, id, **params):
        """
        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
        """
        path = "{resource_name}/{resource_id}".format(
            resource_name=cls._resource_name, resource_id=id)
        api_version = getattr(cls, "_api_version", None)

        return APIClient.submit("GET", path, api_version, **params)
예제 #40
0
    def get_items(cls, id, **params):
        """
        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
        """
        path = '{resource_name}/{resource_id}/{sub_resource_name}'.format(
            resource_name=cls._resource_name,
            resource_id=id,
            sub_resource_name=cls._sub_resource_name)
        return APIClient.submit('GET', path, **params)