Skip to content

Commit 9211e27

Browse files
authored
Merge pull request #18 from yeti-platform/entitysearch_tag
Add support for tags in search_entities and update tests
2 parents 88702dd + e8aa9dd commit 9211e27

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "yeti-python"
3-
version = "2.0.8"
3+
version = "2.1.0"
44
description = "Python bindings for the Yeti API"
55
authors = ["tomchop"]
66
license = "Apache"

tests/api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,17 @@ def test_search_entities(self, mock_post):
6666
mock_post.return_value = mock_response
6767

6868
result = self.api.search_entities(
69-
name="test_entity", description="test_description"
69+
name="test_entity", description="test_description", tags=["tag1"]
7070
)
7171
self.assertEqual(result, [{"name": "test_entity"}])
7272
mock_post.assert_called_with(
7373
"http://fake-url/api/v2/entities/search",
7474
json={
75-
"query": {"name": "test_entity", "description": "test_description"},
75+
"query": {
76+
"name": "test_entity",
77+
"description": "test_description",
78+
"tags": ["tag1"],
79+
},
7680
"count": 100,
7781
"page": 0,
7882
},

tests/e2e.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ def test_search_entities(self):
6060
self.assertEqual(result[0]["name"], "testSearch")
6161
self.assertEqual(result[0]["tags"][0]["name"], "testtag")
6262

63+
def test_search_entities_with_tags(self):
64+
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
65+
self.api.new_entity(
66+
{
67+
"name": "testSearchWithTags",
68+
"type": "malware",
69+
"description": "test",
70+
},
71+
tags=["testtag1", "testtag2"],
72+
)
73+
time.sleep(5)
74+
result = self.api.search_entities(
75+
name="testSear", description="tes", tags=["testtag1"]
76+
)
77+
self.assertEqual(len(result), 1, result)
78+
self.assertEqual(result[0]["name"], "testSearchWithTags")
79+
6380
def test_get_multiple_entities(self):
6481
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
6582
self.api.new_entity(

yeti/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def search_indicators(
224224
pattern: The pattern of the indicator to search for.
225225
description: The description of the indicator to search for. (substring match)
226226
tags: The tags of the indicator to search for.
227+
count: The number of results to return (default is 100, which means all).
228+
page: The page of results to return (default is 0, which means the first page).
227229
228230
Returns:
229231
The response from the API; a list of dicts representing indicators.
@@ -299,6 +301,7 @@ def search_entities(
299301
name: str | None = None,
300302
entity_type: str | None = None,
301303
description: str | None = None,
304+
tags: list[str] | None = None,
302305
count: int = 100,
303306
page: int = 0,
304307
) -> list[YetiObject]:
@@ -310,6 +313,7 @@ def search_entities(
310313
name: The name of the entity to search for (substring match).
311314
entity_type: The type of the entity to search for.
312315
description: The description of the entity to search for. (substring match)
316+
tags: The tags of the entity to search for.
313317
count: The number of results to return (default is 100, which means all).
314318
page: The page of results to return (default is 0, which means the first page).
315319
@@ -326,6 +330,8 @@ def search_entities(
326330
query["type"] = entity_type
327331
if description:
328332
query["description"] = description
333+
if tags:
334+
query["tags"] = tags
329335

330336
params = {"query": query, "count": count, "page": page}
331337
response = self.do_request(

0 commit comments

Comments
 (0)