Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: public router adhere to LogHealthAndMetrics option #1014

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions backend/handler/public_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ import (

func NewPublicRouter(cfg *config.Config, persister persistence.Persister, prometheus echo.MiddlewareFunc) *echo.Echo {
e := echo.New()

e.Renderer = template.NewTemplateRenderer()

e.HideBanner = true
g := e.Group("")

e.HTTPErrorHandler = dto.NewHTTPErrorHandler(dto.HTTPErrorHandlerConfig{Debug: false, Logger: e.Logger})
e.Use(middleware.RequestID())
e.Use(hankoMiddleware.GetLoggerMiddleware())
if cfg.Log.LogHealthAndMetrics {
e.Use(hankoMiddleware.GetLoggerMiddleware())
} else {
g.Use(hankoMiddleware.GetLoggerMiddleware())
}

exposeHeader := []string{
httplimit.HeaderRetryAfter,
Expand Down Expand Up @@ -75,7 +78,7 @@ func NewPublicRouter(cfg *config.Config, persister persistence.Persister, promet
if cfg.Password.Enabled {
passwordHandler := NewPasswordHandler(persister, sessionManager, cfg, auditLogger)

password := e.Group("/password")
password := g.Group("/password")
password.PUT("", passwordHandler.Set, sessionMiddleware)
password.POST("/login", passwordHandler.Login)
}
Expand All @@ -84,17 +87,17 @@ func NewPublicRouter(cfg *config.Config, persister persistence.Persister, promet
statusHandler := NewStatusHandler(persister)

e.GET("/", statusHandler.Status)
e.GET("/me", userHandler.Me, sessionMiddleware)
g.GET("/me", userHandler.Me, sessionMiddleware)

user := e.Group("/users")
user := g.Group("/users")
user.POST("", userHandler.Create)
user.GET("/:id", userHandler.Get, sessionMiddleware)

e.POST("/user", userHandler.GetUserIdByEmail)
e.POST("/logout", userHandler.Logout, sessionMiddleware)
g.POST("/user", userHandler.GetUserIdByEmail)
g.POST("/logout", userHandler.Logout, sessionMiddleware)

if cfg.Account.AllowDeletion {
e.DELETE("/user", userHandler.Delete, sessionMiddleware)
g.DELETE("/user", userHandler.Delete, sessionMiddleware)
}

healthHandler := NewHealthHandler()
Expand All @@ -115,7 +118,7 @@ func NewPublicRouter(cfg *config.Config, persister persistence.Persister, promet
if err != nil {
panic(fmt.Errorf("failed to create well-known handler: %w", err))
}
wellKnown := e.Group("/.well-known")
wellKnown := g.Group("/.well-known")
wellKnown.GET("/jwks.json", wellKnownHandler.GetPublicKeys)
wellKnown.GET("/config", wellKnownHandler.GetConfig)

Expand All @@ -124,7 +127,7 @@ func NewPublicRouter(cfg *config.Config, persister persistence.Persister, promet
panic(fmt.Errorf("failed to create public email handler: %w", err))
}

webauthn := e.Group("/webauthn")
webauthn := g.Group("/webauthn")
webauthnRegistration := webauthn.Group("/registration", sessionMiddleware)
webauthnRegistration.POST("/initialize", webauthnHandler.BeginRegistration)
webauthnRegistration.POST("/finalize", webauthnHandler.FinishRegistration)
Expand All @@ -138,25 +141,25 @@ func NewPublicRouter(cfg *config.Config, persister persistence.Persister, promet
webauthnCredentials.PATCH("/:id", webauthnHandler.UpdateCredential)
webauthnCredentials.DELETE("/:id", webauthnHandler.DeleteCredential)

passcode := e.Group("/passcode")
passcode := g.Group("/passcode")
passcodeLogin := passcode.Group("/login")
passcodeLogin.POST("/initialize", passcodeHandler.Init)
passcodeLogin.POST("/finalize", passcodeHandler.Finish)

email := e.Group("/emails", sessionMiddleware)
email := g.Group("/emails", sessionMiddleware)
email.GET("", emailHandler.List)
email.POST("", emailHandler.Create)
email.DELETE("/:id", emailHandler.Delete)
email.POST("/:id/set_primary", emailHandler.SetPrimaryEmail)

thirdPartyHandler := NewThirdPartyHandler(cfg, persister, sessionManager, auditLogger)
thirdparty := e.Group("thirdparty")
thirdparty := g.Group("thirdparty")
thirdparty.GET("/auth", thirdPartyHandler.Auth)
thirdparty.GET("/callback", thirdPartyHandler.Callback)
thirdparty.POST("/callback", thirdPartyHandler.CallbackPost)

tokenHandler := NewTokenHandler(cfg, persister, sessionManager, auditLogger)
e.POST("/token", tokenHandler.Validate)
g.POST("/token", tokenHandler.Validate)

return e
}
Loading