From 73e4994ddc04d0da8decd56b1a94626af57b984f Mon Sep 17 00:00:00 2001 From: Anthony Rubick <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Sun, 7 Sep 2025 17:03:30 -0500 Subject: [PATCH] feat(eventpayload): add GetEventSource() to EventPayload interface this design (as opposed to adding a Source field to the Event struct) requires fewer changes to existing APIs while still supporting the two primary cases for event sources: 1. an event that always has the same source can just return a hard-coded string 2. an event that can come from multiple components (or from plugins) can have a source field that gets returned by this function --- .../mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ .../debugger/mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ .../mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ .../mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ .../helloworld/mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ .../mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ .../mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ .../upnp/mod/zoraxy_plugin/events/events.go | 15 +++++++++++++++ src/mod/plugins/zoraxy_plugin/events/events.go | 15 +++++++++++++++ 9 files changed, 135 insertions(+) diff --git a/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go b/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/example/plugins/debugger/mod/zoraxy_plugin/events/events.go b/example/plugins/debugger/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/debugger/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/debugger/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go b/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go b/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go b/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go b/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go b/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/example/plugins/upnp/mod/zoraxy_plugin/events/events.go b/example/plugins/upnp/mod/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/example/plugins/upnp/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/upnp/mod/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data diff --git a/src/mod/plugins/zoraxy_plugin/events/events.go b/src/mod/plugins/zoraxy_plugin/events/events.go index c743ec6..df61861 100644 --- a/src/mod/plugins/zoraxy_plugin/events/events.go +++ b/src/mod/plugins/zoraxy_plugin/events/events.go @@ -12,6 +12,9 @@ type EventName string type EventPayload interface { // GetName returns the event type GetName() EventName + + // Returns the "source" of the event, that is, the component or plugin that emitted the event + GetEventSource() string } // Event represents a system event @@ -62,6 +65,10 @@ func (e *BlacklistedIPBlockedEvent) GetName() EventName { return EventBlacklistedIPBlocked } +func (e *BlacklistedIPBlockedEvent) GetEventSource() string { + return "proxy-access" +} + // BlacklistToggledEvent represents an event when the blacklist is disabled for an access rule type BlacklistToggledEvent struct { RuleID string `json:"rule_id"` @@ -72,6 +79,10 @@ func (e *BlacklistToggledEvent) GetName() EventName { return EventBlacklistToggled } +func (e *BlacklistToggledEvent) GetEventSource() string { + return "accesslist-api" +} + // AccessRuleCreatedEvent represents an event when a new access ruleset is created type AccessRuleCreatedEvent struct { ID string `json:"id"` @@ -85,6 +96,10 @@ func (e *AccessRuleCreatedEvent) GetName() EventName { return EventAccessRuleCreated } +func (e *AccessRuleCreatedEvent) GetEventSource() string { + return "accesslist-api" +} + // ParseEvent parses a JSON byte slice into an Event struct func ParseEvent(jsonData []byte, event *Event) error { // First, determine the event type, and parse shared fields, from the JSON data