2020-09-10 15:26:34 +02:00
|
|
|
#!/usr/bin/env python3
|
2024-01-17 13:13:14 +01:00
|
|
|
|
|
|
|
from __future__ import annotations
|
2020-09-10 15:26:34 +02:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
2024-02-01 14:40:12 +01:00
|
|
|
def update_objects() -> None:
|
2020-09-10 15:26:34 +02:00
|
|
|
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))
|