Improved the admin's interface
This commit is contained in:
1 parent
4138c85639
commit
6e1800aa5f
11 files changed
+326
-5
No files matched your search
@@ -16,7 +16,7 @@ func checkConfiguration() {
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`AdminWebServerEnabled`, `True`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`AdminWebServerReadTimeoutSeconds`, `10`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`AdminWebServerWriteTimeoutSeconds`, `10`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`AdminWebServerMaxHeaderLenBytes`, `1048576`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`AdminWebServerMaxHeaderLenBytes`, `10485760`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`PublicWebServerPort`, `50000`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`PublicWebServerReadTimeoutSeconds`, `10`)
|
||||
CheckSingleConfigurationPresentsAndAddIfMissing(`PublicWebServerWriteTimeoutSeconds`, `10`)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package ConfigurationDB
|
||||
|
||||
import (
|
||||
"github.com/SommerEngineering/Ocean/Log"
|
||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
// This function reads all configuration values e.g. for the admin's configuration web interface.
|
||||
func ReadAll() (values []ConfigurationDBEntry) {
|
||||
if errFind := collection.Find(bson.D{}).All(&values); errFind != nil {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `Was not able to read all configuration values out of the database.`, `Error while find.`, errFind.Error())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package ConfigurationDB
|
||||
|
||||
import (
|
||||
"github.com/SommerEngineering/Ocean/Log"
|
||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
// This function updates a configuration value e.g. from the admin's configuration web interface.
|
||||
func UpdateValue(name string, configuration ConfigurationDBEntry) {
|
||||
|
||||
// Check the configuration's name:
|
||||
if name == `` {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameSTATE, `Was not able to update a configuration value.`, `The given name was nil!`)
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure, that the configuration is already present:
|
||||
if count, errFind := collection.Find(bson.D{{"Name", name}}).Count(); errFind != nil {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `Was not able to update a configuration value.`, `Error while find the old value.`, errFind.Error())
|
||||
return
|
||||
} else {
|
||||
// Is the configuration already present?
|
||||
if count == 0 {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameSTATE, `Was not able to update a configuration value.`, `The desired configuration is not present.`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure, that the configuration value also uses the same name:
|
||||
if name != configuration.Name {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameSTATE, `Was not able to update a configuration value.`, `The given name was different with the name of the desired configuration value.`)
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
// Case: Any precondition is fulfilled
|
||||
//
|
||||
|
||||
// Selection of the correct configuration (the name is a unique value):
|
||||
selector := bson.D{{"Name", name}}
|
||||
if errUpdate := collection.Update(selector, configuration); errUpdate != nil {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `Was not able to update a configuration value.`, `Error while updating the database.`, errUpdate.Error())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user