mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-22 13:36:16 +01:00
- Introduce `Transport` interface to abstract WebSocket and SSH communication - Add generic `Data` field to `AgentResponse` for streamlined future endpoints - Maintain backward compatibility with legacy hubs and agents using typed fields - Unify fetch operations (SMART, systemd, containers) under a single `request` method - Improve `RequestManager` with deadline awareness and legacy response support - Refactor agent response routing into dedicated `agent/response.go` - Update version to 0.18.0-beta.2
77 lines
2.5 KiB
Go
77 lines
2.5 KiB
Go
package common
|
|
|
|
import (
|
|
"github.com/fxamacker/cbor/v2"
|
|
"github.com/henrygd/beszel/internal/entities/smart"
|
|
"github.com/henrygd/beszel/internal/entities/system"
|
|
"github.com/henrygd/beszel/internal/entities/systemd"
|
|
)
|
|
|
|
type WebSocketAction = uint8
|
|
|
|
const (
|
|
// Request system data from agent
|
|
GetData WebSocketAction = iota
|
|
// Check the fingerprint of the agent
|
|
CheckFingerprint
|
|
// Request container logs from agent
|
|
GetContainerLogs
|
|
// Request container info from agent
|
|
GetContainerInfo
|
|
// Request SMART data from agent
|
|
GetSmartData
|
|
// Request detailed systemd service info from agent
|
|
GetSystemdInfo
|
|
// Add new actions here...
|
|
)
|
|
|
|
// HubRequest defines the structure for requests sent from hub to agent.
|
|
type HubRequest[T any] struct {
|
|
Action WebSocketAction `cbor:"0,keyasint"`
|
|
Data T `cbor:"1,keyasint,omitempty,omitzero"`
|
|
Id *uint32 `cbor:"2,keyasint,omitempty"`
|
|
}
|
|
|
|
// AgentResponse defines the structure for responses sent from agent to hub.
|
|
type AgentResponse struct {
|
|
Id *uint32 `cbor:"0,keyasint,omitempty"`
|
|
SystemData *system.CombinedData `cbor:"1,keyasint,omitempty,omitzero"` // Legacy (<= 0.17)
|
|
Fingerprint *FingerprintResponse `cbor:"2,keyasint,omitempty,omitzero"` // Legacy (<= 0.17)
|
|
Error string `cbor:"3,keyasint,omitempty,omitzero"`
|
|
String *string `cbor:"4,keyasint,omitempty,omitzero"` // Legacy (<= 0.17)
|
|
SmartData map[string]smart.SmartData `cbor:"5,keyasint,omitempty,omitzero"` // Legacy (<= 0.17)
|
|
ServiceInfo systemd.ServiceDetails `cbor:"6,keyasint,omitempty,omitzero"` // Legacy (<= 0.17)
|
|
// Data is the generic response payload for new endpoints (0.18+)
|
|
Data cbor.RawMessage `cbor:"7,keyasint,omitempty,omitzero"`
|
|
}
|
|
|
|
type FingerprintRequest struct {
|
|
Signature []byte `cbor:"0,keyasint"`
|
|
NeedSysInfo bool `cbor:"1,keyasint"` // For universal token system creation
|
|
}
|
|
|
|
type FingerprintResponse struct {
|
|
Fingerprint string `cbor:"0,keyasint"`
|
|
// Optional system info for universal token system creation
|
|
Hostname string `cbor:"1,keyasint,omitzero"`
|
|
Port string `cbor:"2,keyasint,omitzero"`
|
|
Name string `cbor:"3,keyasint,omitzero"`
|
|
}
|
|
|
|
type DataRequestOptions struct {
|
|
CacheTimeMs uint16 `cbor:"0,keyasint"`
|
|
IncludeDetails bool `cbor:"1,keyasint"`
|
|
}
|
|
|
|
type ContainerLogsRequest struct {
|
|
ContainerID string `cbor:"0,keyasint"`
|
|
}
|
|
|
|
type ContainerInfoRequest struct {
|
|
ContainerID string `cbor:"0,keyasint"`
|
|
}
|
|
|
|
type SystemdInfoRequest struct {
|
|
ServiceName string `cbor:"0,keyasint"`
|
|
}
|