Files
ITWorx-Pulse-Public/internal/agentprotocol/protocol.go
T
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

43 lines
1.1 KiB
Go

package agentprotocol
import (
"errors"
"strings"
"time"
)
const Version = "v1"
type Capability struct {
ID string `json:"id"`
Version string `json:"version"`
ReadOnly bool `json:"readOnly"`
}
type Hello struct {
Protocol string `json:"protocol"`
AgentID string `json:"agentId"`
ObservedAt time.Time `json:"observedAt"`
Capabilities []Capability `json:"capabilities"`
}
func (h Hello) Validate(now time.Time) error {
if h.Protocol != Version {
return errors.New("unsupported agent protocol")
}
if strings.TrimSpace(h.AgentID) == "" || len(h.AgentID) > 120 {
return errors.New("invalid agent id")
}
if h.ObservedAt.IsZero() || h.ObservedAt.After(now.Add(time.Minute)) {
return errors.New("invalid agent observation time")
}
if len(h.Capabilities) > 50 {
return errors.New("too many agent capabilities")
}
for _, capability := range h.Capabilities {
if strings.TrimSpace(capability.ID) == "" || capability.Version == "" || !capability.ReadOnly {
return errors.New("agent capability must be explicit and read-only")
}
}
return nil
}