Allow to define secret key & move the secret key file to parent directory (#358)

This commit is contained in:
Thomas Miceli
2024-10-31 14:50:13 +01:00
committed by GitHub
parent 20372f44e4
commit 4fd0832df9
11 changed files with 98 additions and 43 deletions

View File

@ -6,10 +6,12 @@ import (
"os"
)
func GenerateSecretKey(filePath string) []byte {
// GenerateSecretKey generates a new secret key for sessions
// Returns the key and a boolean indicating if the key was generated
func GenerateSecretKey(filePath string) ([]byte, bool) {
key, err := os.ReadFile(filePath)
if err == nil {
return key
return key, false
}
key = securecookie.GenerateRandomKey(32)
@ -22,5 +24,5 @@ func GenerateSecretKey(filePath string) []byte {
log.Fatal().Err(err).Msgf("Failed to save the key to %s", filePath)
}
return key
return key, true
}