Documentation
¶
Index ¶
- Variables
- func NormaliseFQDN(raw string) string
- func ValidateFQDN(s string) error
- type DesiredHost
- type DesiredHostGroup
- type HTTPHandler
- func (h *HTTPHandler) IgnoreSuggestion(ctx context.Context, req httpapi.IgnoreSuggestionRequestObject) (httpapi.IgnoreSuggestionResponseObject, error)
- func (h *HTTPHandler) ReconcileHostGroups(ctx context.Context, req httpapi.ReconcileHostGroupsRequestObject) (httpapi.ReconcileHostGroupsResponseObject, error)
- func (h *HTTPHandler) ReconcileHosts(ctx context.Context, req httpapi.ReconcileHostsRequestObject) (httpapi.ReconcileHostsResponseObject, error)
- func (h *HTTPHandler) UnignoreSuggestion(ctx context.Context, req httpapi.UnignoreSuggestionRequestObject) (httpapi.UnignoreSuggestionResponseObject, error)
- type Host
- type HostDraft
- type HostGroup
- type HostGroupDraft
- type IgnoredHostSuggestion
- type Observer
- type ReconcileHostGroupsInput
- type ReconcileHostsInput
- type Repository
- func (r *Repository) AddIgnoredSuggestion(ctx context.Context, fqdn string) (IgnoredHostSuggestion, error)
- func (r *Repository) CreateHost(ctx context.Context, draft HostDraft) (ids.HostID, error)
- func (r *Repository) CreateHostGroup(ctx context.Context, draft HostGroupDraft) (ids.HostGroupID, error)
- func (r *Repository) DeleteHost(ctx context.Context, id ids.HostID) error
- func (r *Repository) DeleteHostGroup(ctx context.Context, id ids.HostGroupID) error
- func (r *Repository) ListHostGroups(ctx context.Context) ([]HostGroup, error)
- func (r *Repository) ListHosts(ctx context.Context) ([]Host, error)
- func (r *Repository) ListHostsByIDs(ctx context.Context, hostIDs []ids.HostID) ([]Host, error)
- func (r *Repository) RemoveIgnoredSuggestionByFQDN(ctx context.Context, fqdn string) error
- func (r *Repository) SetHostGroupMembership(ctx context.Context, hostID ids.HostID, groupIDs []ids.HostGroupID) error
- func (r *Repository) UpdateHostGroup(ctx context.Context, group HostGroup) error
- type Service
- func (s *Service) AddIgnoredSuggestion(ctx context.Context, fqdn string) (IgnoredHostSuggestion, error)
- func (s *Service) AddObserver(o Observer)
- func (s *Service) ListHostGroups(ctx context.Context) ([]HostGroup, error)
- func (s *Service) ListHosts(ctx context.Context) ([]Host, error)
- func (s *Service) ReconcileHostGroups(ctx context.Context, in ReconcileHostGroupsInput) error
- func (s *Service) ReconcileHosts(ctx context.Context, in ReconcileHostsInput) error
- func (s *Service) RemoveIgnoredSuggestionByFQDN(ctx context.Context, fqdn string) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
NormaliseFQDN trims whitespace, lowercases, and strips a trailing dot.
func ValidateFQDN ¶
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, logger *slog.Logger) *HTTPHandler
func (*HTTPHandler) IgnoreSuggestion ¶
func (h *HTTPHandler) IgnoreSuggestion( ctx context.Context, req httpapi.IgnoreSuggestionRequestObject, ) (httpapi.IgnoreSuggestionResponseObject, error)
func (*HTTPHandler) ReconcileHostGroups ¶
func (h *HTTPHandler) ReconcileHostGroups( ctx context.Context, req httpapi.ReconcileHostGroupsRequestObject, ) (httpapi.ReconcileHostGroupsResponseObject, error)
func (*HTTPHandler) ReconcileHosts ¶
func (h *HTTPHandler) ReconcileHosts( ctx context.Context, req httpapi.ReconcileHostsRequestObject, ) (httpapi.ReconcileHostsResponseObject, error)
func (*HTTPHandler) UnignoreSuggestion ¶
func (h *HTTPHandler) UnignoreSuggestion( ctx context.Context, req httpapi.UnignoreSuggestionRequestObject, ) (httpapi.UnignoreSuggestionResponseObject, error)
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 ¶
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 Observer ¶
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 (*Repository) CreateHostGroup ¶
func (r *Repository) CreateHostGroup(ctx context.Context, draft HostGroupDraft) (ids.HostGroupID, error)
func (*Repository) DeleteHost ¶
func (*Repository) DeleteHostGroup ¶
func (r *Repository) DeleteHostGroup(ctx context.Context, id ids.HostGroupID) error
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) ListHostsByIDs ¶
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 (*Service) AddIgnoredSuggestion ¶
func (*Service) AddObserver ¶
func (*Service) ListHostGroups ¶
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.