Allow for static secret

This commit is contained in:
Florian Hoss 2024-09-25 15:49:21 +02:00
parent dc2b5e8fb5
commit 387b89963d
Signed by: flohoss
GPG key ID: 5BA0B454E498DF62
2 changed files with 9 additions and 4 deletions

7
internal/env/env.go vendored
View file

@ -19,10 +19,11 @@ type Config struct {
WeatherUnits string `env:"WEATHER_UNITS" envDefault:"metric"` WeatherUnits string `env:"WEATHER_UNITS" envDefault:"metric"`
WeatherLanguage string `env:"WEATHER_LANG" envDefault:"en" validate:"bcp47_language_tag"` WeatherLanguage string `env:"WEATHER_LANG" envDefault:"en" validate:"bcp47_language_tag"`
WeatherDigits bool `env:"WEATHER_DIGITS" envDefault:"false"` WeatherDigits bool `env:"WEATHER_DIGITS" envDefault:"false"`
AuthClientID string `env:"AUTH_CLIENT_ID"` AuthClientID string `env:"AUTH_CLIENT_ID" validate:"required"`
AuthClientSecret string `env:"AUTH_CLIENT_SECRET"` AuthClientSecret string `env:"AUTH_CLIENT_SECRET" validate:"required"`
AuthScopes []string `env:"AUTH_SCOPES" envSeparator:"," envDefault:"openid,email,profile"` AuthScopes []string `env:"AUTH_SCOPES" envSeparator:"," envDefault:"openid,email,profile"`
AuthIssuer string `env:"AUTH_ISSUER"` AuthIssuer string `env:"AUTH_ISSUER" validate:"required,url,endsnotwith=/.well-known/openid-configuration"`
SessionKey string `env:"SESSION_KEY,unset"`
} }
var errParse = errors.New("error parsing environment variables") var errParse = errors.New("error parsing environment variables")

View file

@ -33,7 +33,11 @@ func main() {
b := services.NewBookmarkService() b := services.NewBookmarkService()
parsedUrl, _ := url.Parse(env.PublicUrl) parsedUrl, _ := url.Parse(env.PublicUrl)
store := sessions.NewCookieStore(securecookie.GenerateRandomKey(32)) secret := []byte(env.SessionKey)
if len(secret) == 0 {
secret = securecookie.GenerateRandomKey(32)
}
store := sessions.NewCookieStore(secret)
store.Options = &sessions.Options{ store.Options = &sessions.Options{
Domain: parsedUrl.Hostname(), Domain: parsedUrl.Hostname(),
MaxAge: 86400 * 30, MaxAge: 86400 * 30,