show warning log when secret_key is not set
This commit is contained in:
@@ -55,6 +55,10 @@ func initializeSystem(c *cli.Context) (*settings.Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.SecretKeyNoSet {
|
||||||
|
log.BootWarnf("[initializer.initializeSystem] \"secret_key\" in config file is not set, please change it to keep your user data safe")
|
||||||
|
}
|
||||||
|
|
||||||
settings.SetCurrentConfig(config)
|
settings.SetCurrentConfig(config)
|
||||||
|
|
||||||
err = datastore.InitializeDataStore(config)
|
err = datastore.InitializeDataStore(config)
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ type Config struct {
|
|||||||
UuidServerId uint8
|
UuidServerId uint8
|
||||||
|
|
||||||
// Secret
|
// Secret
|
||||||
|
SecretKeyNoSet bool
|
||||||
SecretKey string
|
SecretKey string
|
||||||
EnableTwoFactor bool
|
EnableTwoFactor bool
|
||||||
TokenExpiredTime uint32
|
TokenExpiredTime uint32
|
||||||
@@ -487,6 +488,7 @@ func loadUuidConfiguration(config *Config, configFile *ini.File, sectionName str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadSecurityConfiguration(config *Config, configFile *ini.File, sectionName string) error {
|
func loadSecurityConfiguration(config *Config, configFile *ini.File, sectionName string) error {
|
||||||
|
config.SecretKeyNoSet = !getConfigItemIsSet(configFile, sectionName, "secret_key")
|
||||||
config.SecretKey = getConfigItemStringValue(configFile, sectionName, "secret_key", defaultSecretKey)
|
config.SecretKey = getConfigItemStringValue(configFile, sectionName, "secret_key", defaultSecretKey)
|
||||||
config.EnableTwoFactor = getConfigItemBoolValue(configFile, sectionName, "enable_two_factor", true)
|
config.EnableTwoFactor = getConfigItemBoolValue(configFile, sectionName, "enable_two_factor", true)
|
||||||
|
|
||||||
@@ -645,6 +647,23 @@ func getFinalPath(workingPath, p string) (string, error) {
|
|||||||
return p, err
|
return p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getConfigItemIsSet(configFile *ini.File, sectionName string, itemName string) bool {
|
||||||
|
environmentKey := getEnvironmentKey(sectionName, itemName)
|
||||||
|
environmentValue := os.Getenv(environmentKey)
|
||||||
|
|
||||||
|
if len(environmentValue) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
section := configFile.Section(sectionName)
|
||||||
|
|
||||||
|
if !section.HasKey(itemName) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return section.Key(itemName).String() != ""
|
||||||
|
}
|
||||||
|
|
||||||
func getConfigItemStringValue(configFile *ini.File, sectionName string, itemName string, defaultValue ...string) string {
|
func getConfigItemStringValue(configFile *ini.File, sectionName string, itemName string, defaultValue ...string) string {
|
||||||
environmentKey := getEnvironmentKey(sectionName, itemName)
|
environmentKey := getEnvironmentKey(sectionName, itemName)
|
||||||
environmentValue := os.Getenv(environmentKey)
|
environmentValue := os.Getenv(environmentKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user