Documentation ¶
Overview ¶
Package runtimeconfig contains logic for managing runtime configuration values stored in the database. Each coderd should have a Manager singleton instance that can create a Resolver for runtime configuration CRUD.
TODO: Implement a caching layer for the Resolver so that we don't hit the database on every request. Configuration values are not expected to change frequently, so we should use pubsub to notify for updates. When implemented, the runtimeconfig will essentially be an in memory lookup with a database for persistence.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEntryNotFound is returned when a runtime entry is not saved in the // store. It is essentially a 'sql.ErrNoRows'. ErrEntryNotFound = xerrors.New("entry not found") // ErrNameNotSet is returned when a runtime entry is created without a name. // This is more likely to happen on DeploymentEntry that has not called // Initialize(). ErrNameNotSet = xerrors.New("name is not set") )
Functions ¶
func JSONString ¶
Types ¶
type EntryMarshaller ¶
EntryMarshaller requires all entries to marshal to and from a string. The final store value is a database `text` column. This also is compatible with serpent values.
type EntryValue ¶
type EntryValue interface { EntryMarshaller Set(string) error }
type Initializer ¶
type Initializer interface {
Initialize(name string)
}
type Manager ¶
type Manager struct{}
Manager is the singleton that produces resolvers for runtime configuration. TODO: Implement caching layer.
func NewManager ¶
func NewManager() *Manager
func (*Manager) OrganizationResolver ¶
OrganizationResolver will namespace all runtime configuration to the provided organization ID. Configuration values stored with a given organization ID require that the organization ID be provided to retrieve the value. No values set here will ever be returned by the call to 'Resolver()'.
type NamespacedResolver ¶
type NamespacedResolver struct {
// contains filtered or unexported fields
}
NamespacedResolver prefixes all keys with a namespace. Then defers to the underlying resolver for the actual operations.
func OrganizationResolver ¶
func OrganizationResolver(orgID uuid.UUID, wrapped Resolver) NamespacedResolver
func (NamespacedResolver) DeleteRuntimeConfig ¶
func (m NamespacedResolver) DeleteRuntimeConfig(ctx context.Context, key string) error
func (NamespacedResolver) GetRuntimeConfig ¶
func (NamespacedResolver) UpsertRuntimeConfig ¶
func (m NamespacedResolver) UpsertRuntimeConfig(ctx context.Context, key, val string) error
type NoopResolver ¶
type NoopResolver struct{}
NoopResolver is a useful test device.
func NewNoopResolver ¶
func NewNoopResolver() *NoopResolver
func (NoopResolver) DeleteRuntimeConfig ¶
func (NoopResolver) DeleteRuntimeConfig(context.Context, string) error
func (NoopResolver) GetRuntimeConfig ¶
func (NoopResolver) UpsertRuntimeConfig ¶
type Resolver ¶
type Resolver interface { // GetRuntimeConfig gets a runtime setting by name. GetRuntimeConfig(ctx context.Context, name string) (string, error) // UpsertRuntimeConfig upserts a runtime setting by name. UpsertRuntimeConfig(ctx context.Context, name, val string) error // DeleteRuntimeConfig deletes a runtime setting by name. DeleteRuntimeConfig(ctx context.Context, name string) error }
type RuntimeEntry ¶
type RuntimeEntry[T EntryValue] struct { // contains filtered or unexported fields }
RuntimeEntry are **only** runtime configurable. They are stored in the database, and have no startup value or default value.
func MustNew ¶
func MustNew[T EntryValue](name string) RuntimeEntry[T]
MustNew is like New but panics if an error occurs.
func New ¶
func New[T EntryValue](name string) (out RuntimeEntry[T], err error)
New creates a new T instance with a defined name and value.
func (RuntimeEntry[T]) Resolve ¶
func (e RuntimeEntry[T]) Resolve(ctx context.Context, r Resolver) (T, error)
Resolve attempts to resolve the runtime value of this field from the store via the given Resolver.
func (RuntimeEntry[T]) SetRuntimeValue ¶
func (e RuntimeEntry[T]) SetRuntimeValue(ctx context.Context, m Resolver, val T) error
SetRuntimeValue attempts to update the runtime value of this field in the store via the given Mutator.
func (RuntimeEntry[T]) UnsetRuntimeValue ¶
func (e RuntimeEntry[T]) UnsetRuntimeValue(ctx context.Context, m Resolver) error
UnsetRuntimeValue removes the runtime value from the store.
type Store ¶
type Store interface { GetRuntimeConfig(ctx context.Context, key string) (string, error) UpsertRuntimeConfig(ctx context.Context, arg database.UpsertRuntimeConfigParams) error DeleteRuntimeConfig(ctx context.Context, key string) error }
Store is a subset of database.Store
type StoreResolver ¶
type StoreResolver struct {
// contains filtered or unexported fields
}
StoreResolver uses the database as the underlying store for runtime settings.
func NewStoreResolver ¶
func NewStoreResolver(db Store) *StoreResolver
func (StoreResolver) DeleteRuntimeConfig ¶
func (m StoreResolver) DeleteRuntimeConfig(ctx context.Context, key string) error
func (StoreResolver) GetRuntimeConfig ¶
func (StoreResolver) UpsertRuntimeConfig ¶
func (m StoreResolver) UpsertRuntimeConfig(ctx context.Context, key, val string) error