config

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config is the single validation+persist+reconcile choke point for beacon's configuration entities (sources, sinks, connectors). The HTTP config API and, later, the Phase 3 UI both sit on Service rather than touching store.Store directly, so every write goes through the same whole-config structural validation and CEL filter compile check before anything is persisted.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
	ErrExists   = errors.New("already exists")
	ErrInUse    = errors.New("referenced by a connector")
)

Sentinel errors returned by Service methods. Callers use errors.Is; the HTTP layer (Phase 2 Task 4) maps them to specific status codes.

Functions

func MergeConfig

func MergeConfig(base, incoming model.Config) model.Config

MergeConfig upserts incoming's entities by id onto base, leaving any base entity not mentioned in incoming untouched. It is exported standalone (like ValidateConfig) so the CLI's import --merge command (Phase 4) can build the same merged result Service.Import would, before validating and writing it directly to the store.

func ValidateConfig

func ValidateConfig(cfg model.Config) error

ValidateConfig checks structural rules (model.Config.Validate: ids, types, references, sink path collisions) and then CEL-compiles every connector's filters. It is exported standalone so the CLI's import command (Phase 4) can validate a file before ever constructing a Service; Service.Import and every write path funnel through it too.

Types

type Reconciler

type Reconciler interface {
	Reconcile(ctx context.Context) error
	Statuses() []supervisor.Status
}

Reconciler is what Service triggers after committing a config change. *supervisor.Supervisor satisfies it; tests use a fake.

type Service

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

Service is beacon's config service layer. Every write is serialized by mu (a read-modify-write against the store must not interleave with another writer), validates the WOULD-BE whole config before touching the store, and — on a successful store write — triggers a supervisor reconcile. A reconcile failure is logged and left visible via Statuses(); it does not roll back the store write and is not returned to the write's caller (spec §3.6: visible, not fatal).

func NewService

func NewService(st *store.Store, rec Reconciler, log *slog.Logger) *Service

NewService builds a Service over st, triggering rec after every successful write. log defaults to slog.Default() when nil.

func (*Service) DeleteConnector

func (s *Service) DeleteConnector(ctx context.Context, id string) error

DeleteConnector removes a connector. ErrNotFound if it doesn't exist. Nothing else references a connector, so there is no ErrInUse case.

func (*Service) DeleteSink

func (s *Service) DeleteSink(ctx context.Context, id string) error

DeleteSink removes a sink. ErrNotFound if it doesn't exist; ErrInUse if any connector (enabled or not) still references it as its sink.

func (*Service) DeleteSource

func (s *Service) DeleteSource(ctx context.Context, id string) error

DeleteSource removes a source. ErrNotFound if it doesn't exist; ErrInUse if any connector (enabled or not) still references it as its source.

func (*Service) Export

func (s *Service) Export(ctx context.Context) (model.Config, error)

Export returns the whole current configuration (used by the CLI/UI export and as the base for a merge Import).

func (*Service) GetConnector

func (s *Service) GetConnector(ctx context.Context, id string) (model.Connector, error)

func (*Service) GetSink

func (s *Service) GetSink(ctx context.Context, id string) (model.Sink, error)

func (*Service) GetSource

func (s *Service) GetSource(ctx context.Context, id string) (model.Source, error)

func (*Service) Import

func (s *Service) Import(ctx context.Context, cfg model.Config, replace bool) error

Import replaces or merges cfg into the stored configuration.

replace=true: cfg becomes the whole configuration wholesale (validated standalone, then a transactional ReplaceConfig).

replace=false (merge): cfg's entities are upserted by id into the currently loaded configuration — entities not mentioned in cfg are left untouched — and the merged result is validated and persisted via ReplaceConfig.

Either way, validation runs against the full would-be result before any store write, so an invalid import leaves the store untouched.

func (*Service) ListConnectors

func (s *Service) ListConnectors(ctx context.Context) ([]model.Connector, error)

func (*Service) ListSinks

func (s *Service) ListSinks(ctx context.Context) ([]model.Sink, error)

func (*Service) ListSources

func (s *Service) ListSources(ctx context.Context) ([]model.Source, error)

func (*Service) PutConnector

func (s *Service) PutConnector(ctx context.Context, v model.Connector, isCreate bool) error

PutConnector creates or updates a connector, following the same isCreate semantics as PutSource.

func (*Service) PutSink

func (s *Service) PutSink(ctx context.Context, v model.Sink, isCreate bool) error

PutSink creates or updates a sink, following the same isCreate semantics as PutSource.

func (*Service) PutSource

func (s *Service) PutSource(ctx context.Context, v model.Source, isCreate bool) error

PutSource creates or updates a source. isCreate=true requires v.ID to not already exist (ErrExists otherwise); isCreate=false requires it to already exist (ErrNotFound otherwise).

func (*Service) Statuses

func (s *Service) Statuses() []supervisor.Status

Statuses passes through the reconciler's live component statuses (for /api/status and the UI dashboard).

func (*Service) ValidateFilters

func (s *Service) ValidateFilters(exprs []string) error

ValidateFilters CEL-compiles exprs without persisting anything, so the UI/CLI can check filter syntax before submitting a connector write.

type ValidationError

type ValidationError struct{ Msg string }

ValidationError reports a structural or CEL-compile problem with a would-be configuration — as opposed to a store/IO failure. The HTTP layer maps a *ValidationError to 422 and anything else to 500.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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