host

package
v0.8.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

type ListParams struct {
	Environment string
	Tag         string
}

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

func NewService(pool *pgxpool.Pool) *Service

NewService binds a Service to a DB pool.

func (*Service) CreateHost

func (s *Service) CreateHost(ctx context.Context, p CreateParams) (Host, error)

CreateHost validates input, inserts the row, returns the new Host.

Spec AC-03, AC-04, AC-05.

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id uuid.UUID) (Host, error)

GetByID returns the host when active; ErrHostNotFound for unknown or soft-deleted IDs.

Spec AC-07.

func (*Service) List

func (s *Service) List(ctx context.Context, p ListParams) ([]Host, error)

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

func (s *Service) SetTarget(ctx context.Context, id uuid.UUID, family string) (Host, error)

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

func (s *Service) SoftDelete(ctx context.Context, id uuid.UUID) error

SoftDelete sets deleted_at; subsequent lookups return ErrHostNotFound. The row remains physically present for audit forensics.

Spec AC-12, C-03.

func (*Service) UpdateHost

func (s *Service) UpdateHost(ctx context.Context, id uuid.UUID, p UpdateParams) (Host, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL