whadmin

package
v1.136.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package whadmin is what an administrator does to a webhook source (#1870): create one, change it, rotate its secret, read its status, and delete it.

Creating a source is more than writing its record. Its tables and view are created on the connection it names, and the connection is proved able to hold them -- its catalog reads the managed-resources bucket and allows register_partition -- before the source is stored, so a source the platform accepts is one whose events can be queried. The table is recorded as a registration, which is how the table listing and every surface reading registrations sees it.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound  = whsource.ErrNotFound
	ErrExists    = whsource.ErrExists
	ErrNameTaken = errors.New("a table with this source's name is already registered on that connection")
	// ErrUnusable wraps the reason a connection could not hold the source's
	// tables, as the query engine gave it.
	ErrUnusable = errors.New("the connection cannot hold this source's table")
)

Refusals a request can meet, beyond whsource.ErrInvalid and the table package's connection refusals.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Sources       Sources
	Tables        Tables
	Registrations Registrations
	Windows       Windows
	Objects       Objects
	Resources     Resources
	Bucket        string
	// Changed is called after every write, so this replica's receiver
	// serves the change at once rather than at its next refresh.
	Changed func()
	// PersonaExists reports whether a persona is defined, so a source cannot
	// name one nobody belongs to. Nil accepts any name.
	PersonaExists func(name string) bool
	NewID         func() (string, error)
	Logger        *slog.Logger
	Now           func() time.Time
}

Deps are what the service acts through.

type Objects

type Objects interface {
	ListKeys(ctx context.Context, bucket, prefix string) ([]string, error)
	DeleteObject(ctx context.Context, bucket, key string) error
}

Objects lists and deletes what a source wrote outside the resource store.

type Registrations

type Registrations interface {
	Insert(ctx context.Context, r tableregister.Registration) error
	ByName(ctx context.Context, connection, catalog, schema, table string) (*tableregister.Registration, error)
	BySource(ctx context.Context, kind, sourceID string) ([]tableregister.Registration, error)
	Delete(ctx context.Context, id string) error
}

Registrations records the source's table. tableregister's store satisfies it.

type Resources

type Resources interface {
	Delete(ctx context.Context, id string) error
}

Resources deletes a compacted window's resource.

type Service

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

Service manages sources.

func New

func New(d Deps) *Service

New builds the service.

func (*Service) Create

func (s *Service) Create(ctx context.Context, src whsource.Source) (whsource.Source, error)

Create makes a source: its tables, the proof its connection can hold them, its record and its registration. A failure part-way removes what was made.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, name string) error

Delete removes a source and everything it wrote: its tables, its windows' resources, its raw segments, its registration and its record.

func (*Service) Get

Get returns one source with its status.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]whsource.Source, error)

List returns every source.

func (*Service) Update

func (s *Service) Update(ctx context.Context, name string, u Update) (whsource.Source, error)

Update changes a source's settings. The name, the connection and the persona stay: the table was created on that connection under a name derived from the source's, and the windows already written are in that persona's library. An empty secret keeps the stored one, so a form never has to carry it.

type Sources

type Sources interface {
	List(ctx context.Context) ([]whsource.Source, error)
	Get(ctx context.Context, name string) (whsource.Source, error)
	Create(ctx context.Context, src whsource.Source) error
	Update(ctx context.Context, src whsource.Source) error
	Delete(ctx context.Context, name string) error
}

Sources is the source record store. whsource.Store satisfies it.

type Tables

type Tables interface {
	TargetFor(connection string) (whtable.Target, error)
	S3Location(prefix string) string
	Create(ctx context.Context, tg whtable.Target, src whsource.Source) error
	Probe(ctx context.Context, tg whtable.Target, src whsource.Source) error
	Drop(ctx context.Context, tg whtable.Target, src whsource.Source) error
}

Tables is the query-engine side. whtable.Tables satisfies it.

type Update

type Update struct {
	Enabled *bool
	Auth    whsource.Auth
	Config  whsource.Config
	// RotationOverlap keeps the previous secret valid this long when Auth
	// carries a new one. Zero ends it at once.
	RotationOverlap time.Duration
}

Update is what an administrator can change on a source.

type Windows

type Windows interface {
	Status(ctx context.Context, source string, now time.Time) (whstore.Status, error)
	ResourceIDs(ctx context.Context, source string) ([]string, error)
}

Windows reads a source's status and the resources its windows were written as.

Jump to

Keyboard shortcuts

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