Ejemplo n.º 1
0
def report(request: Request, name: str):
    def load_value_of(key) -> str:
        may_val = load(key) or {}
        return may_val

    if "report_format_editor" in request.accepted_media_type:
        images = load_value_of("{}images".format(name))
        return Response({
            "template":
            load_value_of("{}html_template".format(name)),
            "vulnerability_report":
            load(name),
            "pdf_css":
            load_value_of("{}pdf_css".format(name)),
            "html_css":
            load_value_of("{}html_css".format(name)),
            "images":
            images,
        })
    data = load(name)
    if request.GET.get('without_overview'):
        # remove charts
        data.pop('overview', None)
    if request.META.get('HTTP_ACCEPT') == "application/xml":
        # XML needs exactly one root
        data = {'report': data}
    return Response(data)
Ejemplo n.º 2
0
def report(request: Request, name: str):
    def load_value_of(key) -> str:
        may_val = load(key) or {}
        return may_val

    if "report_format_editor" in request.accepted_media_type:
        images = load_value_of("{}images".format(name))
        return Response(
            {
                "template": load_value_of("{}html_template".format(name)),
                "vulnerability_report": load(name),
                "pdf_css": load_value_of("{}pdf_css".format(name)),
                "html_css": load_value_of("{}html_css".format(name)),
                "images": images,
            }
        )
    data = load(name)
    data["pheme_version"] = int("".join(filter(str.isdigit, __version__)))
    if request.GET.get("without_overview"):
        # remove charts
        data.pop("overview", None)
    if request.META.get("HTTP_ACCEPT") == "application/xml":
        # XML needs exactly one root
        data = {"report": data}
    return Response(data)
Ejemplo n.º 3
0
def store_cache(request):
    key = request.data.get("key", "unknown")
    data = request.data.get("value")
    if request.data.get("append"):
        if isinstance(data, dict):
            cached = load(key) or {}
            cached[data.get("name", "unknown")] = data.get("content")
            data = cached
    name = store(key, data, id_generator=str)
    return Response(name)
Ejemplo n.º 4
0
def store_cache(request):
    key = request.data.get("key", "unknown")
    data = request.data.get('value')
    if request.data.get('append'):
        if isinstance(data, dict):
            cached = load(key) or {}
            cached[data.get('name', 'unknown')] = data.get('content')
            data = cached
    name = store(key, data, id_generator=str)
    return Response(name)
Ejemplo n.º 5
0
 def load_value_of(key) -> str:
     may_val = load(key) or {}
     return may_val
Ejemplo n.º 6
0
def load_cache(request, key):
    return Response(load(key))