Skip to content

Commit

Permalink
[BUGFIX] Remove online state enrichment in describe_devices() by defa…
Browse files Browse the repository at this point in the history
…ult (#100)

* Default describe_devices() online state enrichment to false

* bump version to 0.3.1
  • Loading branch information
kenoel authored May 26, 2023
1 parent e720cf5 commit 23f59d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
15 changes: 10 additions & 5 deletions caracara/modules/hosts/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def describe_devices(
self,
filters: FalconFilter or str = None,
online_state: Optional[Union[OnlineState, str]] = None,
enrich_with_online_state: Optional[bool] = False,
) -> Dict[str, Dict]:
"""Return a dictionary containing details for every device matching the provided filter.
Expand All @@ -149,11 +150,14 @@ def describe_devices(
self.logger.info("Describing devices according to the filter string %s", filters)
device_ids = self.get_device_ids(filters)

# Collect state data
device_state_data = self.get_online_state(device_ids)
if enrich_with_online_state:
# Collect state data
device_state_data = self.get_online_state(device_ids)

# Filter by online state, if applicable.
if online_state is not None:
if not enrich_with_online_state:
device_state_data = self.get_online_state(device_ids)
self.validate_online_state(online_state)
device_ids = list(filter(
lambda key: device_state_data[key]["state"] == online_state,
Expand All @@ -162,9 +166,10 @@ def describe_devices(

device_data = self.get_device_data(device_ids)

# Enrich the results with the online state field
for device_id, data in device_data.items():
data["state"] = device_state_data[device_id]["state"]
if enrich_with_online_state:
# Enrich the results with the online state field
for device_id, data in device_data.items():
data["state"] = device_state_data[device_id]["state"]

return device_data

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "caracara"
version = "0.3.0"
version = "0.3.1"
description = "The CrowdStrike Falcon Developer Toolkit"
authors = [ "CrowdStrike <falconpy@crowdstrike.com>" ]
readme = "README.md"
Expand Down
8 changes: 2 additions & 6 deletions tests/unit_tests/test_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def test_describe_devices(auth: Client, **_):
visible_devices = dict(
(id_, dev) for id_, dev in mock_devices.items() if dev.get("host_hidden_status") != "hidden"
)
for device_id, data in visible_devices.items():
data["state"] = mock_device_online_states[device_id]["state"]

assert auth.hosts.describe_devices() == visible_devices


Expand All @@ -170,8 +169,6 @@ def test_describe_devices__online_only(auth: Client, **_):
lambda item: item[0] in list(set(visible_ids) & set(online_ids)),
mock_devices.items(),
))
for _, dev in online_visible_devices.items():
dev["state"] = "online"

assert auth.hosts.describe_devices(online_state="online") == online_visible_devices

Expand All @@ -190,8 +187,7 @@ def test_describe_devices__enum_online_state(auth: Client, **_):
lambda item: item[0] in list(set(visible_ids) & set(offline_ids)),
mock_devices.items(),
))
for _, dev in offline_visible_devices.items():
dev["state"] = "offline"

assert auth.hosts.describe_devices(online_state=OnlineState.OFFLINE) == offline_visible_devices


Expand Down

0 comments on commit 23f59d8

Please sign in to comment.