new: Add in ability to set a taxonomies required status

pull/860/head
Tom King 2022-09-14 10:29:38 +01:00
parent 795cc11881
commit b438c27b5e
2 changed files with 21 additions and 0 deletions

View File

@ -1191,6 +1191,17 @@ class PyMISP:
response = self._prepare_request('POST', 'taxonomies/update') response = self._prepare_request('POST', 'taxonomies/update')
return self._check_json_response(response) return self._check_json_response(response)
def set_taxonomy_required(self, taxonomy: Union[MISPTaxonomy, int, str], required: bool = False) -> Dict:
taxonomy_id = get_uuid_or_id_from_abstract_misp(taxonomy)
url = urljoin(self.root_url, 'taxonomies/toggleRequired/{}'.format(taxonomy_id))
payload = {
"Taxonomy": {
"required": required
}
}
response = self._prepare_request('POST', url, data=payload)
return self._check_json_response(response)
# ## END Taxonomies ### # ## END Taxonomies ###
# ## BEGIN Warninglists ### # ## BEGIN Warninglists ###

View File

@ -1657,6 +1657,16 @@ class TestComprehensive(unittest.TestCase):
r = self.admin_misp_connector.disable_taxonomy(tax) r = self.admin_misp_connector.disable_taxonomy(tax)
self.assertEqual(r['message'], 'Taxonomy disabled') self.assertEqual(r['message'], 'Taxonomy disabled')
# Test toggling the required status
r = self.admin_misp_connector.set_taxonomy_required(tax, not tax.required)
self.assertEqual(r['message'], 'Taxonomy toggleRequireded')
updatedTax = self.admin_misp_connector.get_taxonomy(tax, pythonify=True)
self.assertFalse(tax.required == updatedTax.required)
# Return back to default required status
r = self.admin_misp_connector.set_taxonomy_required(tax, not tax.required)
def test_warninglists(self): def test_warninglists(self):
# Make sure we're up-to-date # Make sure we're up-to-date
r = self.admin_misp_connector.update_warninglists() r = self.admin_misp_connector.update_warninglists()