settings

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 13 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package settings adapts plugin preferences and validation to the v1 gRPC transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertAnyToInterface

func ConvertAnyToInterface(anyValue *anypb.Any) (any, error)

ConvertAnyToInterface decodes wrapped JSON; JSON numbers become float64 values.

func ConvertInterfaceToAny

func ConvertInterfaceToAny(v any) (*anypb.Any, error)

ConvertInterfaceToAny wraps the JSON representation in a protobuf bytes value. It returns protobuf encoding errors; JSON-unsupported inputs encode empty bytes.

func FromProtoSetting

func FromProtoSetting(s *settingspb.Setting) settings.Setting

FromProtoSetting decodes metadata without restoring executable validators. Invalid values yield a sensitive zero setting; absent sensitivity metadata stays private.

func FromProtoSettingFileSelection

func FromProtoSettingFileSelection(s *settingspb.SettingFileSelection) *settings.SettingFileSelection

FromProtoSettingFileSelection preserves nil and shares the wire extension slice.

func ProtoTypeToSettingType

func ProtoTypeToSettingType(t settingspb.SettingType) settings.SettingType

ProtoTypeToSettingType maps known wire types and uses text for unknown values.

func SettingTypeToProtoType

func SettingTypeToProtoType(t settings.SettingType) settingspb.SettingType

SettingTypeToProtoType maps known types and uses text for unknown values.

func ToProtoSetting

func ToProtoSetting(s settings.Setting) *settingspb.Setting

ToProtoSetting encodes metadata without a validator and returns nil on encoding failure. Password types always carry sensitive metadata.

func ToProtoSettingFileSelection

func ToProtoSettingFileSelection(s *settings.SettingFileSelection) *settingspb.SettingFileSelection

ToProtoSettingFileSelection preserves nil and shares the extension slice with its input.

Types

type Client

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

Client forwards settings operations over an existing gRPC connection. Callers own the connection; methods other than validation use a background context.

func (*Client) GetSetting

func (c *Client) GetSetting(id string) (settings.Setting, error)

GetSetting returns remote metadata or the RPC error.

func (*Client) GetSettingValue

func (c *Client) GetSettingValue(id string) (any, error)

GetSettingValue decodes a remote value, returning RPC or conversion errors.

func (*Client) ListSettings

func (c *Client) ListSettings() map[string]settings.Setting

ListSettings returns remote metadata, or nil when the RPC fails.

func (*Client) SetSetting

func (c *Client) SetSetting(id string, value any) error

SetSetting encodes one value before asking the remote provider to update it.

func (*Client) SetSettings

func (c *Client) SetSettings(settings map[string]any) error

SetSettings encodes all values before submitting a single bulk update.

func (*Client) ValidateSetting added in v0.7.0

func (c *Client) ValidateSetting(id string, value any) (settings.ValidationResult, error)

ValidateSetting runs remote validation without mutation and bounds the RPC lifetime.

type Provider

type Provider interface {
	// ListSettings returns the settings store
	ListSettings() map[string]settings.Setting

	// GetSetting returns the setting by ID. This ID should be in the form of a dot separated string
	// that represents the path to the setting. For example, "appearance.theme"
	GetSetting(id string) (settings.Setting, error)

	// GetSettingValue returns the value of the setting by ID
	GetSettingValue(id string) (any, error)
	ValidateSetting(id string, value any) (settings.ValidationResult, error)

	// SetSetting sets the value of the setting by ID
	SetSetting(id string, value any) error

	// SetSettings sets multiple settings at once
	SetSettings(settings map[string]any) error
}

Provider is the interface that must be implemented by the settings provider plugin implementations on either side of the RPC.

func NewProviderWrapper

func NewProviderWrapper(base settings.Provider) Provider

NewProviderWrapper wraps the settings provider to allow for the scoped semantics of using the same setting provider for the core and for the plugins

TODO - this is a bit messy and should be refactored. It'll do for now, as we're just trying to get the plugin system working for the time being.

type SettingsPlugin

type SettingsPlugin struct {
	plugin.Plugin

	// Concrete implementation, written in Go. This is only used for plugins
	// that are written in Go.
	Impl Provider
}

SettingsPlugin serves or consumes settings through plugin.Plugin gRPC integration.

func (*SettingsPlugin) GRPCClient

func (p *SettingsPlugin) GRPCClient(
	_ context.Context,
	_ *plugin.GRPCBroker,
	c *grpc.ClientConn,
) (any, error)

GRPCClient wraps the broker-owned connection without taking ownership of its lifetime.

func (*SettingsPlugin) GRPCServer

func (p *SettingsPlugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer registers the supplied provider on the plugin-owned gRPC server.

type SettingsPluginServer

type SettingsPluginServer struct {
	// This is the real implementation
	Impl Provider
}

SettingsPluginServer exposes a provider through the settings RPC service. The provider owns synchronization; RPC cancellation does not cancel provider methods.

func (*SettingsPluginServer) GetSetting

GetSetting returns metadata or an Internal status when the provider fails.

func (*SettingsPluginServer) GetSettingValue

GetSettingValue encodes the provider value or reports an Internal status.

func (*SettingsPluginServer) ListSettings

ListSettings serializes provider metadata into a new response map.

func (*SettingsPluginServer) SetSetting

SetSetting decodes and validates one update through the provider.

func (*SettingsPluginServer) SetSettings

SetSettings decodes every input before calling the provider's bulk update method.

func (*SettingsPluginServer) ValidateSetting added in v0.7.0

ValidateSetting executes registered callbacks in the plugin, without mutating values.

Jump to

Keyboard shortcuts

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