laceworksdk.api.search_endpoint

 1# -*- coding: utf-8 -*-
 2
 3from laceworksdk.api.base_endpoint import BaseEndpoint
 4
 5
 6class SearchEndpoint(BaseEndpoint):
 7    """
 8    A class used to implement Search functionality for Lacework API Endpoints
 9    """
10
11    # If defined, this is the resource used in the URL path
12    RESOURCE = ""
13
14    def __init__(self,
15                 session,
16                 object_type,
17                 endpoint_root="/api/v2"):
18        """
19        :param session: An instance of the HttpSession class.
20        :param object_type: The Lacework object type to use.
21        :param endpoint_root: The URL endpoint root to use.
22        """
23
24        super().__init__(session, object_type, endpoint_root)
25
26    def search(self, json=None, resource=None, **kwargs):
27        """
28        A method to search objects.
29
30        :param json: A dictionary containing the desired search parameters.
31            (timeFilter, filters, returns)
32
33        :return a generator which yields a page of objects at a time as returned by the Lacework API.
34        """
35
36        if not resource and self.RESOURCE:
37            resource = self.RESOURCE
38
39        response = self._session.post(self.build_url(resource=resource, action="search"), json=json)
40
41        while True:
42            response_json = response.json()
43            yield response_json
44
45            try:
46                next_page = response_json.get("paging", {}).get("urls", {}).get("nextPage")
47            except Exception:
48                next_page = None
49
50            if next_page:
51                response = self._session.get(next_page, **kwargs)
52            else:
53                break
class SearchEndpoint(laceworksdk.api.base_endpoint.BaseEndpoint):
 7class SearchEndpoint(BaseEndpoint):
 8    """
 9    A class used to implement Search functionality for Lacework API Endpoints
10    """
11
12    # If defined, this is the resource used in the URL path
13    RESOURCE = ""
14
15    def __init__(self,
16                 session,
17                 object_type,
18                 endpoint_root="/api/v2"):
19        """
20        :param session: An instance of the HttpSession class.
21        :param object_type: The Lacework object type to use.
22        :param endpoint_root: The URL endpoint root to use.
23        """
24
25        super().__init__(session, object_type, endpoint_root)
26
27    def search(self, json=None, resource=None, **kwargs):
28        """
29        A method to search objects.
30
31        :param json: A dictionary containing the desired search parameters.
32            (timeFilter, filters, returns)
33
34        :return a generator which yields a page of objects at a time as returned by the Lacework API.
35        """
36
37        if not resource and self.RESOURCE:
38            resource = self.RESOURCE
39
40        response = self._session.post(self.build_url(resource=resource, action="search"), json=json)
41
42        while True:
43            response_json = response.json()
44            yield response_json
45
46            try:
47                next_page = response_json.get("paging", {}).get("urls", {}).get("nextPage")
48            except Exception:
49                next_page = None
50
51            if next_page:
52                response = self._session.get(next_page, **kwargs)
53            else:
54                break

A class used to implement Search functionality for Lacework API Endpoints

SearchEndpoint(session, object_type, endpoint_root='/api/v2')
15    def __init__(self,
16                 session,
17                 object_type,
18                 endpoint_root="/api/v2"):
19        """
20        :param session: An instance of the HttpSession class.
21        :param object_type: The Lacework object type to use.
22        :param endpoint_root: The URL endpoint root to use.
23        """
24
25        super().__init__(session, object_type, endpoint_root)
Parameters
  • session: An instance of the HttpSession class.
  • object_type: The Lacework object type to use.
  • endpoint_root: The URL endpoint root to use.
RESOURCE = ''
def search(self, json=None, resource=None, **kwargs):
27    def search(self, json=None, resource=None, **kwargs):
28        """
29        A method to search objects.
30
31        :param json: A dictionary containing the desired search parameters.
32            (timeFilter, filters, returns)
33
34        :return a generator which yields a page of objects at a time as returned by the Lacework API.
35        """
36
37        if not resource and self.RESOURCE:
38            resource = self.RESOURCE
39
40        response = self._session.post(self.build_url(resource=resource, action="search"), json=json)
41
42        while True:
43            response_json = response.json()
44            yield response_json
45
46            try:
47                next_page = response_json.get("paging", {}).get("urls", {}).get("nextPage")
48            except Exception:
49                next_page = None
50
51            if next_page:
52                response = self._session.get(next_page, **kwargs)
53            else:
54                break

A method to search objects.

Parameters
  • json: A dictionary containing the desired search parameters. (timeFilter, filters, returns)

:return a generator which yields a page of objects at a time as returned by the Lacework API.