Skip to content

Commit b5e5143

Browse files
authored
Merge pull request #12 from yeti-platform/bloom
Add bloom search endpoint
2 parents 3f393bb + 61cbd9c commit b5e5143

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/api.py

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ def test_search_observables(self, mock_post):
6262
json={"query": {"value": "test_value"}, "count": 0},
6363
)
6464

65+
@patch("yeti.api.requests.Session.post")
66+
def test_search_bloom(self, mock_post):
67+
mock_response = MagicMock()
68+
mock_response.content = b'[{"value": "test.com", "hits": ["filter1"]}]'
69+
mock_post.return_value = mock_response
70+
71+
result = self.api.search_bloom(["test.com"])
72+
self.assertEqual(result, [{"value": "test.com", "hits": ["filter1"]}])
73+
mock_post.assert_called_with(
74+
"http://fake-url/api/v2/bloom/search",
75+
json={"values": ["test.com"]},
76+
)
77+
6578
@patch("yeti.api.requests.Session.post")
6679
def test_new_entity(self, mock_post):
6780
mock_response = MagicMock()

yeti/api.py

+17
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,23 @@ def search_observables(self, value: str) -> list[YetiObject]:
212212
)
213213
return json.loads(response)["observables"]
214214

215+
def search_bloom(self, values: list[str]) -> list[dict[str, Any]]:
216+
"""Searches for a list of observable values in Yeti's bloom filters.
217+
218+
Args:
219+
values: The list of observable values to search for.
220+
221+
Returns:
222+
A list of dicts representing hits, e.g.
223+
224+
{"value": "example.com", hits:["filter1"]}
225+
"""
226+
params = {"values": values}
227+
response = self.do_request(
228+
"POST", f"{self._url_root}/api/v2/bloom/search", json_data=params
229+
)
230+
return json.loads(response)
231+
215232
def new_entity(
216233
self, entity: dict[str, Any], tags: list[str] | None = None
217234
) -> YetiObject:

0 commit comments

Comments
 (0)