internal

package
v0.18.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const AllGenerations int64 = 0
View Source
const CONTEXT_TYPE = "config" + datacontext.OCM_CONTEXT_SUFFIX
View Source
const KIND_CONFIGSET = "config set"
View Source
const KIND_CONFIGTYPE = "config type"
View Source
const OCM_CONFIG_SUFFIX = ".config.ocm.software"

OCM_CONFIG_SUFFIX is the standard suffix used for all configuration types provided by this library.

View Source
const OCM_CONFIG_TYPE_SUFFIX = ".config" + common.OCM_TYPE_GROUP_SUFFIX

OCM_CONFIG_TYPE_SUFFIX is the standard suffix used for configuration types provided by this library.

Variables

View Source
var AllAppliedConfigs = AppliedConfigSelectorFunction(func(*AppliedConfig) bool { return true })
View Source
var AllConfigs = AppliedConfigSelectorFunction(func(*AppliedConfig) bool { return true })
View Source
var DefaultConfigTypeScheme = NewConfigTypeScheme(nil)

DefaultConfigTypeScheme contains all globally known access serializer.

View Source
var DefaultContext = Builder{}.New(datacontext.MODE_SHARED)

DefaultContext is the default context initialized by init functions.

View Source
var Realm = ocmlog.DefineSubRealm("configuration management", "config")

Functions

func ErrNoContext

func ErrNoContext(name string) error

func IsErrConfigNotApplicable

func IsErrConfigNotApplicable(err error) bool

func IsErrNoContext

func IsErrNoContext(err error) bool

func IsGeneric

func IsGeneric(cfg Config) bool

func TargetFunction

func TargetFunction[T any](f func() T) func() interface{}

TargetFunction can be used to map any type specific factory function to a target function returning a formal interface{} type.

Types

type AppliedConfig

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

type AppliedConfigSelector

type AppliedConfigSelector interface {
	Select(cfg *AppliedConfig) bool
}

func AppliedAndSelector

func AppliedAndSelector(and ...AppliedConfigSelector) AppliedConfigSelector

func AppliedConfigSelectorFor

func AppliedConfigSelectorFor(s ConfigSelector) AppliedConfigSelector

func AppliedGenerationSelector

func AppliedGenerationSelector(gen int64) AppliedConfigSelector

func AppliedVersionSelector

func AppliedVersionSelector(v string) AppliedConfigSelector

type AppliedConfigSelectorFunction

type AppliedConfigSelectorFunction func(cfg *AppliedConfig) bool

func (AppliedConfigSelectorFunction) Select

type AppliedConfigs

type AppliedConfigs []*AppliedConfig

func (AppliedConfigs) Configs

func (l AppliedConfigs) Configs() []Config

func (AppliedConfigs) Len

func (l AppliedConfigs) Len() int

func (AppliedConfigs) Less

func (l AppliedConfigs) Less(i, j int) bool

func (AppliedConfigs) Swap

func (l AppliedConfigs) Swap(i, j int)

type Builder

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

func (Builder) Bound

func (b Builder) Bound() (Context, context.Context)

func (Builder) New

func (b Builder) New(m ...datacontext.BuilderMode) Context

func (Builder) WithConfigTypeScheme

func (b Builder) WithConfigTypeScheme(scheme ConfigTypeScheme) Builder

func (Builder) WithContext

func (b Builder) WithContext(ctx context.Context) Builder

func (Builder) WithSharedAttributes

func (b Builder) WithSharedAttributes(ctx datacontext.AttributesContext) Builder

type Config

type Config interface {
	runtime.VersionedTypedObject

	ApplyTo(Context, interface{}) error
}

func NewGenericConfig

func NewGenericConfig(data []byte, unmarshaler runtime.Unmarshaler) (Config, error)

type ConfigApplier

type ConfigApplier interface {
	ApplyConfigTo(Context, cfg, tgt interface{}) error
}

type ConfigApplierFunction

type ConfigApplierFunction func(ctx Context, cfg, tgt interface{}) error

func (ConfigApplierFunction) ApplyConfigTo

func (f ConfigApplierFunction) ApplyConfigTo(ctx Context, cfg, tgt interface{}) error

type ConfigDecoder

type ConfigDecoder = runtime.TypedObjectDecoder[Config]

type ConfigSelector

type ConfigSelector interface {
	Select(Config) bool
}

type ConfigSelectorFunction

type ConfigSelectorFunction func(Config) bool

func (ConfigSelectorFunction) Select

func (f ConfigSelectorFunction) Select(cfg Config) bool

type ConfigSet

type ConfigSet struct {
	Description       string `json:"description,omitempty"`
	ConfigurationList `json:",inline"`
}

type ConfigStore

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

func NewConfigStore

func NewConfigStore() *ConfigStore

func (*ConfigStore) AddSet

func (c *ConfigStore) AddSet(name string, set *ConfigSet)

func (*ConfigStore) Apply

func (s *ConfigStore) Apply(c Config, desc string)

func (*ConfigStore) Generation

func (s *ConfigStore) Generation() int64

func (*ConfigStore) GetConfigForName

func (c *ConfigStore) GetConfigForName(ctx Context, name string, selector AppliedConfigSelector) (int64, AppliedConfigs)

func (*ConfigStore) GetConfigForSelector

