Decorates errors and remove sentry dependency
This commit is contained in:
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
"gitlab.com/wpetit/goweb/template/html"
|
||||
@ -24,6 +23,8 @@ func getServiceContainer(ctx context.Context, conf *config.Config) (*service.Con
|
||||
|
||||
ctn.Provide(build.ServiceName, build.ServiceProvider(ProjectVersion, GitRef, BuildDate))
|
||||
|
||||
keyPairs := make([][]byte, 0)
|
||||
|
||||
// Generate random cookie authentication key if none is set
|
||||
if conf.HTTP.CookieAuthenticationKey == "" {
|
||||
logger.Info(ctx, "could not find cookie authentication key. generating one...")
|
||||
@ -36,30 +37,22 @@ func getServiceContainer(ctx context.Context, conf *config.Config) (*service.Con
|
||||
conf.HTTP.CookieAuthenticationKey = string(cookieAuthenticationKey)
|
||||
}
|
||||
|
||||
// Generate random cookie encryption key if none is set
|
||||
if conf.HTTP.CookieEncryptionKey == "" {
|
||||
logger.Info(ctx, "could not find cookie encryption key. generating one...")
|
||||
keyPairs = append(keyPairs, []byte(conf.HTTP.CookieAuthenticationKey))
|
||||
|
||||
cookieEncryptionKey, err := gorilla.GenerateRandomBytes(32)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not generate cookie encryption key")
|
||||
}
|
||||
|
||||
conf.HTTP.CookieEncryptionKey = string(cookieEncryptionKey)
|
||||
// Use cookie encryption key if set
|
||||
if conf.HTTP.CookieEncryptionKey != "" {
|
||||
keyPairs = append(keyPairs, []byte(conf.HTTP.CookieEncryptionKey))
|
||||
}
|
||||
|
||||
// Create and initialize HTTP session service provider
|
||||
cookieStore := sessions.NewCookieStore(
|
||||
[]byte(conf.HTTP.CookieAuthenticationKey),
|
||||
[]byte(conf.HTTP.CookieEncryptionKey),
|
||||
)
|
||||
cookieStore := sessions.NewCookieStore(keyPairs...)
|
||||
|
||||
// Define default cookie options
|
||||
cookieStore.Options = &sessions.Options{
|
||||
Path: "/",
|
||||
Path: conf.HTTP.CookiePath,
|
||||
HttpOnly: true,
|
||||
MaxAge: conf.HTTP.CookieMaxAge,
|
||||
SameSite: http.SameSiteStrictMode,
|
||||
SameSite: conf.HTTP.CookieSameSite,
|
||||
}
|
||||
|
||||
ctn.Provide(
|
||||
|
Reference in New Issue
Block a user