Pulse/internal/interfaces/interfaces.go
Pulse Monitor 7f5dae9b05 feat: Implement security, type safety, and error handling improvements
Security Enhancements:
- Add TLS fingerprint verification for Proxmox and PBS clients
- Create shared tlsutil package for secure TLS handling
- Implement proper CORS checking for WebSocket connections
- Add configurable allowed origins for WebSocket hub

Type Safety Improvements:
- Replace all TypeScript 'any' types with proper interfaces
- Add proper types for connectionHealth, apiCallDuration, metrics values
- Create typed BackupTask and StorageBackup interfaces
- Ensure all TypeScript code passes strict type checking

Error Handling Enhancements:
- Add comprehensive error handling middleware for API routes
- Implement structured error responses with proper status codes
- Add error boundaries to critical frontend components
- Fix WebSocket upgrade issues by preserving http.Hijacker interface
- Implement storage details endpoint (was TODO)

Code Quality:
- Fix Go vet mutex copy issues by creating StateSnapshot type
- Update ToFrontend() to use pointer receiver
- Ensure all code compiles without warnings
- Add proper error recovery and retry mechanisms

All changes tested and verified to work correctly.
2025-07-29 17:53:51 +00:00

60 lines
2.3 KiB
Go

package interfaces
import (
"context"
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
"github.com/rcourtman/pulse-go-rewrite/internal/types"
)
// StateStore defines the interface for state management
type StateStore interface {
GetSnapshot() models.StateSnapshot
UpdateNodes(nodes []models.Node)
UpdateNodesForInstance(instanceName string, nodes []models.Node)
UpdateVMs(vms []models.VM)
UpdateVMsForInstance(instanceName string, vms []models.VM)
UpdateContainers(containers []models.Container)
UpdateContainersForInstance(instanceName string, containers []models.Container)
UpdateStorage(storage []models.Storage)
UpdatePBSInstances(instances []models.PBSInstance)
SetConnectionHealth(instance string, healthy bool)
}
// WebSocketHub defines the interface for WebSocket hub
type WebSocketHub interface {
BroadcastState(state interface{})
GetClientCount() int
Run(ctx context.Context)
}
// MetricsStore defines the interface for metrics storage
type MetricsStore interface {
AddGuestMetric(guestID string, metricType string, value float64, timestamp time.Time)
AddNodeMetric(nodeID string, metricType string, value float64, timestamp time.Time)
AddStorageMetric(storageID string, metricType string, value float64, timestamp time.Time)
GetGuestMetrics(guestID string, metricType string, duration time.Duration) []types.MetricPoint
GetNodeMetrics(nodeID string, metricType string, duration time.Duration) []types.MetricPoint
GetAllGuestMetrics(guestID string, duration time.Duration) map[string][]types.MetricPoint
GetAllStorageMetrics(storageID string, duration time.Duration) map[string][]types.MetricPoint
Cleanup()
}
// Monitor defines the interface for the monitoring system
type Monitor interface {
Start(ctx context.Context, hub WebSocketHub)
GetState() models.StateSnapshot
GetStartTime() time.Time
GetGuestMetrics(guestID string, duration time.Duration) map[string][]types.MetricPoint
GetNodeMetrics(nodeID string, metricType string, duration time.Duration) []types.MetricPoint
GetStorageMetrics(storageID string, duration time.Duration) map[string][]types.MetricPoint
}
// RateTracker defines the interface for rate tracking
type RateTracker interface {
CalculateRates(guestID string, current types.IOMetrics) (diskRead, diskWrite, netIn, netOut float64)
}