runtimeconfig

package
v2.18.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

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

View Source
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

func JSONString(v any) string

Types

type EntryMarshaller

type EntryMarshaller interface {
	fmt.Stringer
}

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

func (*Manager) OrganizationResolver(db Store, orgID uuid.UUID) Resolver

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()'.

func (*Manager) Resolver

func (*Manager) Resolver(db Store) Resolver

Resolver is the deployment wide namespace for runtime configuration. If you are trying to namespace a configuration, orgs for example, use OrganizationResolver.

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 (m NamespacedResolver) GetRuntimeConfig(ctx context.Context, key string) (string, error)

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) GetRuntimeConfig(context.Context, string) (string, error)

func (NoopResolver) UpsertRuntimeConfig

func (NoopResolver) UpsertRuntimeConfig(context.Context, string, string) error

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 (m StoreResolver) GetRuntimeConfig(ctx context.Context, key string) (string, error)

func (StoreResolver) UpsertRuntimeConfig

func (m StoreResolver) UpsertRuntimeConfig(ctx context.Context, key, val string) error

Jump to

Keyboard shortcuts

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