From 133771d7c44990626386260a0ee8dbe8ae1169c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 25 Jan 2018 17:54:01 +0100 Subject: [PATCH] new: Allow to pass a list of WarningLists (in dict) as parameter --- pymispwarninglists/api.py | 16 ++++++++++------ setup.py | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pymispwarninglists/api.py b/pymispwarninglists/api.py index 36289c5..e901ad5 100644 --- a/pymispwarninglists/api.py +++ b/pymispwarninglists/api.py @@ -108,16 +108,20 @@ class WarningList(): class WarningLists(collections.Mapping): - def __init__(self, slow_search=False): + def __init__(self, slow_search=False, lists=False): """Load all the warning lists from the package. :slow_search: If true, uses the most appropriate search method. Can be slower. Default: exact match. + :lists: A list of warning lists (typically fetched from a MISP instance) """ - self.root_dir_warninglists = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pymispwarninglists'].__file__)), - 'data', 'misp-warninglists', 'lists') + if not lists: + lists = [] + self.root_dir_warninglists = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pymispwarninglists'].__file__)), + 'data', 'misp-warninglists', 'lists') + for warninglist_file in glob(os.path.join(self.root_dir_warninglists, '*', 'list.json')): + with open(warninglist_file, 'r') as f: + lists.append(json.load(f)) self.warninglists = {} - for warninglist_file in glob(os.path.join(self.root_dir_warninglists, '*', 'list.json')): - with open(warninglist_file, 'r') as f: - warninglist = json.load(f) + for warninglist in lists: self.warninglists[warninglist['name']] = WarningList(warninglist, slow_search) def validate_with_schema(self): diff --git a/setup.py b/setup.py index dbee024..89d9563 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='pymispwarninglists', - version='0.1', + version='0.2', author='Raphaël Vinot', author_email='raphael.vinot@circl.lu', maintainer='Raphaël Vinot',