Decorates errors and remove sentry dependency

This commit is contained in:
2022-07-19 10:24:49 +02:00
parent 936a77efe2
commit d0583cc23b
7 changed files with 28 additions and 165 deletions

View File

@ -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(