v0.1.27 release: Complete implementation
Features: - Error logging system with ETHOS #1 compliance - Command factory pattern with UUID generation - Hardware binding with machine fingerprint validation - Ed25519 cryptographic signing for updates - Deduplication and idempotency for commands - Circuit breakers and retry logic - Frontend error logging integration Bug Fixes: - Version display using compile-time injection - Migration 017 CONCURRENTLY issue resolved - Docker build context fixes - Rate limiting implementation verified Documentation: - README updated to reflect actual implementation - v0.1.27 inventory analysis added
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -16,12 +17,52 @@ type AgentCommand struct {
|
||||
Source string `json:"source" db:"source"`
|
||||
Signature string `json:"signature,omitempty" db:"signature"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
||||
SentAt *time.Time `json:"sent_at,omitempty" db:"sent_at"`
|
||||
CompletedAt *time.Time `json:"completed_at,omitempty" db:"completed_at"`
|
||||
Result JSONB `json:"result,omitempty" db:"result"`
|
||||
RetriedFromID *uuid.UUID `json:"retried_from_id,omitempty" db:"retried_from_id"`
|
||||
}
|
||||
|
||||
// Validate checks if the command has all required fields
|
||||
func (c *AgentCommand) Validate() error {
|
||||
if c.ID == uuid.Nil {
|
||||
return ErrCommandIDRequired
|
||||
}
|
||||
if c.AgentID == uuid.Nil {
|
||||
return ErrAgentIDRequired
|
||||
}
|
||||
if c.CommandType == "" {
|
||||
return ErrCommandTypeRequired
|
||||
}
|
||||
if c.Status == "" {
|
||||
return ErrStatusRequired
|
||||
}
|
||||
if c.Source != "manual" && c.Source != "system" {
|
||||
return ErrInvalidSource
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsTerminal returns true if the command is in a terminal state
|
||||
func (c *AgentCommand) IsTerminal() bool {
|
||||
return c.Status == "completed" || c.Status == "failed" || c.Status == "cancelled"
|
||||
}
|
||||
|
||||
// CanRetry returns true if the command can be retried
|
||||
func (c *AgentCommand) CanRetry() bool {
|
||||
return c.Status == "failed" && c.RetriedFromID == nil
|
||||
}
|
||||
|
||||
// Predefined errors for validation
|
||||
var (
|
||||
ErrCommandIDRequired = errors.New("command ID cannot be zero UUID")
|
||||
ErrAgentIDRequired = errors.New("agent ID is required")
|
||||
ErrCommandTypeRequired = errors.New("command type is required")
|
||||
ErrStatusRequired = errors.New("status is required")
|
||||
ErrInvalidSource = errors.New("source must be 'manual' or 'system'")
|
||||
)
|
||||
|
||||
// CommandsResponse is returned when an agent checks in for commands
|
||||
type CommandsResponse struct {
|
||||
Commands []CommandItem `json:"commands"`
|
||||
|
||||
Reference in New Issue
Block a user