runtime

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ChangeTypeCreate = "create"
	ChangeTypeUpdate = "update"
	ChangeTypeDelete = "delete"
)
View Source
var (
	ErrMissingName = errors.New("config-schema: registration is missing a unique name")
	ErrNameTaken   = errors.New("config-schema: registration name already in use")
	ErrMissingSpec = errors.New("config-schema: registration is missing configuration specification")
)
View Source
var (
	ErrNoProvider         = errors.New("config-provider: not initialized")
	ErrCfgSectionNotFound = errors.New("config-provider: no configuration section found")
	ErrReadOnly           = errors.New("config-provider: provider is read-only")
	ErrUnknownConfigTest  = errors.New("config: unknown configuration tests identifier")
	ErrUnknownType        = errors.New("config: unknown-type")
)

Common errors when working with ConfigProvider.

View Source
var (
	OneOfRoles = OneOfRef("identity:roles", "name", "")
	OneOfUsers = OneOfRef("identity:users", "name", "")
)
View Source
var GlobalSchema = new(ConfigSchema)

GlobalSchema is the global configuration schema.

View Source
var (
	IDRef = "_id"
)

Functions

func Must

func Must(err error)

Must panics if err is non-nil.

func OneOf

func OneOf(values ...PossibleValue) conf.KeyValue

OneOf returns a new KeyValue for a OneOfAnnotation conf.Option with it's allowe .Values member set to values.

func OneOfRef

func OneOfRef(ref, valueField, displayField string, allowCustomValue ...bool) conf.KeyValue

OneOfRef returns a new KeyValue for a OneOfReference conf.Option annotation.

func OneOfWithCustom

func OneOfWithCustom(values ...PossibleValue) conf.KeyValue

OneOfWithCustom returns a new KeyValue for a OneOfAnnotation conf.Option with it's allowe .Values member set to values. This annoation also allows for custom values.

func OverviewFields

func OverviewFields(fields ...string) conf.KeyValue

OverviewFields returns a schema annotation that marks one or more fields for use in "overviews" like when displaying section instances in a table layout.

func Readonly

func Readonly() conf.KeyValue

Readonly returns a new Keyvalue that marks an entity as read-only.

func StringFormat

func StringFormat(format string) conf.KeyValue

func Unique

func Unique(uniqueFields ...string) conf.KeyValue

Unique marks each field name passed as unique. This may be useful to enforce unique names accros configuration instances.

Types

type ChangeListener

type ChangeListener interface {
	// NotifyChange is called when an instance of a specific configuration section
	// is created, modified or deleted. The changeType parameter will be set to
	// "create", "update" or "delete" respectively with id holding a unique identifier
	// for the section. Note that sec is only set for create or update operations but MAY
	// be omitted during deletes.
	// Note that any error returned from this callback is displayed to the user but does
	// NOT prevent that change from happening!
	NotifyChange(ctx context.Context, changeType, id string, sec *conf.Section) error
}

type ConfigProvider

type ConfigProvider interface {
	// Create should store a new configuration section and return a unique
	// ID for that section.
	Create(ctx context.Context, sec conf.Section) (id string, err error)

	// Update should update an existing configuration section by id. opts
	// holds the new configuration data for that section.
	Update(ctx context.Context, id string, secType string, opts []conf.Option) error

	// Delete should delete an existing configuration section by id.
	Delete(ctx context.Context, id string) error

	// Get returns all options for the given sectionType.
	Get(ctx context.Context, sectionType string) ([]Section, error)

	// GetID returns the section by ID.
	GetID(ctx context.Context, id string) (Section, error)
}

ConfigProvider is used by ConfigSchema to provide access to configuration values abstracting a way the actual storage and format of configuration data.

type ConfigSchema

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

ConfigSchema defines the allowed sections for a configuration file.

func (*ConfigSchema) AddNotifier

func (schema *ConfigSchema) AddNotifier(listener ChangeListener, types ...string)

func (*ConfigSchema) AddValidator

func (schema *ConfigSchema) AddValidator(validator Validator, types ...string)

func (*ConfigSchema) All

func (schema *ConfigSchema) All(ctx context.Context, secType string) ([]Section, error)

func (*ConfigSchema) Create

