Add RequiresRestart attribute to config option

This commit is contained in:
Daniel 2019-08-02 16:10:07 +02:00
parent 456b53ae72
commit 05bead1890
2 changed files with 101 additions and 100 deletions

View file

@ -5,25 +5,25 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/safing/portbase/log"
"github.com/safing/portbase/database" "github.com/safing/portbase/database"
"github.com/safing/portbase/database/storage"
"github.com/safing/portbase/database/record"
"github.com/safing/portbase/database/query"
"github.com/safing/portbase/database/iterator" "github.com/safing/portbase/database/iterator"
"github.com/safing/portbase/database/query"
"github.com/safing/portbase/database/record"
"github.com/safing/portbase/database/storage"
"github.com/safing/portbase/log"
) )
var ( var (
dbController *database.Controller dbController *database.Controller
) )
// ConfigStorageInterface provices a storage.Interface to the configuration manager. // StorageInterface provices a storage.Interface to the configuration manager.
type ConfigStorageInterface struct { type StorageInterface struct {
storage.InjectBase storage.InjectBase
} }
// Get returns a database record. // Get returns a database record.
func (s *ConfigStorageInterface) Get(key string) (record.Record, error) { func (s *StorageInterface) Get(key string) (record.Record, error) {
optionsLock.Lock() optionsLock.Lock()
defer optionsLock.Unlock() defer optionsLock.Unlock()
@ -36,7 +36,7 @@ func (s *ConfigStorageInterface) Get(key string) (record.Record, error) {
} }
// Put stores a record in the database. // Put stores a record in the database.
func (s *ConfigStorageInterface) Put(r record.Record) error { func (s *StorageInterface) Put(r record.Record) error {
if r.Meta().Deleted > 0 { if r.Meta().Deleted > 0 {
return setConfigOption(r.DatabaseKey(), nil, false) return setConfigOption(r.DatabaseKey(), nil, false)
} }
@ -81,12 +81,12 @@ func (s *ConfigStorageInterface) Put(r record.Record) error {
} }
// Delete deletes a record from the database. // Delete deletes a record from the database.
func (s *ConfigStorageInterface) Delete(key string) error { func (s *StorageInterface) Delete(key string) error {
return setConfigOption(key, nil, false) return setConfigOption(key, nil, false)
} }
// Query returns a an iterator for the supplied query. // Query returns a an iterator for the supplied query.
func (s *ConfigStorageInterface) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error) { func (s *StorageInterface) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error) {
optionsLock.Lock() optionsLock.Lock()
defer optionsLock.Unlock() defer optionsLock.Unlock()
@ -104,7 +104,7 @@ func (s *ConfigStorageInterface) Query(q *query.Query, local, internal bool) (*i
return it, nil return it, nil
} }
func (s *ConfigStorageInterface) processQuery(q *query.Query, it *iterator.Iterator, opts []*Option) { func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator, opts []*Option) {
sort.Sort(sortableOptions(opts)) sort.Sort(sortableOptions(opts))
@ -121,7 +121,7 @@ func (s *ConfigStorageInterface) processQuery(q *query.Query, it *iterator.Itera
} }
// ReadOnly returns whether the database is read only. // ReadOnly returns whether the database is read only.
func (s *ConfigStorageInterface) ReadOnly() bool { func (s *StorageInterface) ReadOnly() bool {
return false return false
} }
@ -136,7 +136,7 @@ func registerAsDatabase() error {
return err return err
} }
controller, err := database.InjectDatabase("config", &ConfigStorageInterface{}) controller, err := database.InjectDatabase("config", &StorageInterface{})
if err != nil { if err != nil {
return err return err
} }

View file

@ -1,9 +1,9 @@
package config package config
import ( import (
"encoding/json"
"fmt" "fmt"
"regexp" "regexp"
"encoding/json"
"github.com/tidwall/sjson" "github.com/tidwall/sjson"
@ -47,6 +47,7 @@ type Option struct {
DefaultValue interface{} DefaultValue interface{}
ExternalOptType string ExternalOptType string
ValidationRegex string ValidationRegex string
RequiresRestart bool
compiledRegex *regexp.Regexp compiledRegex *regexp.Regexp
} }