Documentation
¶
Overview ¶
Package host owns the hosts table — the inventory of machines the platform can talk to. CRUD only; OS discovery and monitoring state land in later slices when their producers exist.
Spec: specs/system/host-inventory.spec.yaml.
Index ¶
- Variables
- type CreateParams
- type Host
- type ListParams
- type Service
- func (s *Service) CreateHost(ctx context.Context, p CreateParams) (Host, error)
- func (s *Service) GetByID(ctx context.Context, id uuid.UUID) (Host, error)
- func (s *Service) List(ctx context.Context, p ListParams) ([]Host, error)
- func (s *Service) SetTarget(ctx context.Context, id uuid.UUID, family string) (Host, error)
- func (s *Service) SoftDelete(ctx context.Context, id uuid.UUID) error
- func (s *Service) UpdateHost(ctx context.Context, id uuid.UUID, p UpdateParams) (Host, error)
- type UpdateParams
Constants ¶
This section is empty.
Variables ¶
var ( ErrHostNotFound = errors.New("host: not found") ErrInvalidHost = errors.New("host: invalid input") ErrDuplicateHost = errors.New("host: hostname already exists in this environment") ErrInvalidCreator = errors.New("host: created_by user does not exist") ErrInvalidTarget = errors.New("host: target_framework is too long or has invalid characters") )
Service errors.
Functions ¶
This section is empty.
Types ¶
type CreateParams ¶
type CreateParams struct {
Hostname string
IPAddress string
Port int // 0 → default 22
DisplayName string
Description string
Environment string // empty → "production"
Tags []string
GroupID *uuid.UUID
Username string
CreatedBy uuid.UUID
}
CreateParams is the input to CreateHost. Validation enforces the "no empty hostname/ip" rule before the SQL would reject it on NOT NULL.
type Host ¶
type Host struct {
ID uuid.UUID
Hostname string
IPAddress string
Port int
DisplayName string
Description string
Environment string
Tags []string
GroupID *uuid.UUID
Username string // per-host override; empty = fall back to system default
CreatedBy uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
// v1.3.0 — multi-layer adaptive health-check fields. Default to
// false / 3 on rows that pre-date migration 0016.
MaintenanceMode bool
CheckPriority int
// v1.4.0 — denormalized OS fields populated by system-host-discovery
// via migration 0017. All nil pre-Discovery.
OSFamily *string
OSVersion *string
Architecture *string
PlatformIdentifier *string
OSDiscoveredAt *time.Time
// Phase 3 (compliance-targets) — the host's own durable target
// framework: operator intent about which framework family this host is
// held to (its default lens, and the per-host override that wins over
// any site-group target in host_effective_target). nil = inherit
// (site-group target, else the org default). Set via SetTarget; read
// by GetByID/UpdateHost. Spec system-compliance-lens, api-hosts.
TargetFramework *string
}
Host is the safe shape returned by every read API.
type ListParams ¶
ListParams scopes List. Empty fields = no filter on that axis.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the host CRUD entry point.
func NewService ¶
NewService binds a Service to a DB pool.
func (*Service) CreateHost ¶
CreateHost validates input, inserts the row, returns the new Host.
Spec AC-03, AC-04, AC-05.
func (*Service) GetByID ¶
GetByID returns the host when active; ErrHostNotFound for unknown or soft-deleted IDs.
Spec AC-07.
func (*Service) List ¶
List returns active hosts matching the filter. Empty Environment + empty Tag returns all active hosts.
Spec AC-09, AC-10, AC-11.
func (*Service) SetTarget ¶ added in v0.5.0
SetTarget sets (or clears, when family is "") the host's own compliance target framework. This is the per-host override: in host_effective_target it wins over any site-group target. Unlike a group target there is no site-only constraint (D1) — a host may always carry its own target. The family token is resolved leniently against the live corpus at query time, so this only bounds garbage/length (D3 handles a target with no matching corpus key as N/A, not 0%). Spec system-compliance-lens, api-hosts.
func (*Service) SoftDelete ¶
SoftDelete sets deleted_at; subsequent lookups return ErrHostNotFound. The row remains physically present for audit forensics.
Spec AC-12, C-03.
func (*Service) UpdateHost ¶
UpdateHost applies the supplied patch fields and bumps updated_at. Immutable fields (id, created_by, created_at) are preserved per spec AC-08.
type UpdateParams ¶
type UpdateParams struct {
IPAddress *string
Port *int
DisplayName *string
Description *string
Environment *string
Tags *[]string
GroupID *uuid.UUID
Username *string
}
UpdateParams carries the patch fields for UpdateHost. Pointers distinguish "leave unchanged" (nil) from "set to value." String fields with no business meaning are pointers; required fields stay as plain types because they cannot be unset.