2014-04-26 09:18:56 +00:00
package ConfigurationDB
2014-10-19 17:19:11 +00:00
import (
"github.com/SommerEngineering/Ocean/Log"
LM "github.com/SommerEngineering/Ocean/Log/Meta"
"gopkg.in/mgo.v2/bson"
)
2014-04-26 09:18:56 +00:00
2015-06-17 15:44:52 +00:00
// Internal function to check the system configuration.
2014-04-26 09:18:56 +00:00
func checkConfiguration ( ) {
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameDATABASE , ` Check now the configuration database. ` )
defer Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameDATABASE , ` Done checking the configuration database. ` )
2014-11-08 17:37:33 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` DefaultLanguageCode ` , ` en-GB ` )
2014-11-07 09:46:33 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerBinding ` , ` 127.0.0.1:60000 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerEnabled ` , ` True ` )
2017-02-02 21:15:48 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerPassword ` , ` ` )
2016-03-16 09:11:05 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerUseTLS ` , ` False ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerTLSCertificateName ` , ` certificateAdmin.pem ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerTLSPrivateKey ` , ` privateKeyAdmin.pem ` )
2014-11-07 09:46:33 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerReadTimeoutSeconds ` , ` 10 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerWriteTimeoutSeconds ` , ` 10 ` )
2015-06-27 17:57:14 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` AdminWebServerMaxHeaderLenBytes ` , ` 10485760 ` )
2015-06-21 18:19:36 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerPort ` , ` 50000 ` )
2016-03-16 11:26:48 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerHostname ` , ` www.my-site.domain ` )
2014-11-07 12:00:55 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerReadTimeoutSeconds ` , ` 10 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerWriteTimeoutSeconds ` , ` 10 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerMaxHeaderLenBytes ` , ` 1048576 ` )
2016-03-16 09:11:05 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerUseTLS ` , ` False ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerTLSCertificateName ` , ` certificatePublic.pem ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` PublicWebServerTLSPrivateKey ` , ` privateKeyPublic.pem ` )
2014-04-26 09:18:56 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` InternalCommPassword ` , ` please replace this with e.g. a random GUID, etc. ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` CustomerDBHost ` , ` localhost:27017 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` CustomerDBDatabase ` , ` Ocean ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` CustomerDBUsername ` , ` root ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` CustomerDBPassword ` , ` please replace this with a good password ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBHost ` , ` localhost:27017 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBDatabase ` , ` Ocean ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBUsername ` , ` root ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBPassword ` , ` please replace this with a good password ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBCacheSizeNumberOfEvents ` , ` 50 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBCacheSizeTime2FlushSeconds ` , ` 6 ` )
2014-11-07 12:30:33 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBEventsExpire ` , ` True ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBEventsExpireAfterDays ` , ` 365 ` )
2015-02-26 15:37:36 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDBWebInterfaceNameCacheRefreshTimeSeconds ` , ` 500 ` )
2014-04-26 09:18:56 +00:00
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogBufferSize ` , ` 500 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDeviceDelayNumberEvents ` , ` 600 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogDeviceDelayTime2FlushSeconds ` , ` 5 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogTimeoutSeconds ` , ` 4 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogStaticFileRequests ` , ` false ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogUseDatabaseLogging ` , ` false ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` LogUseConsoleLogging ` , ` true ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` OceanUtilizeCPUs ` , ` 2 ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` FilenameWebResources ` , ` web.zip ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` MapStaticFiles2Root ` , ` false ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` MapStaticFiles2RootRootFile ` , ` index.html ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` EnableStaticFiles ` , ` true ` )
CheckSingleConfigurationPresentsAndAddIfMissing ( ` robots.txt ` , ` User - agent : *
Disallow : ` )
}
2015-06-17 15:44:52 +00:00
// Use this function to ensure that the database contains at least a default value for the configuration.
2014-04-26 09:18:56 +00:00
func CheckSingleConfigurationPresentsAndAddIfMissing ( name , value string ) {
if ! checkSingleConfigurationPresents ( name ) {
addSingleConfiguration ( name , value )
}
}
2015-06-17 15:44:52 +00:00
// Check if a configuration value is present.
2014-04-26 09:18:56 +00:00
func checkSingleConfigurationPresents ( name string ) ( result bool ) {
selection := bson . D { { "Name" , name } }
count , _ := collection . Find ( selection ) . Count ( )
return count > 0
}
2015-06-17 15:44:52 +00:00
// Adds a configuration value.
2014-04-26 09:18:56 +00:00
func addSingleConfiguration ( name , value string ) {
entry := ConfigurationDBEntry { }
entry . Name = name
entry . Value = value
collection . Insert ( entry )
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameDATABASE , ` Add a missing configuration to the configuration database. ` , ` Name= ` + name , ` Value= ` + value )
}