Skip to content

Add function to get Yara bundles with overlays #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# yeti-python

Python client for the Yeti v2 API

[![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)
24 changes: 24 additions & 0 deletions tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,30 @@ def test_error_message(self, mock_post):
self.assertEqual(str(raised.exception), "error_message")
self.assertEqual(raised.exception.status_code, 400)

@patch("yeti.api.requests.Session.post")
def test_get_yara_bundle_with_overlays(self, mock_post):
# Mock the YARA bundle response
mock_response = MagicMock()
mock_response.content = b'{"bundle": "bundlestring"}'
mock_post.return_value = mock_response

# Call the method with overlays
result = self.api.get_yara_bundle_with_overlays(
overlays=["overlay1", "overlay2"]
)

# Check the result
self.assertEqual(result, {"bundle": "bundlestring"})
mock_post.assert_called_with(
"http://fake-url/api/v2/indicators/yara/bundle",
json={
"ids": [],
"tags": [],
"exclude_tags": [],
"overlays": ["overlay1", "overlay2"],
},
)


if __name__ == "__main__":
unittest.main()
39 changes: 39 additions & 0 deletions yeti/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,45 @@ def patch_indicator(
)
return json.loads(response)

def get_yara_bundle_with_overlays(
self,
ids: list[str] | None = None,
tags: list[str] | None = None,
exclude_tags: list[str] | None = None,
overlays: list[str] | None = None,
) -> str:
"""Gets a Yara bundle with overlays.

Args:
ids: The list of IDs to include in the bundle.
tags: Include Yara rules with this tag in the bundle.
exclude_tags: Remove Yara rules with this tag from the bundle.
overlays: The list of overlays to include in the bundle.
"""
if ids is None:
ids = []
if tags is None:
tags = []
if exclude_tags is None:
exclude_tags = []
if overlays is None:
overlays = []

params = {
"ids": ids,
"tags": tags,
"exclude_tags": exclude_tags,
"overlays": overlays,
}

result = self.do_request(
"POST",
f"{self._url_root}/api/v2/indicators/yara/bundle",
json_data=params,
)

return json.loads(result)

def search_dfiq(self, name: str, dfiq_type: str | None = None) -> list[YetiObject]:
"""Searches for a DFIQ in Yeti.

Expand Down