func (schema *ConfigSchema) Create(ctx context.Context, secType string, options []conf.Option) (string, error)

func (*ConfigSchema) DecodeSection

func (schema *ConfigSchema) DecodeSection(ctx context.Context, section string, target interface{}) error

DecodeSection decodes the values of section from into target.

func (*ConfigSchema) Delete

func (schema *ConfigSchema) Delete(ctx context.Context, id string) error

func (*ConfigSchema) FileSpec

func (schema *ConfigSchema) FileSpec() conf.FileSpec

FileSpec returns the current file spec described by the config schema.

func (*ConfigSchema) GetID

func (schema *ConfigSchema) GetID(ctx context.Context, id string) (Section, error)

func (*ConfigSchema) OptionsForSection

func (schema *ConfigSchema) OptionsForSection(name string) (conf.OptionRegistry, bool)

OptionsForSection implements conf.SectionRegistry.

func (*ConfigSchema) Register

func (schema *ConfigSchema) Register(regs ...Schema) error

Register registers a section at the global config registry.

func (*ConfigSchema) SchemaAsMap

func (schema *ConfigSchema) SchemaAsMap(ctx context.Context, name string, withDefaults bool) (map[string]map[string]interface{}, error)

func (*ConfigSchema) SchemaByName

func (schema *ConfigSchema) SchemaByName(name string) (Schema, error)

SchemaByName returns the schema definition by name.

func (*ConfigSchema) Schemas

func (schema *ConfigSchema) Schemas() []Schema

Schemas returns a slice of all registered configuration schemas.

func (*ConfigSchema) SetProvider

func (schema *ConfigSchema) SetProvider(provider ConfigProvider)

SetProvider sets the parsed configuration file for the schema.

func (*ConfigSchema) Test

func (schema *ConfigSchema) Test(ctx context.Context, schemaType, testID string, configSpec, testSpec []conf.Option) (*TestResult, error)

Test validates configSpec using the defined configuration test testID. testSpec holds configuration values required for the test as defined in ConfigTest.Spec. Test automatically applies defaults for configSpec and testSpec and validates them against the respective configuration specification.

func (*ConfigSchema) Update

func (schema *ConfigSchema) Update(ctx context.Context, id, secType string, opts []conf.Option) error

type ConfigSchemaBuilder

type ConfigSchemaBuilder []func(*ConfigSchema) error

ConfigSchemaBuilder collects functions that add configuration sections to a configuration scheme. It's to allow code to be used with multiple configuration schemes while still being allowed to register on the global configuration.

func NewConfigSchemaBuilder

func NewConfigSchemaBuilder(funcs ...func(s *ConfigSchema) error) ConfigSchemaBuilder

NewConfigSchemaBuilder returns a new config schema builder using funcs.

func (*ConfigSchemaBuilder) AddToSchema

func (csb *ConfigSchemaBuilder) AddToSchema(scheme *ConfigSchema) error

AddToSchema applies all functions from csb to scheme. It aborts if non-nil error is returned.

func (*ConfigSchemaBuilder) Register

func (csb *ConfigSchemaBuilder) Register(funcs ...func(*ConfigSchema) error)

Register adds a config schema setup function to the list.

type ConfigTest

type ConfigTest struct {
	// ID is a unique ID for this configuration test and used to identify
	// and trigger the test.
	ID string `json:"id"`

	// Name holds a human readable name of the test and is used when the user
	// can select between available config tests.
	Name string `json:"name"`

	// Spec defines a set of options that the user can or must provide in order to
	// test a configuration schema.
	Spec conf.OptionRegistry `json:"spec"`

	// TestFunc is called to verify that config works as expected. config adheres to the
	// schema specification. testSpec is the configuration to execute the test and may hold
	// additional data like the receiver of a test notification.
	TestFunc func(ctx context.Context, config []conf.Option, testSpec []conf.Option) (*TestResult, error) `json:"-"`
}

ConfigTest can be added to Schema to support testing a configuration before is stored in the backend.

type NotificationError

type NotificationError struct {
	Wrapped error
}

func (*NotificationError) Error

func (nf *NotificationError) Error() string

func (*NotificationError) Unwrap

func (nf *NotificationError) Unwrap() error

type OneOfAnnotation

