laceworksdk.api.v2.datasources

Lacework Datasources API wrapper.

 1# -*- coding: utf-8 -*-
 2"""
 3Lacework Datasources API wrapper.
 4"""
 5
 6from laceworksdk.api.base_endpoint import BaseEndpoint
 7
 8
 9class DatasourcesAPI(BaseEndpoint):
10
11    _DEFAULT_DESCRIPTION = "No description available."
12
13    def __init__(self, session):
14        """
15        Initializes the Datasources object.
16
17        :param session: An instance of the HttpSession class
18
19        :return DatasourcesAPI object.
20        """
21
22        super().__init__(session, "Datasources")
23
24    def get(self,
25            type=None):
26        """
27        A method to get Datasources objects.
28
29        :param type: A string representing the object type.
30
31        :return response json
32        """
33
34        response = self._session.get(self.build_url(resource=type))
35
36        return response.json()
37
38    def get_by_type(self,
39                    type):
40        """
41        A method to get a Datasources object by type.
42
43        :param type: A string representing the object type.
44
45        :return response json
46        """
47
48        return self.get(type=type)
49
50    def get_datasource(self,
51                       datasource):
52        """
53        A method to get the schema for a particular datasource.
54
55        :param datasource: A string representing the datasource to check for.
56
57        :return response json
58        """
59
60        return self.get(type=datasource)
61
62    def list_data_sources(self):
63        """
64        A method to list the datasources that are available.
65
66        :return A list of tuples with two entries, source name and description.
67        """
68
69        response_json = self.get()
70
71        return_sources = []
72        data_sources = response_json.get("data", [])
73        for data_source in data_sources:
74            description = data_source.get(
75                "description", self._DEFAULT_DESCRIPTION)
76            if description == "None":
77                description = self._DEFAULT_DESCRIPTION
78
79            return_sources.append(
80                (data_source.get("name", "No name"), description))
81
82        return return_sources
class DatasourcesAPI(laceworksdk.api.base_endpoint.BaseEndpoint):
10class DatasourcesAPI(BaseEndpoint):
11
12    _DEFAULT_DESCRIPTION = "No description available."
13
14    def __init__(self, session):
15        """
16        Initializes the Datasources object.
17
18        :param session: An instance of the HttpSession class
19
20        :return DatasourcesAPI object.
21        """
22
23        super().__init__(session, "Datasources")
24
25    def get(self,
26            type=None):
27        """
28        A method to get Datasources objects.
29
30        :param type: A string representing the object type.
31
32        :return response json
33        """
34
35        response = self._session.get(self.build_url(resource=type))
36
37        return response.json()
38
39    def get_by_type(self,
40                    type):
41        """
42        A method to get a Datasources object by type.
43
44        :param type: A string representing the object type.
45
46        :return response json
47        """
48
49        return self.get(type=type)
50
51    def get_datasource(self,
52                       datasource):
53        """
54        A method to get the schema for a particular datasource.
55
56        :param datasource: A string representing the datasource to check for.
57
58        :return response json
59        """
60
61        return self.get(type=datasource)
62
63    def list_data_sources(self):
64        """
65        A method to list the datasources that are available.
66
67        :return A list of tuples with two entries, source name and description.
68        """
69
70        response_json = self.get()
71
72        return_sources = []
73        data_sources = response_json.get("data", [])
74        for data_source in data_sources:
75            description = data_source.get(
76                "description", self._DEFAULT_DESCRIPTION)
77            if description == "None":
78                description = self._DEFAULT_DESCRIPTION
79
80            return_sources.append(
81                (data_source.get("name", "No name"), description))
82
83        return return_sources

A class used to implement base functionality for Lacework API Endpoints

DatasourcesAPI(session)
14    def __init__(self, session):
15        """
16        Initializes the Datasources object.
17
18        :param session: An instance of the HttpSession class
19
20        :return DatasourcesAPI object.
21        """
22
23        super().__init__(session, "Datasources")

Initializes the Datasources object.

Parameters
  • session: An instance of the HttpSession class

:return DatasourcesAPI object.

def get(self, type=None):
25    def get(self,
26            type=None):
27        """
28        A method to get Datasources objects.
29
30        :param type: A string representing the object type.
31
32        :return response json
33        """
34
35        response = self._session.get(self.build_url(resource=type))
36
37        return response.json()

A method to get Datasources objects.

Parameters
  • type: A string representing the object type.

:return response json

def get_by_type(self, type):
39    def get_by_type(self,
40                    type):
41        """
42        A method to get a Datasources object by type.
43
44        :param type: A string representing the object type.
45
46        :return response json
47        """
48
49        return self.get(type=type)

A method to get a Datasources object by type.

Parameters
  • type: A string representing the object type.

:return response json

def get_datasource(self, datasource):
51    def get_datasource(self,
52                       datasource):
53        """
54        A method to get the schema for a particular datasource.
55
56        :param datasource: A string representing the datasource to check for.
57
58        :return response json
59        """
60
61        return self.get(type=datasource)

A method to get the schema for a particular datasource.

Parameters
  • datasource: A string representing the datasource to check for.

:return response json

def list_data_sources(self):
63    def list_data_sources(self):
64        """
65        A method to list the datasources that are available.
66
67        :return A list of tuples with two entries, source name and description.
68        """
69
70        response_json = self.get()
71
72        return_sources = []
73        data_sources = response_json.get("data", [])
74        for data_source in data_sources:
75            description = data_source.get(
76                "description", self._DEFAULT_DESCRIPTION)
77            if description == "None":
78                description = self._DEFAULT_DESCRIPTION
79
80            return_sources.append(
81                (data_source.get("name", "No name"), description))
82
83        return return_sources

A method to list the datasources that are available.

:return A list of tuples with two entries, source name and description.