Skip to content

Commit 2f4f189

Browse files
droessmjAlan Nixalannix-lw
authored
Adding AgentInfo and Inventory endpoints (#70)
* added AgentInfo, Inventory search endpoints * tweaked doc * tests: adding tests for AgentInfo and Inventory * Update laceworksdk/api/__init__.py Co-authored-by: Alan Nix <65611624+alannix-lw@users.noreply.github.com> Co-authored-by: Alan Nix <alan.nix@lacework.net> Co-authored-by: Alan Nix <65611624+alannix-lw@users.noreply.github.com>
1 parent 8ef599c commit 2f4f189

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

laceworksdk/api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from .v2.activities import ActivitiesAPI
2525
from .v2.agent_access_tokens import AgentAccessTokensAPI
26+
from .v2.agent_info import AgentInfoAPI
2627
from .v2.alert_channels import AlertChannelsAPI
2728
from .v2.alert_profiles import AlertProfilesAPI
2829
from .v2.alert_rules import AlertRulesAPI
@@ -36,6 +37,7 @@
3637
from .v2.datasources import DatasourcesAPI
3738
from .v2.entities import EntitiesAPI
3839
from .v2.evidence import EvidenceAPI
40+
from .v2.inventory import InventoryAPI
3941
from .v2.organization_info import OrganizationInfoAPI
4042
from .v2.policies import PoliciesAPI
4143
from .v2.queries import QueriesAPI
@@ -136,6 +138,7 @@ def __init__(self,
136138
self.account = AccountAPI(self._session)
137139
self.activities = ActivitiesAPI(self._session)
138140
self.agent_access_tokens = AgentAccessTokensAPI(self._session)
141+
self.agent_info = AgentInfoAPI(self._session)
139142
self.alert_channels = AlertChannelsAPI(self._session)
140143
self.alert_profiles = AlertProfilesAPI(self._session)
141144
self.alert_rules = AlertRulesAPI(self._session)
@@ -153,6 +156,7 @@ def __init__(self,
153156
self.events = EventsAPI(self._session)
154157
self.evidence = EvidenceAPI(self._session)
155158
self.files = DownloadFileAPI(self._session)
159+
self.inventory = InventoryAPI(self._session)
156160
self.integrations = IntegrationsAPI(self._session)
157161
self.organization_info = OrganizationInfoAPI(self._session)
158162
self.policies = PoliciesAPI(self._session)

laceworksdk/api/v2/agent_info.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Lacework AgentInfo API wrapper.
4+
"""
5+
6+
from laceworksdk.api.search_endpoint import SearchEndpoint
7+
8+
9+
class AgentInfoAPI(SearchEndpoint):
10+
11+
def __init__(self, session):
12+
"""
13+
Initializes the AgentInfo API object.
14+
15+
:param session: An instance of the HttpSession class
16+
17+
:return AgentInfoAPI object.
18+
"""
19+
20+
super().__init__(session, "AgentInfo")

laceworksdk/api/v2/inventory.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Lacework Inventory API wrapper.
4+
"""
5+
6+
from laceworksdk.api.search_endpoint import SearchEndpoint
7+
8+
9+
class InventoryAPI(SearchEndpoint):
10+
11+
def __init__(self, session):
12+
"""
13+
Initializes the Inventory API object.
14+
15+
:param session: An instance of the HttpSession class
16+
17+
:return InventoryAPI object.
18+
"""
19+
20+
super().__init__(session, "Inventory")

tests/api/v2/test_agent_info.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Test suite for the community-developed Python SDK for interacting with Lacework APIs.
4+
"""
5+
6+
import pytest
7+
8+
from laceworksdk.api.v2.agent_info import (
9+
AgentInfoAPI
10+
)
11+
from tests.api.test_search_endpoint import SearchEndpoint
12+
13+
# Tests
14+
15+
16+
@pytest.fixture(scope="module")
17+
def api_object(api):
18+
return api.agent_info
19+
20+
21+
class TestConfigsEndpoint(SearchEndpoint):
22+
23+
OBJECT_TYPE = AgentInfoAPI

tests/api/v2/test_inventory.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Test suite for the community-developed Python SDK for interacting with Lacework APIs.
4+
"""
5+
6+
import pytest
7+
8+
from laceworksdk.api.v2.inventory import (
9+
InventoryAPI
10+
)
11+
from tests.api.test_search_endpoint import SearchEndpoint
12+
13+
# Tests
14+
15+
16+
@pytest.fixture(scope="module")
17+
def api_object(api):
18+
return api.inventory
19+
20+
21+
class TestConfigsEndpoint(SearchEndpoint):
22+
23+
OBJECT_TYPE = InventoryAPI
24+
25+
@pytest.mark.parametrize("dataset", ["AwsCompliance", "GcpCompliance"])
26+
def test_api_search_by_date(self, api_object, dataset):
27+
start_time, end_time = self._get_start_end_times(self.DAY_DELTA)
28+
29+
for attribute in self.OBJECT_MAP.keys():
30+
response = getattr(api_object, attribute).search(json={
31+
"timeFilters": {
32+
"startTime": start_time,
33+
"endTime": end_time
34+
},
35+
"dataset": dataset
36+
})
37+
38+
self._assert_pages(response, self.MAX_PAGES)

0 commit comments

Comments
 (0)