Unify Dashboard & Webhook events (#394)

This change unifies the previously adhoc SignalR events and Webhooks into a single event format.
This commit is contained in:
bmc-msft
2021-01-11 16:43:09 -05:00
committed by GitHub
parent 465727680d
commit 513d1f52c9
37 changed files with 2970 additions and 825 deletions

View File

@ -7,6 +7,7 @@ import json
import logging
from typing import Optional, Union
from memoization import cached
from onefuzztypes.models import Report
from onefuzztypes.primitives import Container
from pydantic import ValidationError
@ -16,7 +17,7 @@ from .azure.storage import StorageType
def parse_report(
content: Union[str, bytes], metadata: Optional[str] = None
content: Union[str, bytes], file_path: Optional[str] = None
) -> Optional[Report]:
if isinstance(content, bytes):
try:
@ -24,7 +25,7 @@ def parse_report(
except UnicodeDecodeError as err:
logging.error(
"unable to parse report (%s): unicode decode of report failed - %s",
metadata,
file_path,
err,
)
return None
@ -33,28 +34,30 @@ def parse_report(
data = json.loads(content)
except json.decoder.JSONDecodeError as err:
logging.error(
"unable to parse report (%s): json decoding failed - %s", metadata, err
"unable to parse report (%s): json decoding failed - %s", file_path, err
)
return None
try:
entry = Report.parse_obj(data)
except ValidationError as err:
logging.error("unable to parse report (%s): %s", metadata, err)
logging.error("unable to parse report (%s): %s", file_path, err)
return None
return entry
# cache the last 1000 reports
@cached(max_size=1000)
def get_report(container: Container, filename: str) -> Optional[Report]:
metadata = "/".join([container, filename])
file_path = "/".join([container, filename])
if not filename.endswith(".json"):
logging.error("get_report invalid extension: %s", metadata)
logging.error("get_report invalid extension: %s", file_path)
return None
blob = get_blob(container, filename, StorageType.corpus)
if blob is None:
logging.error("get_report invalid blob: %s", metadata)
logging.error("get_report invalid blob: %s", file_path)
return None
return parse_report(blob, metadata=metadata)
return parse_report(blob, file_path=file_path)