type OneOfAnnotation struct {
	Values []PossibleValue `json:"values,omitempty"`
	// AllowCustomValue can be set to true if custom values
	// should also be allowed for the annoated option.
	AllowCustomValue bool `json:"allowCustomValue"`
}

OneOfAnnotation is used to describe a "select" type of configuration option.

type OneOfReference

type OneOfReference struct {
	// SchemaType is the name of the schema that
	// holds possible values.
	SchemaType string `json:"schemaType"`
	// ValueField is the name of the field in the referenced
	// schema.
	ValueField string `json:"valueField"`
	// DisplayFiled is the name fo the field that should be diplayed
	// in the user interface.
	DisplayField string `json:"displayField,omitempty"`
	// AllowCustomValue can be set to true if custom values
	// should also be allowed for the annoated option.
	AllowCustomValue bool `json:"allowCustomValue"`
}

type PossibleValue

type PossibleValue struct {
	Display string      `json:"display"`
	Value   interface{} `json:"value"`
}

PossibleValue describes an allowed value for a configuration option. PossibleValues are used for "select" components in a user interface.

type Schema

type Schema struct {
	// Name is the name of the registration block and is used to identify the allowed
	// values of a configuration.
	// Name is required when registering a new configuration block.
	Name string `json:"name"`

	// DisplayName holds a human readable name for the schema type and is mainly used
	// in the user interface. If omitted, DisplayName is set to equal Name.
	DisplayName string `json:"displayName"`

	// SVGData may hold an icon definition that may be rendered in a <svg> tag
	// in a user interface.
	SVGData string `json:"svgData,omitempty"`

	// Description holds a human readable description of the configuration block and
	// is mainly used by the user interface.
	// Description is optional.
	Description string `json:"description"`

	// Category defines the category the configuration section belongs to.
	// Categories can be used to group related sections together in the user
	// interface.
	Category string `json:"category"`

	// Spec holds the actual section registry that defines which sections, values and
	// which types are allowed for instances of the configuration block.
	// Spec is required when registering a new configuration block.
	Spec conf.OptionRegistry `json:"-"`

	// Multi should be set to true if multiple instances of the registered
	// configuration can exist at the same time.
	Multi bool `json:"multi"`

	// Internal can be set to true if the schema should not be exposed via
	// the REST API.
	Internal bool `json:"internal"`

	// Annotations may hold additional annotations about the configuration schema. Those
	// annotations may be, for example, used by user interfaces to determine how to
	// best display the configuration setting.
	Annotations conf.Annotation `json:"annotation"`

	// Tests may hold one or more configuration test that a user may perform in order to
	// be certain that a configuration schema works as expected.
	Tests []ConfigTest `json:"tests,omitempty"`
}

Schema is passed to ConfigSchema.Register and holds metadata and information about the registered configuration block.

type Section

type Section struct {
	ID string
	conf.Section
}

func (Section) Decode

func (sec Section) Decode(spec conf.OptionRegistry, target interface{}) error

Decode is a shortcut for using conf.DecodeSections with sec only.

type StringFormatAnnotation

type StringFormatAnnotation struct {
	// Format defines the format of the annotated string
	// value.
	//
	// Valid values are:
	//
	//	- text/plain
	//	- text/markdown
	//	- application/json
	//
	Format string `json:"format"`
}

type TestResult

type TestResult struct {
	Error   string `json:"error"`
	Message string `json:"message,omitempty"`
}

func NewTestError

func NewTestError(err error) *TestResult

type Validator

type Validator interface {
	// Validate can be set if if the configuration section must be externally validated
	// before being created or updated.
	// The parameter id is only set in case of an update. Users should be aware that
	// even if ValidateFunc returns a nil-error the section might fail to be saved successfully.
	// Users should use a ChangeListener callback instead.
	Validate(ctx context.Context, sec Section) error
}

Directories

Path Synopsis
configprovider
Package execer provides a trigger type that executes an external program.
Package execer provides a trigger type that executes an external program.
Package trigger adds a ppacher/system-conf based trigger system that listens for events from cis/runtime/events.
Package trigger adds a ppacher/system-conf based trigger system that listens for events from cis/runtime/events.

Jump to

Keyboard shortcuts

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