show warning log when secret_key is not set

This commit is contained in:
MaysWind
2024-07-07 21:27:41 +08:00
parent cc3e1f2978
commit a2d6aff28b
2 changed files with 23 additions and 0 deletions
+4
View File
@@ -55,6 +55,10 @@ func initializeSystem(c *cli.Context) (*settings.Config, error) {
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)
err = datastore.InitializeDataStore(config)
+19
View File
@@ -197,6 +197,7 @@ type Config struct {
UuidServerId uint8
// Secret
SecretKeyNoSet bool
SecretKey string
EnableTwoFactor bool
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 {
config.SecretKeyNoSet = !getConfigItemIsSet(configFile, sectionName, "secret_key")
config.SecretKey = getConfigItemStringValue(configFile, sectionName, "secret_key", defaultSecretKey)
config.EnableTwoFactor = getConfigItemBoolValue(configFile, sectionName, "enable_two_factor", true)
@@ -645,6 +647,23 @@ func getFinalPath(workingPath, p string) (string, error) {
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 {
environmentKey := getEnvironmentKey(sectionName, itemName)
environmentValue := os.Getenv(environmentKey)