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 ¶
- Variables
- func MergeConfig(base, incoming model.Config) model.Config
- func ValidateConfig(cfg model.Config) error
- type Reconciler
- type Service
- func (s *Service) DeleteConnector(ctx context.Context, id string) error
- func (s *Service) DeleteSink(ctx context.Context, id string) error
- func (s *Service) DeleteSource(ctx context.Context, id string) error
- func (s *Service) Export(ctx context.Context) (model.Config, error)
- func (s *Service) GetConnector(ctx context.Context, id string) (model.Connector, error)
- func (s *Service) GetSink(ctx context.Context, id string) (model.Sink, error)
- func (s *Service) GetSource(ctx context.Context, id string) (model.Source, error)
- func (s *Service) Import(ctx context.Context, cfg model.Config, replace bool) error
- func (s *Service) ListConnectors(ctx context.Context) ([]model.Connector, error)
- func (s *Service) ListSinks(ctx context.Context) ([]model.Sink, error)
- func (s *Service) ListSources(ctx context.Context) ([]model.Source, error)
- func (s *Service) PutConnector(ctx context.Context, v model.Connector, isCreate bool) error
- func (s *Service) PutSink(ctx context.Context, v model.Sink, isCreate bool) error
- func (s *Service) PutSource(ctx context.Context, v model.Source, isCreate bool) error
- func (s *Service) Statuses() []supervisor.Status
- func (s *Service) ValidateFilters(exprs []string) error
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
NewService builds a Service over st, triggering rec after every successful write. log defaults to slog.Default() when nil.
func (*Service) DeleteConnector ¶
DeleteConnector removes a connector. ErrNotFound if it doesn't exist. Nothing else references a connector, so there is no ErrInUse case.
func (*Service) DeleteSink ¶
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 ¶
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 ¶
Export returns the whole current configuration (used by the CLI/UI export and as the base for a merge Import).
func (*Service) GetConnector ¶
func (*Service) Import ¶
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 (*Service) ListSources ¶
func (*Service) PutConnector ¶
PutConnector creates or updates a connector, following the same isCreate semantics as PutSource.
func (*Service) PutSink ¶
PutSink creates or updates a sink, following the same isCreate semantics as PutSource.
func (*Service) PutSource ¶
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 ¶
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