Skip to content

Commit

Permalink
new: Method to get the new version of the templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Sep 10, 2020
1 parent e3815a4 commit 9c48079
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions pymisp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .tools import stix # noqa
from .tools import openioc # noqa
from .tools import ext_lookups # noqa
from .tools import update_objects # noqa

from .api import PyMISP, register_user # noqa
from .api import PyMISP as ExpandedPyMISP # noqa
Expand Down
1 change: 1 addition & 0 deletions pymisp/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .csvloader import CSVLoader # noqa
from .sshauthkeyobject import SSHAuthorizedKeysObject # noqa
from .feed import feed_meta_generator # noqa
from .update_objects import update_objects # noqa
try:
from .urlobject import URLObject # noqa
except ImportError:
Expand Down
29 changes: 29 additions & 0 deletions pymisp/tools/update_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import zipfile
from io import BytesIO
from pathlib import Path

import requests

from ..abstract import resources_path

static_repo = "https://github.com/MISP/misp-objects/archive/main.zip"


def update_objects():
r = requests.get(static_repo)

zipped_repo = BytesIO(r.content)

with zipfile.ZipFile(zipped_repo, 'r') as myzip:
for name in myzip.namelist():
if not name.endswith('.json'):
continue
name_on_disk = name.replace('misp-objects-main', 'misp-objects')
path = resources_path / Path(name_on_disk)
if not path.parent.exists():
path.parent.mkdir(parents=True)
with path.open('wb') as f:
f.write(myzip.read(name))

0 comments on commit 9c48079

Please sign in to comment.