service

package
v0.0.0-...-d78cc51 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 17 Imported by: 6

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 ModelConfigProvider

type ModelConfigProvider interface {
	// ConfigSchema returns extra config attributes specific
	// to this provider only.
	ConfigSchema() schema.Fields

	// Schema returns the configuration schema for an environment.
	Schema() configschema.Fields
}

ModelConfigProvider represents an interface that a [EnvironProvider] can implement to provide opinions and defaults into a model's config.

type ModelConfigProviderFunc

type ModelConfigProviderFunc func(ctx context.Context, cloudType string) (ModelConfigProvider, error)

ModelConfigProviderFunc describes a type that is able to return a environs.ModelConfigProvider for the model it is scoped to. The function internally determines the cloud type for the model. If no model config provider exists for the model's cloud type then a coreerrors.NotFound error is returned. If the cloud type provider does not support model config then a coreerrors.NotSupported error is returned.

func ProviderModelConfigGetter

func ProviderModelConfigGetter() ModelConfigProviderFunc

ProviderModelConfigGetter returns a ModelConfigProviderFunc that can be used to get a ModelConfigProvider for the model. The function internally determines the cloud type from the model config and caches the provider for the lifetime of the function.

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.

Provider-specific config attributes are stored as strings in the database (map[string]string). When reading from the database, if a providerSchema is provided, the service will coerce provider-specific attributes from strings to their proper types (bool, int, etc.) according to the provider's schema. This ensures that provider code can safely type-assert these values without panicking.

func NewProviderService

func NewProviderService(
	st ProviderState,
	modelConfigProviderGetterFunc ModelConfigProviderFunc,
) *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)

	// NamespacesForWatchModelConfig returns the namespace identifiers used for
	// watching model configuration changes.
	NamespacesForWatchModelConfig() []string

	// GetModelAgentVersionAndStream returns the current model's set agent
	// version and stream.
	GetModelAgentVersionAndStream(context.Context) (ver string, stream string, err 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,
	modelConfigProviderGetterFunc ModelConfigProviderFunc,
	st State,
) *Service

NewService creates a new ModelConfig service.

func (*Service) GetModelConfigSchemaForCloudType

func (s *Service) GetModelConfigSchemaForCloudType(ctx context.Context, cloudType string) (configschema.Fields, error)

GetModelConfigSchemaForCloudType returns the schema of the model config for a given cloud provider

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. - Agent stream is not changed 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

	// 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,
	modelConfigProviderGetterFunc ModelConfigProviderFunc,
	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,
	modelConfigProviderGetterFunc ModelConfigProviderFunc,
	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 {
	// NewNamespaceMapperWatcher returns a new watcher that receives changes
	// from the input base watcher's db/queue. Change-log events will be emitted
	// only if the filter accepts them, and dispatching the notifications via
	// the Changes channel, once the mapper has processed them. Filtering of
	// values is done first by the filter, and then by the mapper. Based on the
	// mapper's logic a subset of them (or none) may be emitted. A filter option
	// is required, though additional filter options can be provided.
	NewNamespaceMapperWatcher(
		ctx context.Context,
		initialStateQuery eventsource.NamespaceQuery,
		summary string,
		mapper eventsource.Mapper,
		filterOption eventsource.FilterOption, filterOptions ...eventsource.FilterOption,
	) (watcher.StringsWatcher, error)
}

WatcherFactory describes methods for creating watchers.

Jump to

Keyboard shortcuts

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