Skip to content

Commit

Permalink
Adding AgentInfo and Inventory endpoints (#70)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored May 23, 2022
1 parent 8ef599c commit 2f4f189
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
4 changes: 4 additions & 0 deletions laceworksdk/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from .v2.activities import ActivitiesAPI
from .v2.agent_access_tokens import AgentAccessTokensAPI
from .v2.agent_info import AgentInfoAPI
from .v2.alert_channels import AlertChannelsAPI
from .v2.alert_profiles import AlertProfilesAPI
from .v2.alert_rules import AlertRulesAPI
Expand All @@ -36,6 +37,7 @@
from .v2.datasources import DatasourcesAPI
from .v2.entities import EntitiesAPI
from .v2.evidence import EvidenceAPI
from .v2.inventory import InventoryAPI
from .v2.organization_info import OrganizationInfoAPI
from .v2.policies import PoliciesAPI
from .v2.queries import QueriesAPI
Expand Down Expand Up @@ -136,6 +138,7 @@ def __init__(self,
self.account = AccountAPI(self._session)
self.activities = ActivitiesAPI(self._session)
self.agent_access_tokens = AgentAccessTokensAPI(self._session)
self.agent_info = AgentInfoAPI(self._session)
self.alert_channels = AlertChannelsAPI(self._session)
self.alert_profiles = AlertProfilesAPI(self._session)
self.alert_rules = AlertRulesAPI(self._session)
Expand All @@ -153,6 +156,7 @@ def __init__(self,
self.events = EventsAPI(self._session)
self.evidence = EvidenceAPI(self._session)
self.files = DownloadFileAPI(self._session)
self.inventory = InventoryAPI(self._session)
self.integrations = IntegrationsAPI(self._session)
self.organization_info = OrganizationInfoAPI(self._session)
self.policies = PoliciesAPI(self._session)
Expand Down
20 changes: 20 additions & 0 deletions laceworksdk/api/v2/agent_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
"""
Lacework AgentInfo API wrapper.
"""

from laceworksdk.api.search_endpoint import SearchEndpoint


class AgentInfoAPI(SearchEndpoint):

def __init__(self, session):
"""
Initializes the AgentInfo API object.
:param session: An instance of the HttpSession class
:return AgentInfoAPI object.
"""

super().__init__(session, "AgentInfo")
20 changes: 20 additions & 0 deletions laceworksdk/api/v2/inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
"""
Lacework Inventory API wrapper.
"""

from laceworksdk.api.search_endpoint import SearchEndpoint


class InventoryAPI(SearchEndpoint):

def __init__(self, session):
"""
Initializes the Inventory API object.
:param session: An instance of the HttpSession class
:return InventoryAPI object.
"""

super().__init__(session, "Inventory")
23 changes: 23 additions & 0 deletions tests/api/v2/test_agent_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
"""
Test suite for the community-developed Python SDK for interacting with Lacework APIs.
"""

import pytest

from laceworksdk.api.v2.agent_info import (
AgentInfoAPI
)
from tests.api.test_search_endpoint import SearchEndpoint

# Tests


@pytest.fixture(scope="module")
def api_object(api):
return api.agent_info


class TestConfigsEndpoint(SearchEndpoint):

OBJECT_TYPE = AgentInfoAPI
38 changes: 38 additions & 0 deletions tests/api/v2/test_inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""
Test suite for the community-developed Python SDK for interacting with Lacework APIs.
"""

import pytest

from laceworksdk.api.v2.inventory import (
InventoryAPI
)
from tests.api.test_search_endpoint import SearchEndpoint

# Tests


@pytest.fixture(scope="module")
def api_object(api):
return api.inventory


class TestConfigsEndpoint(SearchEndpoint):

OBJECT_TYPE = InventoryAPI

@pytest.mark.parametrize("dataset", ["AwsCompliance", "GcpCompliance"])
def test_api_search_by_date(self, api_object, dataset):
start_time, end_time = self._get_start_end_times(self.DAY_DELTA)

for attribute in self.OBJECT_MAP.keys():
response = getattr(api_object, attribute).search(json={
"timeFilters": {
"startTime": start_time,
"endTime": end_time
},
"dataset": dataset
})

self._assert_pages(response, self.MAX_PAGES)

0 comments on commit 2f4f189

Please sign in to comment.