service

package
v0.0.0-...-b9bb202 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoerceConfigForStorage

func CoerceConfigForStorage(attrs map[string]any) (map[string]string, error)

CoerceConfigForStorage is responsible for taking a config object and distilling all of its attribute values down to strings for persistence. The best way to have complex types go through this function is for type to implement the stringer interface.

TODO tlm: This function is really bad and should be removed with some work. Specifically the services layer should not be trying to understand the default in and outs of every config type and how to get it into shape for persistence. Instead, the config should be providing translation helpers to deal with this so that each attribute can be encapsulated on its own. This is a leftover copy from Mongo and should be dealt with at some stage.

Types

type ModelDefaultsProvider

type ModelDefaultsProvider interface {
	// ModelDefaults will return the default config values to be used for a model
	// and its config.
	ModelDefaults(context.Context) (modeldefaults.Defaults, error)
}

ModelDefaultsProvider is responsible for providing the default config values for a model.

type ProviderService

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

ProviderService defines the service for interacting with ModelConfig. The provider service is a subset of the ModelConfig service, and is used by the provider package to interact with the ModelConfig service. By not exposing the full ModelConfig service, the provider package is not able to modify the ModelConfig entities, only read them.

func NewProviderService

func NewProviderService(
	st ProviderState,
) *ProviderService

NewProviderService creates a new ModelConfig service.

func (*ProviderService) ModelConfig

func (s *ProviderService) ModelConfig(ctx context.Context) (*config.Config, error)

ModelConfig returns the current config for the model.

type ProviderState

type ProviderState interface {
	// AllKeysQuery returns a SQL statement that will return all known model config
	// keys.
	AllKeysQuery() string
	// ModelConfig returns the currently set config for the model.
	ModelConfig(context.Context) (map[string]string, error)
}

ProviderState defines the state methods required by the ProviderService.

type Service

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

Service defines the service for interacting with ModelConfig.

func NewService

func NewService(
	defaultsProvider ModelDefaultsProvider,
	modelValidator config.Validator,
	st State,
) *Service

NewService creates a new ModelConfig service.

func (*Service) ModelConfig

func (s *Service) ModelConfig(ctx context.Context) (*config.Config, error)

ModelConfig returns the current config for the model.

func (*Service) ModelConfigValues

func (s *Service) ModelConfigValues(
	ctx context.Context,
) (config.ConfigValues, error)

ModelConfigValues returns the config values for the model and the source of the value.

func (*Service) SetModelConfig

func (s *Service) SetModelConfig(
	ctx context.Context,
	cfg map[string]any,
) error

SetModelConfig will remove any existing model config for the model and replace with the new config provided. The new config will also be hydrated with any model default attributes that have not been set on the config.

func (*Service) UpdateModelConfig

func (s *Service) UpdateModelConfig(
	ctx context.Context,
	updateAttrs map[string]any,
	removeAttrs []string,
	additionalValidators ...config.Validator,
) error

UpdateModelConfig takes a set of updated and removed attributes to apply. Removed attributes are replaced with their model default values should they exist. All model config updates are validated against the currently set model config. The model config is ran through several validation steps before being persisted. If an error occurs during validation then a config.ValidationError is returned. The caller can also optionally pass in additional config.Validators to be run.

The following validations on model config are run by default: - Agent version is not change between updates. - Charmhub url is not changed between updates. - The networking space chosen is valid and can be used. - The secret backend is valid and can be used. - Authorized keys are not changed. - Container networking method is not being changed.

type SpaceValidatorState

type SpaceValidatorState interface {
	// SpaceExists checks if the space identified by the given space name exists.
	SpaceExists(ctx context.Context, spaceName string) (bool, error)
}

SpaceValidatorState represents the state entity for validating space-related model config.

type State

type State interface {
	ProviderState
	SpaceValidatorState

	// AgentVersion returns the current models agent version. If no agent
	// version has been set for the current model then a error satisfying
	// [errors.NotFound] is returned.
	AgentVersion(context.Context) (string, error)

	// ModelConfigHasAttributes returns the set of attributes that model config
	// currently has set out of the list supplied.
	ModelConfigHasAttributes(context.Context, []string) ([]string, error)

	// SetModelConfig is responsible for setting the current model config and
	// overwriting all previously set values even if the config supplied is
	// empty or nil.
	SetModelConfig(context.Context, map[string]string) error

	// UpdateModelConfig is responsible for both inserting, updating and
	// removing model config values for the current model.
	UpdateModelConfig(context.Context, map[string]string, []string) error
}

State represents the state entity for accessing and setting per model configuration values.

type WatchableProviderService

type WatchableProviderService struct {
	ProviderService
	// contains filtered or unexported fields
}

WatchableProviderService defines the service for interacting with ModelConfig and the ability to create watchers.

func NewWatchableProviderService

func NewWatchableProviderService(
	st ProviderState,
	watcherFactory WatcherFactory,
) *WatchableProviderService

NewWatchableProviderService creates a new WatchableProviderService for interacting with ModelConfig and the ability to create watchers.

func (*WatchableProviderService) Watch

Watch returns a watcher that returns keys for any changes to model config.

type WatchableService

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

WatchableService defines the service for interacting with ModelConfig and the ability to create watchers.

func NewWatchableService

func NewWatchableService(
	defaultsProvider ModelDefaultsProvider,
	modelValidator config.Validator,
	st State,
	watcherFactory WatcherFactory,
) *WatchableService

NewWatchableService creates a new WatchableService for interacting with ModelConfig and the ability to create watchers.

func (*WatchableService) Watch

Watch returns a watcher that returns keys for any changes to model config.

type WatcherFactory

type WatcherFactory interface {
	// NewNamespaceWatcher returns a new namespace watcher
	// for events based on the input change mask.
	NewNamespaceWatcher(string, changestream.ChangeType, eventsource.NamespaceQuery) (watcher.StringsWatcher, error)
}

WatcherFactory describes methods for creating watchers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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