func (c *ConfigStore) GetConfigForSelector(ctx Context, selector AppliedConfigSelector) (int64, AppliedConfigs)

func (*ConfigStore) GetConfigForType

func (c *ConfigStore) GetConfigForType(ctx Context, typ string, selector AppliedConfigSelector) (int64, AppliedConfigs)

func (*ConfigStore) GetSet

func (c *ConfigStore) GetSet(name string) *ConfigSet

func (*ConfigStore) Reset

func (s *ConfigStore) Reset() int64

type ConfigType

type ConfigType interface {
	runtime.VersionedTypedObjectType[Config]
	Usage() string
}

type ConfigTypeScheme

type ConfigTypeScheme interface {
	runtime.TypeScheme[Config, ConfigType]

	Usage() string
}

func NewConfigTypeScheme

func NewConfigTypeScheme(defaultDecoder ConfigDecoder, base ...ConfigTypeScheme) ConfigTypeScheme

type ConfigurationList

type ConfigurationList struct {
	Configurations []*GenericConfig `json:"configurations,omitempty"`
}

func (*ConfigurationList) AddConfig

func (c *ConfigurationList) AddConfig(cfg Config) error

func (*ConfigurationList) AddConfigData

func (c *ConfigurationList) AddConfigData(ctx Context, data []byte) error

type Context

type Context interface {
	datacontext.Context
	ContextProvider

	AttributesContext() datacontext.AttributesContext

	// Info provides the context for nested configuration evaluation
	Info() string
	// WithInfo provides the same context with additional nesting info
	WithInfo(desc string) Context

	ConfigTypes() ConfigTypeScheme

	// SkipUnknownConfig can be used to control the behaviour
	// for processing unknown configuration object types.
	// It returns the previous mode valid before setting the
	// new one.
	SkipUnknownConfig(bool) bool

	// Validate validates the applied configuration for not using
	// unknown configuration types, anymore. This can be used after setting
	// SkipUnknownConfig, to check whether there are still unknown types
	// which will be skipped. It does not provide information, whether
	// config objects were skipped for previous object configuration
	// requests.
	Validate() error

	// GetConfigForData deserialize configuration objects for known
	// configuration types.
	GetConfigForData(data []byte, unmarshaler runtime.Unmarshaler) (Config, error)

	// ApplyData applies the config given by a byte stream to the config store
	// If the config type is not known, a generic config is stored and returned.
	// In this case an unknown error for kind KIND_CONFIGTYPE is returned.
	ApplyData(data []byte, unmarshaler runtime.Unmarshaler, desc string) (Config, error)
	// ApplyConfig applies the config to the config store
	ApplyConfig(spec Config, desc string) error

	GetConfigForType(generation int64, typ string) (int64, []Config)
	GetConfigForName(generation int64, name string) (int64, []Config)
	GetConfig(generation int64, selector ConfigSelector) (int64, []Config)

	AddConfigSet(name string, set *ConfigSet)
	ApplyConfigSet(name string) error

	// Reset all configs applied so far, subsequent calls to ApplyTo will
	// ony see configs allpied after the last reset.
	Reset() int64
	// Generation return the actual config generation.
	// this is a strictly increasing number, regardless of the number
	// of Reset calls.
	Generation() int64
	// ApplyTo applies all configurations applied after the last reset with
	// a generation larger than the given watermark to the specified target.
	// A target may be any object. The applied configuration objects decide
	// on their own whether they are applicable for the given target.
	// The generation of the last applied object is returned to be used as
	// new watermark.
	ApplyTo(gen int64, target interface{}) (int64, error)
}

func DefinedForContext

func DefinedForContext(ctx context.Context) (Context, bool)

func FromContext

func FromContext(ctx context.Context) Context

FromContext returns the Context to use for context.Context. This is either an explicit context or the default context. The returned context incorporates the given context.

func FromProvider

func FromProvider(p ContextProvider) Context

type ContextProvider

type ContextProvider interface {
	ConfigContext() Context
}

type Evaluator

type Evaluator interface {
	Evaluate(ctx Context) (Config, error)
}

type GenericConfig

type GenericConfig struct {
	runtime.UnstructuredVersionedTypedObject `json:",inline"`
	// contains filtered or unexported fields
}

func ToGenericConfig

func ToGenericConfig(c Config) (*GenericConfig, error)

func (*GenericConfig) ApplyTo

func (s *GenericConfig) ApplyTo(ctx Context, target interface{}) error

func (*GenericConfig) Evaluate

func (s *GenericConfig) Evaluate(ctx Context) (Config, error)

func (*GenericConfig) IsUnknown

func (s *GenericConfig) IsUnknown() bool

type Updater

type Updater interface {
	// Update replays missing configuration requests
	// applicable for a dedicated type of context or configuration target
	// stored in a configuration context.
	// It should be created for and called from within such a context
	Update() error
	State() (int64, bool)
	GetContext() Context

	Lock()
	Unlock()
	RLock()
	RUnlock()
}

Updater implements the generation based update protocol to update data contexts based on the config requests made to a configuration context.

func NewUpdater

func NewUpdater(ctx ContextProvider, target interface{}) Updater

NewUpdater create a configuration updater for a configuration target based on a dedicated configuration context.

func NewUpdaterForFactory

func NewUpdaterForFactory[T any](ctx ContextProvider, t func() T) Updater

Jump to

Keyboard shortcuts

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