diff --git a/samples/test-search-template.py b/samples/test-search-template.py new file mode 100644 index 0000000..5527d26 --- /dev/null +++ b/samples/test-search-template.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import print_function +from __future__ import unicode_literals + +import sys +import json +from thehive4py.api import TheHiveApi +from thehive4py.models import CaseTemplate +from thehive4py.exceptions import CaseTemplateException +from thehive4py.query import * + +api = TheHiveApi('http://127.0.0.1:9000', 'JC7wGXWHi0XhvepKK1fBnP67d6JRjx0r') + +print('Search for case templates') +print('-----------------------------') + +response = api.find_case_templates(query=Eq("status", "Ok")) + +if response.status_code == 200: + print(json.dumps(response.json(), indent=4, sort_keys=True)) + print('') + +else: + print('ko: {}/{}'.format(response.status_code, response.text)) + sys.exit(0) diff --git a/tests/test_case.py b/tests/test_case.py index 096d394..25d9972 100644 --- a/tests/test_case.py +++ b/tests/test_case.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock from thehive4py.api import TheHiveApi @@ -37,3 +37,4 @@ def test_get_case(mock_get): assert mock_response.json.call_count == 1 assert case.id == test_id + diff --git a/thehive4py/api.py b/thehive4py/api.py index 6baeec4..0680889 100644 --- a/thehive4py/api.py +++ b/thehive4py/api.py @@ -315,6 +315,13 @@ def get_linked_cases(self, case_id): except requests.exceptions.RequestException as e: raise CaseException("Linked cases fetch error: {}".format(e)) + def find_case_templates(self, **attributes): + """ + :return: list of case templates + :rtype: json + """ + return self.__find_rows("/api/case/template/_search", **attributes) + def get_case_template(self, name): """