add jwtkey config to avoid logging in again after reboot
This commit is contained in:
@@ -12,10 +12,16 @@ type Config struct {
|
||||
Port string `toml:"port" comment:"The port to listen on for the server."`
|
||||
DatabaseFilePath string `toml:"database_file_path" comment:"Path to sqlite database file."`
|
||||
DemoDataPath string `toml:"demo_data_path" comment:"The path to the sql file to load for demo data."`
|
||||
JWTKey string `toml:"jwt_key" comment:"The key used to encrypt the generated JWT. Encoded in base64. If empty a random one will be generated on every restart."`
|
||||
}
|
||||
|
||||
func defaultConfig() Config {
|
||||
return Config{Port: "8080", DatabaseFilePath: "plm.db", DemoDataPath: ""}
|
||||
return Config{
|
||||
Port: "8080",
|
||||
DatabaseFilePath: "plm.db",
|
||||
DemoDataPath: "",
|
||||
JWTKey: "",
|
||||
}
|
||||
}
|
||||
|
||||
func LoadConfig(configPath string) Config {
|
||||
|
||||
@@ -27,12 +27,17 @@ func getKeyVariableName() string {
|
||||
return "PLM_JWT_KEY"
|
||||
}
|
||||
|
||||
func InitKey() error {
|
||||
func InitKey(jwtkey string) error {
|
||||
var err error
|
||||
keyName := getKeyVariableName()
|
||||
//ignore config value, look in env first
|
||||
key := os.Getenv(keyName)
|
||||
if key == "" {
|
||||
key, err = generateSecureToken(64)
|
||||
if jwtkey != "" {
|
||||
key = jwtkey
|
||||
} else {
|
||||
key, err = generateSecureToken(64)
|
||||
}
|
||||
os.Setenv(keyName, key)
|
||||
}
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user