Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ const (
CommandQueue = "/queue/authorization/command"
EventQueue = "/queue/authorization"
ReplyPrefix = "/queue/authorization/reply."

// SSE notification topic — published by dbdiscauth after DB writes,
// consumed by configui to push real-time updates to the browser.
SSEEventsTopic = "/topic/ui.events"

// SSE event type constants
SSENotification = "sse_notification"

// UI event names sent via SSE
UIEventIRCStateChanged = "irc_state_changed"
UIEventIRCAdded = "irc_added"
UIEventIRCDeleted = "irc_deleted"
UIEventRacdeviceStateChanged = "racdevice_state_changed"
UIEventRacdeviceAdded = "racdevice_added"
UIEventRacdeviceDeleted = "racdevice_deleted"
UIEventValveStateChanged = "valve_state_changed"
)

type AuthClientInterface interface {
Expand Down Expand Up @@ -191,6 +207,27 @@ func (as *AuthorizationService) BroadcastService(svc Service) error {
return as.SendEnvelope(EventQueue, env)
}

// UINotification is a lightweight event published to SSEEventsTopic after DB writes.
// The configui SSE endpoint subscribes and pushes these to browsers in real time.
type UINotification struct {
Event string `json:"event"` // e.g. "irc_state_changed"
Data interface{} `json:"data"` // event-specific payload
}

// PublishUIEvent publishes a UI notification to the SSE topic so connected
// browsers receive instant updates.
func (as *AuthorizationService) PublishUIEvent(event string, data interface{}) error {
notification := UINotification{
Event: event,
Data: data,
}
env, err := wire.NewEnvelope(SSENotification, notification)
if err != nil {
return err
}
return as.SendEnvelope(SSEEventsTopic, env)
}

type AuthorizationClient struct {
*service.BaseClient
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const (
GETLOGIN = auth.GETLOGIN

UPDATESERVICEX = auth.UPDATESERVICEX

// SSE notification constants
SSENotification = auth.SSENotification
SSEEventsTopic = auth.SSEEventsTopic

// UI event names sent via SSE
UIEventIRCStateChanged = auth.UIEventIRCStateChanged
UIEventIRCAdded = auth.UIEventIRCAdded
UIEventIRCDeleted = auth.UIEventIRCDeleted
UIEventRacdeviceStateChanged = auth.UIEventRacdeviceStateChanged
UIEventRacdeviceAdded = auth.UIEventRacdeviceAdded
UIEventRacdeviceDeleted = auth.UIEventRacdeviceDeleted
UIEventValveStateChanged = auth.UIEventValveStateChanged
)

func NewAuthClientWithBus(mb messagebus.Messagebus, clientName string) *auth.AuthorizationClient {
Expand Down Expand Up @@ -56,6 +69,7 @@ type Login = auth.Login
type AuthorizationClient = auth.AuthorizationClient
type AuthorizationService = auth.AuthorizationService
type AuthClientInterface = auth.AuthClientInterface
type UINotification = auth.UINotification

const (
SYSTEM_TYPE_IDRAC = auth.IDRAC
Expand Down