Documentation
¶
Overview ¶
Package configstore persists the UI configuration (spec 3): objects and settings with a revision (config_rev), history snapshots, audit entries with a diff, and encrypted secrets. Validation of the whole configuration is done by the caller (internal/app).
Index ¶
- Constants
- Variables
- func Section(kind string) (string, error)
- type Change
- type Cipher
- type Deps
- type Key
- type Object
- type ObjectView
- type Overview
- type Problem
- type Sealer
- type Service
- func (sv *Service) Commit(ctx context.Context, base, next *Snapshot, by string) (int64, error)
- func (sv *Service) Load(ctx context.Context) (*Snapshot, error)
- func (sv *Service) Masked(kind string, o Object) map[string]any
- func (sv *Service) View(k Key, o Object) ObjectView
- func (sv *Service) WithObject(base *Snapshot, k Key, body map[string]any, by string) (*Snapshot, error)
- func (sv *Service) WithSettings(base *Snapshot, set map[string]any) (*Snapshot, error)
- func (sv *Service) WithoutObject(base *Snapshot, k Key) (*Snapshot, error)
- type SettingView
- type Settings
- type Snapshot
- type Store
- type ValidationError
Constants ¶
const ( KindConnection = "connection" KindDevice = "device" KindMeter = "meter" )
Kinds of UI objects.
const ActionChange = "config_change"
ActionChange is the audit action of a saved UI change.
const Masked = "***"
Masked is shown instead of a stored secret; sent back unchanged it keeps the secret.
Variables ¶
var ( // ErrNoKey is returned when a secret is read without a usable secret.key. ErrNoKey = errors.New("configstore: secret.key is missing") // ErrBadSecret is returned for a stored secret that cannot be decrypted. ErrBadSecret = errors.New("configstore: secret cannot be decrypted") )
var ( // ErrNotFound is returned for an unknown object. ErrNotFound = errors.New("configstore: not found") // ErrUnknownKind is returned for a kind other than connection, device or meter. ErrUnknownKind = errors.New("configstore: unknown kind") // ErrConflict is returned when another change was saved since the edited revision. ErrConflict = errors.New("configstore: configuration changed meanwhile") // ErrLocked is returned for objects and settings owned by config.yaml or env. ErrLocked = errors.New("configstore: defined in config.yaml") )
Functions ¶
Types ¶
type Change ¶
type Change struct {
Kind string `json:"kind"`
ID string `json:"id"`
Body map[string]any `json:"body"`
}
Change is one object write of a batch (PUT /api/v1/config, the setup probe); a nil Body deletes the object.
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher encrypts the secrets of the UI configuration with XChaCha20-Poly1305 and the 256-bit key in secret.key. A Cipher without key (CLI jobs that must not create one) fails every Seal and Open with ErrNoKey.
func LoadKey ¶
LoadKey reads the key file; a missing file is created with a new key when create is set (server start), else the returned Cipher has no key.
type Object ¶
type Object struct {
Body map[string]any // file form: {"connection": "lan", "auth": {"password": …}}
UpdatedAt time.Time
UpdatedBy string
Unreadable []string // secret paths that could not be decrypted (lost secret.key)
// contains filtered or unexported fields
}
Object is one UI object with plain secrets.
type ObjectView ¶
type ObjectView struct {
Kind string `json:"kind"`
ID string `json:"id"`
Locked bool `json:"locked"` // defined in config.yaml or env: read-only
Body map[string]any `json:"body"`
UpdatedAt *time.Time `json:"updated_at"`
UpdatedBy string `json:"updated_by,omitempty"`
Unreadable []string `json:"unreadable,omitempty"` // secrets to enter again
}
ObjectView is one object as the settings API shows it (secrets masked).
type Overview ¶
type Overview struct {
Rev int64 `json:"config_rev"`
Objects []ObjectView `json:"objects"`
Settings map[string]SettingView `json:"settings"`
}
Overview is the whole configuration as the settings pages need it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service loads, edits and commits the UI configuration.
func (*Service) Commit ¶
Commit stores next as the change from base and returns the new revision; without a difference nothing is written. ErrConflict when another change was saved since base.
func (*Service) Load ¶
Load reads the stored UI configuration and decrypts its secrets; a secret that cannot be decrypted is empty and listed in Object.Unreadable.
func (*Service) View ¶
func (sv *Service) View(k Key, o Object) ObjectView
View returns the view of a stored object.
func (*Service) WithObject ¶
func (sv *Service) WithObject(base *Snapshot, k Key, body map[string]any, by string, ) (*Snapshot, error)
WithObject returns base with the object k set to body. A secret sent as Masked keeps the stored value; secret references (${env:…}, ${file:…}) are refused, because they would let the UI read server files and variables.
func (*Service) WithSettings ¶
WithSettings returns base with the given settings; a nil value removes the setting (back to the default).
type SettingView ¶
type SettingView struct {
Value any `json:"value"`
Locked bool `json:"locked"` // set in config.yaml or env
Stored bool `json:"stored"` // set in the UI configuration (else default or file)
}
SettingView is one UI setting with its effective value.
type Settings ¶
type Settings struct {
// Secrets lists the secret paths inside an object body per kind ("auth.password").
Secrets map[string][]string
// SettingKeys are the settings the UI may change.
SettingKeys []string
}
Settings describe the schema parts the store needs to know.
type Snapshot ¶
type Snapshot struct {
Rev int64
Objects map[Key]Object
Settings map[string]any // flat keys: "site.name"
}
Snapshot is the UI configuration at one revision. It is never changed in place: the With… methods of Store return a new one.
type Store ¶
type Store interface {
ConfigState(ctx context.Context) (storage.ConfigState, error)
ApplyConfig(ctx context.Context, c storage.ConfigChange) (int64, error)
}
Store is the interface of storage the config service needs.
type ValidationError ¶
type ValidationError struct{ Problems []Problem }
ValidationError lists every problem of a change (HTTP 422).
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string