Exemple #1
0
from zipfile import ZipFile, ZIP_DEFLATED

from flask import Flask, jsonify, request, send_file, send_from_directory, abort
from karton.core import Producer, Task, Resource
from karton.core.task import TaskState
from minio.error import NoSuchKey

from drakcore.system import SystemService
from drakcore.util import get_config
from drakcore.analysis import AnalysisProxy
from drakcore.database import Database

app = Flask(__name__, static_folder="frontend/build/static")
conf = get_config()

backend = SystemService(conf).backend
minio = backend.minio
db = Database(
    conf.config["drakmon"].get("database",
                               "sqlite:///var/lib/drakcore/drakcore.db"),
    pathlib.Path(__file__).parent / "migrations",
)


@app.before_first_request
def update_metadata_cache():
    """ Scans whole MinIO bucket and fetch missing metadata files """
    for analysis in AnalysisProxy(minio, None).enumerate():
        try:
            get_analysis_metadata(analysis.uid)
        except NoSuchKey:
Exemple #2
0
from flask import Flask, jsonify, request, send_file, redirect, send_from_directory, Response, abort
from karton2 import Config, Producer, Resource, Task
from minio.error import NoSuchKey
from datetime import datetime
from time import mktime

from drakcore.system import SystemService
from drakcore.util import find_config


app = Flask(__name__, static_folder='frontend/build/static')
conf = Config(find_config())

drakmon_cfg = {k: v for k, v in conf.config.items("drakmon")}

rs = SystemService(conf).rs
minio = SystemService(conf).minio


@app.after_request
def add_header(response):
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response


@app.route("/list")
def route_list():
    analyses = []
    res = minio.list_objects_v2("drakrun")

    for obj in res: