hosts

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest        = errors.New("bad request")
	ErrHostNotFound      = errors.New("host not found")
	ErrHostConflict      = errors.New("host already exists")
	ErrHostFQDNImmutable = errors.New("host fqdn is immutable; rename = delete + create")
	ErrDuplicateHostID   = errors.New("duplicate host id in reconcile request")
	ErrDuplicateHostFQDN = errors.New("duplicate fqdn in reconcile request")

	ErrHostGroupNotFound = errors.New("host group not found")
	ErrHostGroupConflict = errors.New("host group name already exists")
	ErrGroupNameRequired = errors.New("group name is required")
	ErrInvalidGroupColor = errors.New("group color must be a 6-digit hex color (e.g. #4C6EF5)")
	ErrDuplicateGroupID  = errors.New("duplicate group id")

	ErrSuggestionNotFound = errors.New("ignored suggestion not found")
	ErrSuggestionConflict = errors.New("suggestion already ignored")

	ErrReferenceNotFound = errors.New("referenced entity not found")
)

Functions

func NormaliseFQDN

func NormaliseFQDN(raw string) string

NormaliseFQDN trims whitespace, lowercases, and strips a trailing dot.

func NormaliseHost added in v0.5.0

func NormaliseHost(raw string) string

NormaliseHost normalises a requested host (e.g. an X-Forwarded-Host value) for comparison against stored grants. Host grants are bare FQDNs by construction

func ValidateFQDN

func ValidateFQDN(s string) error

ValidateFQDN checks that s is a well-formed hostname per RFC 1123. It expects the input to already be lowercased/trimmed (NormaliseFQDN does this).

Types

type DesiredHost

type DesiredHost struct {
	ID       *ids.HostID
	FQDN     string
	GroupIDs []ids.HostGroupID
}

DesiredHost is the caller-provided shape of a single host inside a reconcile request. A nil ID marks a brand-new host; a non-nil ID must match an existing row. FQDN is immutable on updates — a mismatch returns ErrHostFQDNImmutable. GroupIDs replaces the host's full group membership.

type DesiredHostGroup

type DesiredHostGroup struct {
	ID          *ids.HostGroupID
	Name        string
	Color       string
	Icon        string
	Description *string
	HostIDs     []ids.HostID
}

DesiredHostGroup is the caller-provided shape of a single host group inside a reconcile request. A nil ID marks a brand-new group; a non-nil ID must match an existing group or the reconcile fails with ErrHostGroupNotFound.

type HTTPHandler

type HTTPHandler struct {
	// contains filtered or unexported fields
}

func NewHTTPHandler

func NewHTTPHandler(service *Service, repo *Repository, logger *slog.Logger) *HTTPHandler

func (*HTTPHandler) GetHostGroup added in v0.6.0

func (*HTTPHandler) ListHostGroups added in v0.6.0

func (*HTTPHandler) ListHosts added in v0.6.0

type Host

type Host struct {
	ID        ids.HostID `db:"id"`
	FQDN      string     `db:"fqdn"`
	UpdatedAt time.Time  `db:"updated_at"`
	CreatedAt time.Time  `db:"created_at"`
}

type HostDraft

type HostDraft struct {
	FQDN     string
	GroupIDs []ids.HostGroupID
}

HostDraft is the minimum shape needed to insert a new hosts row.

type HostGroup

type HostGroup struct {
	ID          ids.HostGroupID `db:"id"`
	Name        string          `db:"name"`
	Color       string          `db:"color"`
	Icon        string          `db:"icon"`
	Description *string         `db:"description"`
	UpdatedAt   time.Time       `db:"updated_at"`
	CreatedAt   time.Time       `db:"created_at"`
	HostIDs     []ids.HostID    `db:"-"`
}

func (HostGroup) SameDefinitionAs

func (g HostGroup) SameDefinitionAs(other HostGroup) bool

SameDefinitionAs reports whether two groups would produce identical rows in host_groups + host_group_members. Used by the reconciler to skip no-op updates and avoid spurious updated_at bumps.

type HostGroupDraft

type HostGroupDraft struct {
	Name        string
	Color       string
	Icon        string
	Description *string
	HostIDs     []ids.HostID
}

HostGroupDraft is the minimum shape needed to insert a new host_groups row plus its members in a single repository call.

type IgnoredHostSuggestion

type IgnoredHostSuggestion struct {
	ID        int64     `db:"id"`
	FQDN      string    `db:"fqdn"`
	CreatedAt time.Time `db:"created_at"`
}

type Observer

type Observer interface {
	OnHostAccessChanged(ctx context.Context)
}

Observer is implemented by any component that must react when host or group configuration changes (e.g. policy.Service refreshing its cache).

type ReconcileHostGroupsInput

type ReconcileHostGroupsInput struct {
	Groups []DesiredHostGroup
}

ReconcileHostGroupsInput is the full desired image of host_groups that the caller wants the database to converge to.

type ReconcileHostsInput

type ReconcileHostsInput struct {
	Hosts []DesiredHost
}

ReconcileHostsInput is the full desired image of hosts that the caller wants the database to converge to.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(db *database.DB) *Repository

func (*Repository) AddIgnoredSuggestion

func (r *Repository) AddIgnoredSuggestion(ctx context.Context, fqdn string) (IgnoredHostSuggestion, error)

func (*Repository) CreateHost

func (r *Repository) CreateHost(ctx context.Context, draft HostDraft) (ids.HostID, error)

func (*Repository) CreateHostGroup

func (r *Repository) CreateHostGroup(ctx context.Context, draft HostGroupDraft) (ids.HostGroupID, error)

func (*Repository) DeleteHost

func (r *Repository) DeleteHost(ctx context.Context, id ids.HostID) error

func (*Repository) DeleteHostGroup

func (r *Repository) DeleteHostGroup(ctx context.Context, id ids.HostGroupID) error

func (*Repository) GetAllHostsWithGroups added in v0.6.0

func (r *Repository) GetAllHostsWithGroups(ctx context.Context) (httpapi.HostListResponse, error)

GetAllHostsWithGroups returns every host with all of its group memberships, for the host list page.

func (*Repository) GetHostGroupDetail added in v0.6.0

func (r *Repository) GetHostGroupDetail(ctx context.Context, id ids.HostGroupID) (*httpapi.GroupDetailWithUsers, error)

GetHostGroupDetail returns the full detail for one host group: its member hosts, the users granted access to it, and the network policies that grant access through it. Returns ErrHostGroupNotFound if id does not exist.

func (*Repository) GetHostGroupsList added in v0.6.0

func (r *Repository) GetHostGroupsList(ctx context.Context) (httpapi.GroupListResponse, error)

GetHostGroupsList returns the light host-groups list for the group list page: display fields plus a member-host count, without the per-group users/hosts/ network-policy detail (see GetHostGroupDetail for that).

func (*Repository) ListHostGroups

func (r *Repository) ListHostGroups(ctx context.Context) ([]HostGroup, error)

ListHostGroups returns every host group with its member host IDs. Members are loaded with a second query and joined in memory so a group with no members still appears in the result.

func (*Repository) ListHosts

func (r *Repository) ListHosts(ctx context.Context) ([]Host, error)

func (*Repository) ListHostsByIDs

func (r *Repository) ListHostsByIDs(ctx context.Context, hostIDs []ids.HostID) ([]Host, error)

func (*Repository) RemoveIgnoredSuggestionByFQDN

func (r *Repository) RemoveIgnoredSuggestionByFQDN(ctx context.Context, fqdn string) error

func (*Repository) SetHostGroupMembership

func (r *Repository) SetHostGroupMembership(ctx context.Context, hostID ids.HostID, groupIDs []ids.HostGroupID) error

SetHostGroupMembership replaces the full set of groups that hostID belongs to.

func (*Repository) UpdateHostGroup

func (r *Repository) UpdateHostGroup(ctx context.Context, group HostGroup) error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(repo repository, tx transactor, logger *slog.Logger) *Service

func (*Service) AddIgnoredSuggestion

func (s *Service) AddIgnoredSuggestion(ctx context.Context, fqdn string) (IgnoredHostSuggestion, error)

func (*Service) AddObserver

func (s *Service) AddObserver(o Observer)

func (*Service) ListHostGroups

func (s *Service) ListHostGroups(ctx context.Context) ([]HostGroup, error)

func (*Service) ListHosts

func (s *Service) ListHosts(ctx context.Context) ([]Host, error)

ListHosts returns all hosts ordered by ID.

func (*Service) ReconcileHostGroups

func (s *Service) ReconcileHostGroups(ctx context.Context, in ReconcileHostGroupsInput) error

ReconcileHostGroups makes the database converge to the desired image of host_groups + members in a single transaction. Groups present in `in` with a non-nil ID are updated; groups with a nil ID are created; groups currently in the database whose ID is absent from `in` are deleted.

All referenced host IDs are validated up-front so the transaction can fail fast without partial work. Observers are notified once on success because group membership changes can shift effective per-user host access.

func (*Service) ReconcileHosts

func (s *Service) ReconcileHosts(ctx context.Context, in ReconcileHostsInput) error

ReconcileHosts makes the database converge to the desired image of hosts in a single transaction. Hosts present in `in` with a non-nil ID retain their group membership as specified; hosts with a nil ID are created; hosts currently in the database whose ID is absent from `in` are deleted.

Note: deleting a host cascades to host_group_members (ON DELETE CASCADE), so a reconcile that drops hosts implicitly changes effective user host access. Observers are always notified on success.

func (*Service) RemoveIgnoredSuggestionByFQDN

func (s *Service) RemoveIgnoredSuggestionByFQDN(ctx context.Context, fqdn string) error

Jump to

Keyboard shortcuts

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