updates
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
from .utils import register_event_handlers
|
||||
|
||||
|
||||
__all__ = ["register_event_handlers"]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from safety.events.handlers import EventHandler
|
||||
from safety.events.types import EventBusReadyEvent
|
||||
from safety.events.utils import emit_firewall_heartbeat
|
||||
|
||||
from safety.tool import ToolInspector
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from safety.events.event_bus import EventBus
|
||||
|
||||
|
||||
class HeartbeatInspectionEventHandler(EventHandler[EventBusReadyEvent]):
|
||||
"""
|
||||
Inspect the system for installed tools and send an emit
|
||||
a firewall heartbeat event.
|
||||
"""
|
||||
|
||||
def __init__(self, event_bus: "EventBus") -> None:
|
||||
super().__init__()
|
||||
self.event_bus = event_bus
|
||||
|
||||
async def handle(self, event: EventBusReadyEvent):
|
||||
ctx = event.payload.ctx
|
||||
inspector = ToolInspector(timeout=1.0)
|
||||
tools = await inspector.inspect_all_tools()
|
||||
|
||||
emit_firewall_heartbeat(self.event_bus, ctx, tools=tools)
|
||||
@@ -0,0 +1,40 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from safety_schemas.models.events import EventType
|
||||
from safety.events.event_bus import EventBus
|
||||
from safety.events.types import InternalEventType
|
||||
|
||||
from .handlers import HeartbeatInspectionEventHandler
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from safety.models import SafetyCLI
|
||||
|
||||
|
||||
def register_event_handlers(event_bus: "EventBus", obj: "SafetyCLI") -> None:
|
||||
"""
|
||||
Subscribes to the firewall events that are relevant to the current context.
|
||||
"""
|
||||
handle_inspection = HeartbeatInspectionEventHandler(event_bus=event_bus)
|
||||
event_bus.subscribe([InternalEventType.EVENT_BUS_READY], handle_inspection)
|
||||
|
||||
if sec_events_handler := obj.security_events_handler:
|
||||
event_bus.subscribe(
|
||||
[
|
||||
EventType.FIREWALL_CONFIGURED,
|
||||
EventType.FIREWALL_HEARTBEAT,
|
||||
EventType.FIREWALL_DISABLED,
|
||||
EventType.PACKAGE_INSTALLED,
|
||||
EventType.PACKAGE_UNINSTALLED,
|
||||
EventType.PACKAGE_UPDATED,
|
||||
EventType.TOOL_COMMAND_EXECUTED,
|
||||
EventType.INIT_STARTED,
|
||||
EventType.FIREWALL_SETUP_RESPONSE_CREATED,
|
||||
EventType.FIREWALL_SETUP_COMPLETED,
|
||||
EventType.CODEBASE_DETECTION_STATUS,
|
||||
EventType.CODEBASE_SETUP_RESPONSE_CREATED,
|
||||
EventType.CODEBASE_SETUP_COMPLETED,
|
||||
EventType.INIT_SCAN_COMPLETED,
|
||||
EventType.INIT_EXITED,
|
||||
],
|
||||
sec_events_handler,
|
||||
)
|
||||
Reference in New Issue
Block a user