Documentation
¶
Overview ¶
Package settings adapts plugin preferences and validation to the v1 gRPC transport.
Index ¶
- func ConvertAnyToInterface(anyValue *anypb.Any) (any, error)
- func ConvertInterfaceToAny(v any) (*anypb.Any, error)
- func FromProtoSetting(s *settingspb.Setting) settings.Setting
- func FromProtoSettingFileSelection(s *settingspb.SettingFileSelection) *settings.SettingFileSelection
- func ProtoTypeToSettingType(t settingspb.SettingType) settings.SettingType
- func SettingTypeToProtoType(t settings.SettingType) settingspb.SettingType
- func ToProtoSetting(s settings.Setting) *settingspb.Setting
- func ToProtoSettingFileSelection(s *settings.SettingFileSelection) *settingspb.SettingFileSelection
- type Client
- func (c *Client) CommitSettings(ctx context.Context, values map[string]any, persist settings.PersistFunc) (settings.CommitResult, error)
- func (c *Client) GetSetting(id string) (settings.Setting, error)
- func (c *Client) GetSettingValue(id string) (any, error)
- func (c *Client) ListSettings() map[string]settings.Setting
- func (c *Client) ValidateSetting(id string, value any) (settings.ValidationResult, error)
- type Provider
- type SettingsPlugin
- type SettingsPluginServer
- func (s *SettingsPluginServer) CommitSettings(stream settingspb.SettingsPlugin_CommitSettingsServer) error
- func (s *SettingsPluginServer) GetSetting(_ context.Context, in *settingspb.GetSettingRequest) (*settingspb.Setting, error)
- func (s *SettingsPluginServer) GetSettingValue(_ context.Context, in *settingspb.GetSettingValueRequest) (*settingspb.GetSettingValueResponse, error)
- func (s *SettingsPluginServer) ListSettings(_ context.Context, _ *emptypb.Empty) (*settingspb.ListSettingsResponse, error)
- func (s *SettingsPluginServer) ValidateSetting(_ context.Context, in *settingspb.ValidateSettingRequest) (*settingspb.ValidateSettingResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertAnyToInterface ¶
ConvertAnyToInterface decodes wrapped JSON; JSON numbers become float64 values.
func ConvertInterfaceToAny ¶
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; commits honor caller cancellation and a bounded deadline.
func (*Client) CommitSettings ¶ added in v0.10.0
func (c *Client) CommitSettings( ctx context.Context, values map[string]any, persist settings.PersistFunc, ) (settings.CommitResult, error)
CommitSettings persists normalized remote values before acknowledging publication. Keys remain opaque plugin setting IDs, matching ListSettings and hydration. A lost response after persistence is durable success with uncertain application.
func (*Client) GetSetting ¶
GetSetting returns remote metadata or the RPC error.
func (*Client) GetSettingValue ¶
GetSettingValue decodes a remote value, returning RPC or conversion errors.
func (*Client) ListSettings ¶
ListSettings returns remote metadata, or nil when the RPC fails.
func (*Client) ValidateSetting ¶ added in v0.7.0
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)
// CommitSettings validates once and publishes only after persistence succeeds.
// Unlike the base provider, persistence keys are opaque plugin setting IDs,
// matching ListSettings and the host's stored values used for hydration.
CommitSettings(ctx context.Context, values map[string]any, persist settings.PersistFunc) (settings.CommitResult, error)
}
Provider is the interface that must be implemented by the settings provider plugin implementations on either side of the RPC.
func NewProviderWrapper ¶
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. Cancellation releases the persistence callback waiting for acknowledgement.
func (*SettingsPluginServer) CommitSettings ¶ added in v0.10.0
func (s *SettingsPluginServer) CommitSettings(stream settingspb.SettingsPlugin_CommitSettingsServer) error
CommitSettings keeps validation, persistence and publication in one provider transaction.
func (*SettingsPluginServer) GetSetting ¶
func (s *SettingsPluginServer) GetSetting( _ context.Context, in *settingspb.GetSettingRequest, ) (*settingspb.Setting, error)
GetSetting returns metadata or an Internal status when the provider fails.
func (*SettingsPluginServer) GetSettingValue ¶
func (s *SettingsPluginServer) GetSettingValue( _ context.Context, in *settingspb.GetSettingValueRequest, ) (*settingspb.GetSettingValueResponse, error)
GetSettingValue encodes the provider value or reports an Internal status.
func (*SettingsPluginServer) ListSettings ¶
func (s *SettingsPluginServer) ListSettings( _ context.Context, _ *emptypb.Empty, ) (*settingspb.ListSettingsResponse, error)
ListSettings serializes provider metadata into a new response map.
func (*SettingsPluginServer) ValidateSetting ¶ added in v0.7.0
func (s *SettingsPluginServer) ValidateSetting( _ context.Context, in *settingspb.ValidateSettingRequest, ) (*settingspb.ValidateSettingResponse, error)
ValidateSetting executes registered callbacks in the plugin, without mutating values.