mirror of https://github.com/MISP/PyMISP
parent
0947e5eabe
commit
a1326f2cf2
|
@ -880,6 +880,23 @@ class PyMISP:
|
|||
response = self._prepare_request('POST', f'tags/delete/{tag_id}')
|
||||
return self._check_json_response(response)
|
||||
|
||||
def search_tags(self, tag_name: str, pythonify: bool = False) -> Union[Dict, List[MISPTag]]:
|
||||
"""Search a tag by name.
|
||||
:param tag_name: Name (can be a part of it) to search
|
||||
"""
|
||||
r = self._prepare_request('GET', f'tags/index/searchall:{tag_name}')
|
||||
tag_r = self._check_json_response(r)
|
||||
if 'errors' in tag_r:
|
||||
return tag_r
|
||||
if not (self.global_pythonify or pythonify):
|
||||
return tag_r['Tag']
|
||||
to_return: List[MISPTag] = []
|
||||
for tag in tag_r['Tag']:
|
||||
t = MISPTag()
|
||||
t.from_dict(**tag)
|
||||
to_return.append(t)
|
||||
return to_return
|
||||
|
||||
# ## END Tags ###
|
||||
|
||||
# ## BEGIN Taxonomies ###
|
||||
|
|
|
@ -1338,6 +1338,14 @@ class TestComprehensive(unittest.TestCase):
|
|||
# Delete event
|
||||
self.admin_misp_connector.delete_event(first)
|
||||
|
||||
# Search tag
|
||||
# Partial search
|
||||
tags = self.admin_misp_connector.search_tags(new_tag.name[:5], pythonify=True)
|
||||
self.assertEqual(tags[0].name, 'this is a test tag')
|
||||
# No tags found
|
||||
tags = self.admin_misp_connector.search_tags('not a tag')
|
||||
self.assertFalse(tags)
|
||||
|
||||
# Delete tag
|
||||
response = self.admin_misp_connector.delete_tag(new_tag)
|
||||
self.assertEqual(response['message'], 'Tag deleted.')
|
||||
|
|
Loading…
Reference in New Issue