Skip to content

Commit cd4942a

Browse files
authored
Merge pull request #9 from yeti-platform/overlays
Add function to get Yara bundles with overlays
2 parents 2ac576a + 33c8332 commit cd4942a

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# yeti-python
2+
23
Python client for the Yeti v2 API
4+
5+
[![Unit tests](https://github.com/yeti-platform/yeti-python/actions/workflows/unittests.yml/badge.svg)](https://github.com/yeti-platform/yeti-python/actions/workflows/unittests.yml)

tests/api.py

+24
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,30 @@ def test_error_message(self, mock_post):
295295
self.assertEqual(str(raised.exception), "error_message")
296296
self.assertEqual(raised.exception.status_code, 400)
297297

298+
@patch("yeti.api.requests.Session.post")
299+
def test_get_yara_bundle_with_overlays(self, mock_post):
300+
# Mock the YARA bundle response
301+
mock_response = MagicMock()
302+
mock_response.content = b'{"bundle": "bundlestring"}'
303+
mock_post.return_value = mock_response
304+
305+
# Call the method with overlays
306+
result = self.api.get_yara_bundle_with_overlays(
307+
overlays=["overlay1", "overlay2"]
308+
)
309+
310+
# Check the result
311+
self.assertEqual(result, {"bundle": "bundlestring"})
312+
mock_post.assert_called_with(
313+
"http://fake-url/api/v2/indicators/yara/bundle",
314+
json={
315+
"ids": [],
316+
"tags": [],
317+
"exclude_tags": [],
318+
"overlays": ["overlay1", "overlay2"],
319+
},
320+
)
321+
298322

299323
if __name__ == "__main__":
300324
unittest.main()

yeti/api.py

+39
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,45 @@ def patch_indicator(
274274
)
275275
return json.loads(response)
276276

277+
def get_yara_bundle_with_overlays(
278+
self,
279+
ids: list[str] | None = None,
280+
tags: list[str] | None = None,
281+
exclude_tags: list[str] | None = None,
282+
overlays: list[str] | None = None,
283+
) -> str:
284+
"""Gets a Yara bundle with overlays.
285+
286+
Args:
287+
ids: The list of IDs to include in the bundle.
288+
tags: Include Yara rules with this tag in the bundle.
289+
exclude_tags: Remove Yara rules with this tag from the bundle.
290+
overlays: The list of overlays to include in the bundle.
291+
"""
292+
if ids is None:
293+
ids = []
294+
if tags is None:
295+
tags = []
296+
if exclude_tags is None:
297+
exclude_tags = []
298+
if overlays is None:
299+
overlays = []
300+
301+
params = {
302+
"ids": ids,
303+
"tags": tags,
304+
"exclude_tags": exclude_tags,
305+
"overlays": overlays,
306+
}
307+
308+
result = self.do_request(
309+
"POST",
310+
f"{self._url_root}/api/v2/indicators/yara/bundle",
311+
json_data=params,
312+
)
313+
314+
return json.loads(result)
315+
277316
def search_dfiq(self, name: str, dfiq_type: str | None = None) -> list[YetiObject]:
278317
"""Searches for a DFIQ in Yeti.
279318

0 commit comments

Comments
 (0)