From b499b9b17d46c2e48a5f4477a308cfdadd92bf56 Mon Sep 17 00:00:00 2001 From: bmc-msft <41130664+bmc-msft@users.noreply.github.com> Date: Thu, 21 Jan 2021 05:31:02 -0500 Subject: [PATCH] always set SignalR events at the end of handlers (#445) Addresses an issue where events meant for SignalR do not get sent to the service when an App Service instance spins down before a timer event fires. --- .../__app__/agent_can_schedule/__init__.py | 11 ++++- .../__app__/agent_can_schedule/function.json | 42 +++++++++------- .../__app__/agent_commands/__init__.py | 11 ++++- .../__app__/agent_commands/function.json | 46 ++++++++++-------- .../__app__/agent_events/__init__.py | 11 ++++- .../__app__/agent_events/function.json | 44 +++++++++-------- .../__app__/agent_registration/__init__.py | 11 ++++- .../__app__/agent_registration/function.json | 46 ++++++++++-------- .../__app__/containers/__init__.py | 11 ++++- .../__app__/containers/function.json | 8 +++- src/api-service/__app__/download/__init__.py | 11 ++++- .../__app__/download/function.json | 42 +++++++++------- src/api-service/__app__/info/__init__.py | 11 ++++- src/api-service/__app__/info/function.json | 42 +++++++++------- .../__app__/job_templates/__init__.py | 11 ++++- .../__app__/job_templates/function.json | 8 +++- .../__app__/job_templates_manage/__init__.py | 11 ++++- .../job_templates_manage/function.json | 8 +++- src/api-service/__app__/jobs/__init__.py | 11 ++++- src/api-service/__app__/jobs/function.json | 8 +++- .../__app__/negotiate/function.json | 2 +- src/api-service/__app__/node/__init__.py | 11 ++++- src/api-service/__app__/node/function.json | 48 +++++++++++-------- .../__app__/node_add_ssh_key/__init__.py | 17 +++++-- .../__app__/node_add_ssh_key/function.json | 44 +++++++++-------- .../__app__/notifications/__init__.py | 11 ++++- .../__app__/notifications/function.json | 8 +++- src/api-service/__app__/pool/__init__.py | 11 ++++- src/api-service/__app__/pool/function.json | 48 +++++++++++-------- src/api-service/__app__/proxy/__init__.py | 11 ++++- src/api-service/__app__/proxy/function.json | 48 +++++++++++-------- .../__app__/proxy_notification/function.json | 34 ++++++------- .../__app__/queue_file_changes/function.json | 34 ++++++------- .../queue_node_heartbeat/function.json | 34 ++++++------- .../queue_task_heartbeat/function.json | 34 ++++++------- .../__app__/queue_updates/function.json | 34 ++++++------- .../__app__/queue_webhooks/__init__.py | 7 ++- .../__app__/queue_webhooks/function.json | 28 ++++++----- src/api-service/__app__/repro_vms/__init__.py | 11 ++++- .../__app__/repro_vms/function.json | 8 +++- src/api-service/__app__/scaleset/__init__.py | 11 ++++- .../__app__/scaleset/function.json | 48 +++++++++++-------- src/api-service/__app__/tasks/__init__.py | 12 +++-- src/api-service/__app__/tasks/function.json | 8 +++- .../__app__/timer_daily/__init__.py | 7 ++- .../__app__/timer_daily/function.json | 26 ++++++---- .../__app__/timer_proxy/function.json | 32 ++++++------- .../__app__/timer_repro/function.json | 2 +- .../__app__/timer_tasks/function.json | 32 ++++++------- src/api-service/__app__/webhooks/__init__.py | 11 ++++- .../__app__/webhooks/function.json | 8 +++- .../__app__/webhooks_logs/__init__.py | 11 ++++- .../__app__/webhooks_logs/function.json | 8 +++- .../__app__/webhooks_ping/__init__.py | 11 ++++- .../__app__/webhooks_ping/function.json | 8 +++- 55 files changed, 708 insertions(+), 414 deletions(-) diff --git a/src/api-service/__app__/agent_can_schedule/__init__.py b/src/api-service/__app__/agent_can_schedule/__init__.py index b1b74343e..36e12d3f7 100644 --- a/src/api-service/__app__/agent_can_schedule/__init__.py +++ b/src/api-service/__app__/agent_can_schedule/__init__.py @@ -10,6 +10,7 @@ from onefuzztypes.requests import CanScheduleRequest from onefuzztypes.responses import CanSchedule from ..onefuzzlib.endpoint_authorization import call_if_agent +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Node from ..onefuzzlib.request import not_ok, ok, parse_request from ..onefuzzlib.tasks.main import Task @@ -42,7 +43,13 @@ def post(req: func.HttpRequest) -> func.HttpResponse: return ok(CanSchedule(allowed=allowed, work_stopped=work_stopped)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"POST": post} method = methods[req.method] - return call_if_agent(req, method) + result = call_if_agent(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/agent_can_schedule/function.json b/src/api-service/__app__/agent_can_schedule/function.json index dddca408d..2e6ddb9cb 100644 --- a/src/api-service/__app__/agent_can_schedule/function.json +++ b/src/api-service/__app__/agent_can_schedule/function.json @@ -1,20 +1,26 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "post" - ], - "route": "agents/can_schedule" - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "post" + ], + "route": "agents/can_schedule" + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] } diff --git a/src/api-service/__app__/agent_commands/__init__.py b/src/api-service/__app__/agent_commands/__init__.py index 09504e052..89af2de27 100644 --- a/src/api-service/__app__/agent_commands/__init__.py +++ b/src/api-service/__app__/agent_commands/__init__.py @@ -9,6 +9,7 @@ from onefuzztypes.requests import NodeCommandDelete, NodeCommandGet from onefuzztypes.responses import BoolResult, PendingNodeCommand from ..onefuzzlib.endpoint_authorization import call_if_agent +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import NodeMessage from ..onefuzzlib.request import not_ok, ok, parse_request @@ -42,7 +43,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=True)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"DELETE": delete, "GET": get} method = methods[req.method] - return call_if_agent(req, method) + result = call_if_agent(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/agent_commands/function.json b/src/api-service/__app__/agent_commands/function.json index 7821c38fa..3130d6f5b 100644 --- a/src/api-service/__app__/agent_commands/function.json +++ b/src/api-service/__app__/agent_commands/function.json @@ -1,22 +1,28 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post", - "delete" - ], - "route": "agents/commands" - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post", + "delete" + ], + "route": "agents/commands" + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] } diff --git a/src/api-service/__app__/agent_events/__init__.py b/src/api-service/__app__/agent_events/__init__.py index f71c949f3..fe5172ea4 100644 --- a/src/api-service/__app__/agent_events/__init__.py +++ b/src/api-service/__app__/agent_events/__init__.py @@ -18,6 +18,7 @@ from onefuzztypes.responses import BoolResult from ..onefuzzlib.agent_events import on_state_update, on_worker_event from ..onefuzzlib.endpoint_authorization import call_if_agent +from ..onefuzzlib.events import get_events from ..onefuzzlib.request import not_ok, ok, parse_request @@ -71,7 +72,13 @@ def post(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=True)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"POST": post} method = methods[req.method] - return call_if_agent(req, method) + result = call_if_agent(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/agent_events/function.json b/src/api-service/__app__/agent_events/function.json index 95958727d..a87735265 100644 --- a/src/api-service/__app__/agent_events/function.json +++ b/src/api-service/__app__/agent_events/function.json @@ -1,20 +1,26 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "post" - ], - "route": "agents/events" - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "post" + ], + "route": "agents/events" + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/agent_registration/__init__.py b/src/api-service/__app__/agent_registration/__init__.py index 522836473..5422a8b56 100644 --- a/src/api-service/__app__/agent_registration/__init__.py +++ b/src/api-service/__app__/agent_registration/__init__.py @@ -17,6 +17,7 @@ from ..onefuzzlib.azure.creds import get_instance_url from ..onefuzzlib.azure.queue import get_queue_sas from ..onefuzzlib.azure.storage import StorageType from ..onefuzzlib.endpoint_authorization import call_if_agent +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Node, NodeMessage, NodeTasks, Pool from ..onefuzzlib.request import not_ok, ok, parse_uri @@ -116,7 +117,13 @@ def post(req: func.HttpRequest) -> func.HttpResponse: return create_registration_response(node.machine_id, pool) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"POST": post, "GET": get} method = methods[req.method] - return call_if_agent(req, method) + result = call_if_agent(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/agent_registration/function.json b/src/api-service/__app__/agent_registration/function.json index de53d557c..944c3d8d5 100644 --- a/src/api-service/__app__/agent_registration/function.json +++ b/src/api-service/__app__/agent_registration/function.json @@ -1,22 +1,28 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post", - "delete" - ], - "route": "agents/registration" - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post", + "delete" + ], + "route": "agents/registration" + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] } diff --git a/src/api-service/__app__/containers/__init__.py b/src/api-service/__app__/containers/__init__.py index 4bd86236c..bbfeb355f 100644 --- a/src/api-service/__app__/containers/__init__.py +++ b/src/api-service/__app__/containers/__init__.py @@ -21,6 +21,7 @@ from ..onefuzzlib.azure.containers import ( ) from ..onefuzzlib.azure.storage import StorageType from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.request import not_ok, ok, parse_request @@ -89,7 +90,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=delete_container(request.name, StorageType.corpus))) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/containers/function.json b/src/api-service/__app__/containers/function.json index 4507dd368..2b8c019c4 100644 --- a/src/api-service/__app__/containers/function.json +++ b/src/api-service/__app__/containers/function.json @@ -16,6 +16,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/download/__init__.py b/src/api-service/__app__/download/__init__.py index 95390ccb0..18477061b 100644 --- a/src/api-service/__app__/download/__init__.py +++ b/src/api-service/__app__/download/__init__.py @@ -14,6 +14,7 @@ from ..onefuzzlib.azure.containers import ( ) from ..onefuzzlib.azure.storage import StorageType from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.request import not_ok, parse_uri, redirect @@ -46,7 +47,13 @@ def get(req: func.HttpRequest) -> func.HttpResponse: ) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/download/function.json b/src/api-service/__app__/download/function.json index 8d9664d6d..f0740808c 100644 --- a/src/api-service/__app__/download/function.json +++ b/src/api-service/__app__/download/function.json @@ -1,19 +1,25 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/info/__init__.py b/src/api-service/__app__/info/__init__.py index 890765408..6c41ebd4e 100644 --- a/src/api-service/__app__/info/__init__.py +++ b/src/api-service/__app__/info/__init__.py @@ -14,12 +14,13 @@ from ..onefuzzlib.azure.creds import ( get_instance_id, get_subscription, ) +from ..onefuzzlib.events import get_events from ..onefuzzlib.request import ok from ..onefuzzlib.versions import versions -def main(req: func.HttpRequest) -> func.HttpResponse: - return ok( +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: + response = ok( Info( resource_group=get_base_resource_group(), region=get_base_region(), @@ -30,3 +31,9 @@ def main(req: func.HttpRequest) -> func.HttpResponse: insights_instrumentation_key=get_insights_instrumentation_key(), ) ) + + events = get_events() + if events: + dashboard.set(events) + + return response diff --git a/src/api-service/__app__/info/function.json b/src/api-service/__app__/info/function.json index 8d9664d6d..f0740808c 100644 --- a/src/api-service/__app__/info/function.json +++ b/src/api-service/__app__/info/function.json @@ -1,19 +1,25 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/job_templates/__init__.py b/src/api-service/__app__/job_templates/__init__.py index dbdb1d7a4..a5af4459c 100644 --- a/src/api-service/__app__/job_templates/__init__.py +++ b/src/api-service/__app__/job_templates/__init__.py @@ -8,6 +8,7 @@ from onefuzztypes.job_templates import JobTemplateRequest from onefuzztypes.models import Error from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.job_templates.templates import JobTemplateIndex from ..onefuzzlib.request import not_ok, ok, parse_request from ..onefuzzlib.user_credentials import parse_jwt_token @@ -34,7 +35,13 @@ def post(req: func.HttpRequest) -> func.HttpResponse: return ok(job) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/job_templates/function.json b/src/api-service/__app__/job_templates/function.json index 4667f0aca..635c311aa 100644 --- a/src/api-service/__app__/job_templates/function.json +++ b/src/api-service/__app__/job_templates/function.json @@ -15,6 +15,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/job_templates_manage/__init__.py b/src/api-service/__app__/job_templates_manage/__init__.py index b94ef5238..9678c0e15 100644 --- a/src/api-service/__app__/job_templates_manage/__init__.py +++ b/src/api-service/__app__/job_templates_manage/__init__.py @@ -14,6 +14,7 @@ from onefuzztypes.models import Error from onefuzztypes.responses import BoolResult from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.job_templates.templates import JobTemplateIndex from ..onefuzzlib.request import not_ok, ok, parse_request @@ -61,7 +62,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=entry is not None)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/job_templates_manage/function.json b/src/api-service/__app__/job_templates_manage/function.json index 57d1baecc..de21b9065 100644 --- a/src/api-service/__app__/job_templates_manage/function.json +++ b/src/api-service/__app__/job_templates_manage/function.json @@ -17,6 +17,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/jobs/__init__.py b/src/api-service/__app__/jobs/__init__.py index 53c2edede..d07e6a982 100644 --- a/src/api-service/__app__/jobs/__init__.py +++ b/src/api-service/__app__/jobs/__init__.py @@ -9,6 +9,7 @@ from onefuzztypes.models import Error, JobConfig, JobTaskInfo from onefuzztypes.requests import JobGet, JobSearch from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.jobs import Job from ..onefuzzlib.request import not_ok, ok, parse_request from ..onefuzzlib.tasks.main import Task @@ -74,7 +75,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(job) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/jobs/function.json b/src/api-service/__app__/jobs/function.json index 4507dd368..2b8c019c4 100644 --- a/src/api-service/__app__/jobs/function.json +++ b/src/api-service/__app__/jobs/function.json @@ -16,6 +16,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/negotiate/function.json b/src/api-service/__app__/negotiate/function.json index 712b2684d..4bea9bf59 100644 --- a/src/api-service/__app__/negotiate/function.json +++ b/src/api-service/__app__/negotiate/function.json @@ -22,4 +22,4 @@ "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/node/__init__.py b/src/api-service/__app__/node/__init__.py index 5460fd9e0..e6beef9e8 100644 --- a/src/api-service/__app__/node/__init__.py +++ b/src/api-service/__app__/node/__init__.py @@ -10,6 +10,7 @@ from onefuzztypes.requests import NodeGet, NodeSearch, NodeUpdate from onefuzztypes.responses import BoolResult from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Node, NodeTasks from ..onefuzzlib.request import not_ok, ok, parse_request @@ -100,7 +101,13 @@ def patch(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=True)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "PATCH": patch, "DELETE": delete, "POST": post} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/node/function.json b/src/api-service/__app__/node/function.json index 6e8ff8d50..5b32b5a58 100644 --- a/src/api-service/__app__/node/function.json +++ b/src/api-service/__app__/node/function.json @@ -1,22 +1,28 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "patch", - "delete", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "patch", + "delete", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/node_add_ssh_key/__init__.py b/src/api-service/__app__/node_add_ssh_key/__init__.py index 9bb4fdb3f..fb1aaf055 100644 --- a/src/api-service/__app__/node_add_ssh_key/__init__.py +++ b/src/api-service/__app__/node_add_ssh_key/__init__.py @@ -9,6 +9,8 @@ from onefuzztypes.models import Error from onefuzztypes.requests import NodeAddSshKey from onefuzztypes.responses import BoolResult +from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Node from ..onefuzzlib.request import not_ok, ok, parse_request @@ -31,8 +33,13 @@ def post(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=True)) -def main(req: func.HttpRequest) -> func.HttpResponse: - if req.method == "POST": - return post(req) - else: - raise Exception("invalid method") +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: + methods = {"POST": post} + method = methods[req.method] + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/node_add_ssh_key/function.json b/src/api-service/__app__/node_add_ssh_key/function.json index f5977b40d..8fb087ef7 100644 --- a/src/api-service/__app__/node_add_ssh_key/function.json +++ b/src/api-service/__app__/node_add_ssh_key/function.json @@ -1,20 +1,26 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "post" - ], - "route": "node/add_ssh_key" - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "post" + ], + "route": "node/add_ssh_key" + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/notifications/__init__.py b/src/api-service/__app__/notifications/__init__.py index 4acfd946c..c38d5b646 100644 --- a/src/api-service/__app__/notifications/__init__.py +++ b/src/api-service/__app__/notifications/__init__.py @@ -10,6 +10,7 @@ from onefuzztypes.models import Error from onefuzztypes.requests import NotificationCreate, NotificationGet from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.notifications.main import Notification from ..onefuzzlib.request import not_ok, ok, parse_request @@ -49,7 +50,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(entry) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/notifications/function.json b/src/api-service/__app__/notifications/function.json index 4507dd368..2b8c019c4 100644 --- a/src/api-service/__app__/notifications/function.json +++ b/src/api-service/__app__/notifications/function.json @@ -16,6 +16,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/pool/__init__.py b/src/api-service/__app__/pool/__init__.py index b2f45f60a..4160aa7eb 100644 --- a/src/api-service/__app__/pool/__init__.py +++ b/src/api-service/__app__/pool/__init__.py @@ -22,6 +22,7 @@ from ..onefuzzlib.azure.queue import get_queue_sas from ..onefuzzlib.azure.storage import StorageType from ..onefuzzlib.azure.vmss import list_available_skus from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Pool from ..onefuzzlib.request import not_ok, ok, parse_request @@ -131,7 +132,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=True)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/pool/function.json b/src/api-service/__app__/pool/function.json index 719a2ca47..7065b64e0 100644 --- a/src/api-service/__app__/pool/function.json +++ b/src/api-service/__app__/pool/function.json @@ -1,22 +1,28 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post", - "delete", - "patch" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post", + "delete", + "patch" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/proxy/__init__.py b/src/api-service/__app__/proxy/__init__.py index cbfc88b6f..d4bdea682 100644 --- a/src/api-service/__app__/proxy/__init__.py +++ b/src/api-service/__app__/proxy/__init__.py @@ -12,6 +12,7 @@ from onefuzztypes.requests import ProxyCreate, ProxyDelete, ProxyGet, ProxyReset from onefuzztypes.responses import BoolResult, ProxyGetResult from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Scaleset from ..onefuzzlib.proxy import Proxy from ..onefuzzlib.proxy_forward import ProxyForward @@ -114,7 +115,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=True)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete, "PATCH": patch} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/proxy/function.json b/src/api-service/__app__/proxy/function.json index 719a2ca47..7065b64e0 100644 --- a/src/api-service/__app__/proxy/function.json +++ b/src/api-service/__app__/proxy/function.json @@ -1,22 +1,28 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post", - "delete", - "patch" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post", + "delete", + "patch" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/proxy_notification/function.json b/src/api-service/__app__/proxy_notification/function.json index af444d70d..5abb803ea 100644 --- a/src/api-service/__app__/proxy_notification/function.json +++ b/src/api-service/__app__/proxy_notification/function.json @@ -1,18 +1,18 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "name": "msg", - "type": "queueTrigger", - "direction": "in", - "queueName": "proxy", - "connection": "AzureWebJobsStorage" - }, - { - "type": "signalR", - "direction": "out", - "name": "dashboard", - "hubName": "dashboard" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msg", + "type": "queueTrigger", + "direction": "in", + "queueName": "proxy", + "connection": "AzureWebJobsStorage" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/queue_file_changes/function.json b/src/api-service/__app__/queue_file_changes/function.json index bab03837f..bef4a9c04 100644 --- a/src/api-service/__app__/queue_file_changes/function.json +++ b/src/api-service/__app__/queue_file_changes/function.json @@ -1,18 +1,18 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "name": "msg", - "type": "queueTrigger", - "direction": "in", - "queueName": "file-changes", - "connection": "AzureWebJobsStorage" - }, - { - "type": "signalR", - "direction": "out", - "name": "dashboard", - "hubName": "dashboard" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msg", + "type": "queueTrigger", + "direction": "in", + "queueName": "file-changes", + "connection": "AzureWebJobsStorage" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/queue_node_heartbeat/function.json b/src/api-service/__app__/queue_node_heartbeat/function.json index 938997ee0..0fc9d7b5e 100644 --- a/src/api-service/__app__/queue_node_heartbeat/function.json +++ b/src/api-service/__app__/queue_node_heartbeat/function.json @@ -1,18 +1,18 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "name": "msg", - "type": "queueTrigger", - "direction": "in", - "queueName": "node-heartbeat", - "connection": "AzureWebJobsStorage" - }, - { - "type": "signalR", - "direction": "out", - "name": "dashboard", - "hubName": "dashboard" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msg", + "type": "queueTrigger", + "direction": "in", + "queueName": "node-heartbeat", + "connection": "AzureWebJobsStorage" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/queue_task_heartbeat/function.json b/src/api-service/__app__/queue_task_heartbeat/function.json index 6acb7d870..94424ec01 100644 --- a/src/api-service/__app__/queue_task_heartbeat/function.json +++ b/src/api-service/__app__/queue_task_heartbeat/function.json @@ -1,18 +1,18 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "name": "msg", - "type": "queueTrigger", - "direction": "in", - "queueName": "task-heartbeat", - "connection": "AzureWebJobsStorage" - }, - { - "type": "signalR", - "direction": "out", - "name": "dashboard", - "hubName": "dashboard" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msg", + "type": "queueTrigger", + "direction": "in", + "queueName": "task-heartbeat", + "connection": "AzureWebJobsStorage" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/queue_updates/function.json b/src/api-service/__app__/queue_updates/function.json index 7cb35f36d..a39c9820c 100644 --- a/src/api-service/__app__/queue_updates/function.json +++ b/src/api-service/__app__/queue_updates/function.json @@ -1,18 +1,18 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "name": "msg", - "type": "queueTrigger", - "direction": "in", - "queueName": "update-queue", - "connection": "AzureWebJobsStorage" - }, - { - "type": "signalR", - "direction": "out", - "name": "dashboard", - "hubName": "dashboard" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msg", + "type": "queueTrigger", + "direction": "in", + "queueName": "update-queue", + "connection": "AzureWebJobsStorage" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/queue_webhooks/__init__.py b/src/api-service/__app__/queue_webhooks/__init__.py index 61aaa2581..d81abfe01 100644 --- a/src/api-service/__app__/queue_webhooks/__init__.py +++ b/src/api-service/__app__/queue_webhooks/__init__.py @@ -7,10 +7,15 @@ import json import azure.functions as func +from ..onefuzzlib.events import get_events from ..onefuzzlib.webhooks import WebhookMessageLog, WebhookMessageQueueObj -def main(msg: func.QueueMessage) -> None: +def main(msg: func.QueueMessage, dashboard: func.Out[str]) -> None: body = msg.get_body() obj = WebhookMessageQueueObj.parse_obj(json.loads(body)) WebhookMessageLog.process_from_queue(obj) + + events = get_events() + if events: + dashboard.set(events) diff --git a/src/api-service/__app__/queue_webhooks/function.json b/src/api-service/__app__/queue_webhooks/function.json index df691c8e1..12a3b0799 100644 --- a/src/api-service/__app__/queue_webhooks/function.json +++ b/src/api-service/__app__/queue_webhooks/function.json @@ -1,12 +1,18 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "name": "msg", - "type": "queueTrigger", - "direction": "in", - "queueName": "webhooks", - "connection": "AzureWebJobsStorage" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msg", + "type": "queueTrigger", + "direction": "in", + "queueName": "webhooks", + "connection": "AzureWebJobsStorage" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/repro_vms/__init__.py b/src/api-service/__app__/repro_vms/__init__.py index 99269f00b..f9d474a87 100644 --- a/src/api-service/__app__/repro_vms/__init__.py +++ b/src/api-service/__app__/repro_vms/__init__.py @@ -9,6 +9,7 @@ from onefuzztypes.models import Error, ReproConfig from onefuzztypes.requests import ReproGet from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.repro import Repro from ..onefuzzlib.request import not_ok, ok, parse_request from ..onefuzzlib.user_credentials import parse_jwt_token @@ -73,7 +74,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(vm) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/repro_vms/function.json b/src/api-service/__app__/repro_vms/function.json index 4507dd368..2b8c019c4 100644 --- a/src/api-service/__app__/repro_vms/function.json +++ b/src/api-service/__app__/repro_vms/function.json @@ -16,6 +16,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/scaleset/__init__.py b/src/api-service/__app__/scaleset/__init__.py index 584a1b36f..8f5e955a8 100644 --- a/src/api-service/__app__/scaleset/__init__.py +++ b/src/api-service/__app__/scaleset/__init__.py @@ -17,6 +17,7 @@ from onefuzztypes.responses import BoolResult from ..onefuzzlib.azure.creds import get_base_region, get_regions from ..onefuzzlib.azure.vmss import list_available_skus from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Pool, Scaleset from ..onefuzzlib.request import not_ok, ok, parse_request @@ -143,7 +144,13 @@ def patch(req: func.HttpRequest) -> func.HttpResponse: return ok(scaleset) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete, "PATCH": patch} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/scaleset/function.json b/src/api-service/__app__/scaleset/function.json index 719a2ca47..7065b64e0 100644 --- a/src/api-service/__app__/scaleset/function.json +++ b/src/api-service/__app__/scaleset/function.json @@ -1,22 +1,28 @@ { - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post", - "delete", - "patch" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} \ No newline at end of file + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post", + "delete", + "patch" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ] +} diff --git a/src/api-service/__app__/tasks/__init__.py b/src/api-service/__app__/tasks/__init__.py index e9fd24c3c..685df7781 100644 --- a/src/api-service/__app__/tasks/__init__.py +++ b/src/api-service/__app__/tasks/__init__.py @@ -3,7 +3,6 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# import logging import azure.functions as func from onefuzztypes.enums import ErrorCode, JobState from onefuzztypes.models import Error, TaskConfig @@ -11,6 +10,7 @@ from onefuzztypes.requests import TaskGet, TaskSearch from onefuzztypes.responses import BoolResult from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.jobs import Job from ..onefuzzlib.pools import NodeTasks from ..onefuzzlib.request import not_ok, ok, parse_request @@ -99,7 +99,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(task) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/tasks/function.json b/src/api-service/__app__/tasks/function.json index b1017ab89..282a853df 100644 --- a/src/api-service/__app__/tasks/function.json +++ b/src/api-service/__app__/tasks/function.json @@ -17,6 +17,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/timer_daily/__init__.py b/src/api-service/__app__/timer_daily/__init__.py index 827df6c35..0621af705 100644 --- a/src/api-service/__app__/timer_daily/__init__.py +++ b/src/api-service/__app__/timer_daily/__init__.py @@ -8,12 +8,13 @@ import logging import azure.functions as func from onefuzztypes.enums import VmState +from ..onefuzzlib.events import get_events from ..onefuzzlib.pools import Scaleset from ..onefuzzlib.proxy import Proxy from ..onefuzzlib.webhooks import WebhookMessageLog -def main(mytimer: func.TimerRequest) -> None: # noqa: F841 +def main(mytimer: func.TimerRequest, dashboard: func.Out[str]) -> None: # noqa: F841 for proxy in Proxy.search(): if not proxy.is_used(): logging.info("stopping proxy") @@ -33,3 +34,7 @@ def main(mytimer: func.TimerRequest) -> None: # noqa: F841 log_entry.event_id, ) log_entry.delete() + + events = get_events() + if events: + dashboard.set(events) diff --git a/src/api-service/__app__/timer_daily/function.json b/src/api-service/__app__/timer_daily/function.json index 4c6387e9c..8bf006bce 100644 --- a/src/api-service/__app__/timer_daily/function.json +++ b/src/api-service/__app__/timer_daily/function.json @@ -1,11 +1,17 @@ { - "bindings": [ - { - "direction": "in", - "name": "mytimer", - "schedule": "1.00:00:00", - "type": "timerTrigger" - } - ], - "scriptFile": "__init__.py" -} \ No newline at end of file + "bindings": [ + { + "direction": "in", + "name": "mytimer", + "schedule": "1.00:00:00", + "type": "timerTrigger" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ], + "scriptFile": "__init__.py" +} diff --git a/src/api-service/__app__/timer_proxy/function.json b/src/api-service/__app__/timer_proxy/function.json index 8ed6b1ea6..7aa1d22e7 100644 --- a/src/api-service/__app__/timer_proxy/function.json +++ b/src/api-service/__app__/timer_proxy/function.json @@ -1,17 +1,17 @@ { - "bindings": [ - { - "direction": "in", - "name": "mytimer", - "schedule": "00:00:30", - "type": "timerTrigger" - }, - { - "type": "signalR", - "direction": "out", - "name": "dashboard", - "hubName": "dashboard" - } - ], - "scriptFile": "__init__.py" -} \ No newline at end of file + "bindings": [ + { + "direction": "in", + "name": "mytimer", + "schedule": "00:00:30", + "type": "timerTrigger" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ], + "scriptFile": "__init__.py" +} diff --git a/src/api-service/__app__/timer_repro/function.json b/src/api-service/__app__/timer_repro/function.json index ebe98447c..7aa1d22e7 100644 --- a/src/api-service/__app__/timer_repro/function.json +++ b/src/api-service/__app__/timer_repro/function.json @@ -14,4 +14,4 @@ } ], "scriptFile": "__init__.py" -} \ No newline at end of file +} diff --git a/src/api-service/__app__/timer_tasks/function.json b/src/api-service/__app__/timer_tasks/function.json index 009043c96..79e64f055 100644 --- a/src/api-service/__app__/timer_tasks/function.json +++ b/src/api-service/__app__/timer_tasks/function.json @@ -1,17 +1,17 @@ { - "bindings": [ - { - "direction": "in", - "name": "mytimer", - "schedule": "00:00:15", - "type": "timerTrigger" - }, - { - "type": "signalR", - "direction": "out", - "name": "dashboard", - "hubName": "dashboard" - } - ], - "scriptFile": "__init__.py" -} \ No newline at end of file + "bindings": [ + { + "direction": "in", + "name": "mytimer", + "schedule": "00:00:15", + "type": "timerTrigger" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" + } + ], + "scriptFile": "__init__.py" +} diff --git a/src/api-service/__app__/webhooks/__init__.py b/src/api-service/__app__/webhooks/__init__.py index dd413c432..3298f17a5 100644 --- a/src/api-service/__app__/webhooks/__init__.py +++ b/src/api-service/__app__/webhooks/__init__.py @@ -16,6 +16,7 @@ from onefuzztypes.requests import ( from onefuzztypes.responses import BoolResult from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.request import not_ok, ok, parse_request from ..onefuzzlib.webhooks import Webhook @@ -105,7 +106,13 @@ def delete(req: func.HttpRequest) -> func.HttpResponse: return ok(BoolResult(result=True)) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"GET": get, "POST": post, "DELETE": delete, "PATCH": patch} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/webhooks/function.json b/src/api-service/__app__/webhooks/function.json index d97ed662b..7065b64e0 100644 --- a/src/api-service/__app__/webhooks/function.json +++ b/src/api-service/__app__/webhooks/function.json @@ -17,6 +17,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/webhooks_logs/__init__.py b/src/api-service/__app__/webhooks_logs/__init__.py index ce1875319..2c79c9581 100644 --- a/src/api-service/__app__/webhooks_logs/__init__.py +++ b/src/api-service/__app__/webhooks_logs/__init__.py @@ -10,6 +10,7 @@ from onefuzztypes.models import Error from onefuzztypes.requests import WebhookGet from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.request import not_ok, ok, parse_request from ..onefuzzlib.webhooks import Webhook, WebhookMessageLog @@ -28,7 +29,13 @@ def post(req: func.HttpRequest) -> func.HttpResponse: return ok(logs) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"POST": post} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/webhooks_logs/function.json b/src/api-service/__app__/webhooks_logs/function.json index 1c42ac593..f11b3faf8 100644 --- a/src/api-service/__app__/webhooks_logs/function.json +++ b/src/api-service/__app__/webhooks_logs/function.json @@ -15,6 +15,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +} diff --git a/src/api-service/__app__/webhooks_ping/__init__.py b/src/api-service/__app__/webhooks_ping/__init__.py index 148781d37..042e66b9d 100644 --- a/src/api-service/__app__/webhooks_ping/__init__.py +++ b/src/api-service/__app__/webhooks_ping/__init__.py @@ -10,6 +10,7 @@ from onefuzztypes.models import Error from onefuzztypes.requests import WebhookGet from ..onefuzzlib.endpoint_authorization import call_if_user +from ..onefuzzlib.events import get_events from ..onefuzzlib.request import not_ok, ok, parse_request from ..onefuzzlib.webhooks import Webhook @@ -29,7 +30,13 @@ def post(req: func.HttpRequest) -> func.HttpResponse: return ok(ping) -def main(req: func.HttpRequest) -> func.HttpResponse: +def main(req: func.HttpRequest, dashboard: func.Out[str]) -> func.HttpResponse: methods = {"POST": post} method = methods[req.method] - return call_if_user(req, method) + result = call_if_user(req, method) + + events = get_events() + if events: + dashboard.set(events) + + return result diff --git a/src/api-service/__app__/webhooks_ping/function.json b/src/api-service/__app__/webhooks_ping/function.json index 83042b074..2968ee1a0 100644 --- a/src/api-service/__app__/webhooks_ping/function.json +++ b/src/api-service/__app__/webhooks_ping/function.json @@ -15,6 +15,12 @@ "type": "http", "direction": "out", "name": "$return" + }, + { + "type": "signalR", + "direction": "out", + "name": "dashboard", + "hubName": "dashboard" } ] -} \ No newline at end of file +}