Skip to content

Commit 842c180

Browse files
committed
Add support for tags in search_entities and update tests
1 parent 88702dd commit 842c180

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from yeti import errors
66
from yeti.api import YetiApi
77

8+
os.environ["YETI_ENDPOINT"] = "http://localhost:3000/"
9+
YETI_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoibWNwIiwic3ViIjoieWV0aSIsInNjb3BlcyI6WyJhbGwiXSwiY3JlYXRlZCI6IjIwMjUtMDYtMDJUMTk6NDI6MjcuNDcxNzA5WiIsImV4cCI6bnVsbCwibGFzdF91c2VkIjpudWxsLCJlbmFibGVkIjp0cnVlLCJleHBpcmVkIjpmYWxzZX0.qw6TlHkkxol--qjdOdnporlyYP0i2uJGgjzdKybpX2U"
10+
os.environ["YETI_API_KEY"] = YETI_API_KEY
11+
812

913
class YetiEndToEndTest(unittest.TestCase):
1014
def setUp(self):
@@ -60,6 +64,23 @@ def test_search_entities(self):
6064
self.assertEqual(result[0]["name"], "testSearch")
6165
self.assertEqual(result[0]["tags"][0]["name"], "testtag")
6266

67+
def test_search_entities_with_tags(self):
68+
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
69+
self.api.new_entity(
70+
{
71+
"name": "testSearchWithTags",
72+
"type": "malware",
73+
"description": "test",
74+
},
75+
tags=["testtag1", "testtag2"],
76+
)
77+
time.sleep(5)
78+
result = self.api.search_entities(
79+
name="testSear", description="tes", tags=["testtag1"]
80+
)
81+
self.assertEqual(len(result), 1, result)
82+
self.assertEqual(result[0]["name"], "testSearchWithTags")
83+
6384
def test_get_multiple_entities(self):
6485
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
6586
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)