mirror of
https://github.com/safing/portbase
synced 2025-09-04 11:40:23 +00:00
Make default api listen address configurable, fix race conditions
This commit is contained in:
parent
bbf06b31ac
commit
60dbbe55e9
3 changed files with 21 additions and 11 deletions
|
@ -8,8 +8,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
listenAddressFlag string
|
listenAddressFlag string
|
||||||
listenAddressConfig config.StringOption
|
listenAddressConfig config.StringOption
|
||||||
|
defaultListenAddress string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -37,13 +38,19 @@ func registerConfig() error {
|
||||||
Description: "Define on what IP and port the API should listen on. Be careful, changing this may become a security issue.",
|
Description: "Define on what IP and port the API should listen on. Be careful, changing this may become a security issue.",
|
||||||
ExpertiseLevel: config.ExpertiseLevelExpert,
|
ExpertiseLevel: config.ExpertiseLevelExpert,
|
||||||
OptType: config.OptTypeString,
|
OptType: config.OptTypeString,
|
||||||
DefaultValue: "127.0.0.1:18",
|
DefaultValue: defaultListenAddress,
|
||||||
ValidationRegex: "^([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}|\\[[:0-9A-Fa-f]+\\]:[0-9]{1,5})$",
|
ValidationRegex: "^([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}|\\[[:0-9A-Fa-f]+\\]:[0-9]{1,5})$",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
listenAddressConfig = config.GetAsString("api/listenAddress", "127.0.0.1:18")
|
listenAddressConfig = config.GetAsString("api/listenAddress", defaultListenAddress)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetDefaultAPIListenAddress(address string) {
|
||||||
|
if defaultListenAddress == "" {
|
||||||
|
defaultListenAddress = address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -367,7 +367,10 @@ func (api *DatabaseAPI) processSub(opID []byte, sub *database.Subscription) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// TODO: use upd, new and delete msgTypes
|
// TODO: use upd, new and delete msgTypes
|
||||||
if r.Meta().IsDeleted() {
|
r.Lock()
|
||||||
|
isDeleted := r.Meta().IsDeleted()
|
||||||
|
r.Unlock()
|
||||||
|
if isDeleted {
|
||||||
api.send(opID, dbMsgTypeDel, r.Key(), nil)
|
api.send(opID, dbMsgTypeDel, r.Key(), nil)
|
||||||
} else {
|
} else {
|
||||||
api.send(opID, dbMsgTypeUpd, r.Key(), data)
|
api.send(opID, dbMsgTypeUpd, r.Key(), data)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
modules.Register("config", prep, start, stop, "database")
|
modules.Register("config", prep, start, nil, "database")
|
||||||
}
|
}
|
||||||
|
|
||||||
func prep() error {
|
func prep() error {
|
||||||
|
@ -19,14 +19,14 @@ func prep() error {
|
||||||
func start() error {
|
func start() error {
|
||||||
configFilePath = path.Join(database.GetDatabaseRoot(), "config.json")
|
configFilePath = path.Join(database.GetDatabaseRoot(), "config.json")
|
||||||
|
|
||||||
err := loadConfig()
|
err := registerAsDatabase()
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return registerAsDatabase()
|
err = loadConfig()
|
||||||
}
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
func stop() error {
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue