mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-01-16 12:22:30 +00:00
* Refactor logging to use centralized logger utility - Removed direct usage of zerolog in multiple files and replaced it with a centralized logging utility in the `utils` package. - Introduced `Loggers` struct to manage different loggers (Audit, HTTP, App) with configurable levels and outputs. - Updated all relevant files to utilize the new logging structure, ensuring consistent logging practices across the application. - Enhanced error handling and logging messages for better traceability and debugging. * refactor: update logging implementation to use new logger structure * Refactor logging to use tlog package - Replaced instances of utils logging with tlog in various controllers, services, and middleware. - Introduced audit logging for login success, login failure, and logout events. - Created tlog package with structured logging capabilities using zerolog. - Added tests for the new tlog logger functionality. * refactor: update logging configuration in environment files * fix: adding coderabbit suggestions * fix: ensure correct audit caller * fix: include reason in audit login failure logs
92 lines
2.5 KiB
Go
92 lines
2.5 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"github.com/steveiliop56/tinyauth/internal/repository"
|
|
"github.com/steveiliop56/tinyauth/internal/service"
|
|
"github.com/steveiliop56/tinyauth/internal/utils/tlog"
|
|
)
|
|
|
|
type Services struct {
|
|
accessControlService *service.AccessControlsService
|
|
authService *service.AuthService
|
|
dockerService *service.DockerService
|
|
ldapService *service.LdapService
|
|
oauthBrokerService *service.OAuthBrokerService
|
|
}
|
|
|
|
func (app *BootstrapApp) initServices(queries *repository.Queries) (Services, error) {
|
|
services := Services{}
|
|
|
|
ldapService := service.NewLdapService(service.LdapServiceConfig{
|
|
Address: app.config.Ldap.Address,
|
|
BindDN: app.config.Ldap.BindDN,
|
|
BindPassword: app.config.Ldap.BindPassword,
|
|
BaseDN: app.config.Ldap.BaseDN,
|
|
Insecure: app.config.Ldap.Insecure,
|
|
SearchFilter: app.config.Ldap.SearchFilter,
|
|
AuthCert: app.config.Ldap.AuthCert,
|
|
AuthKey: app.config.Ldap.AuthKey,
|
|
})
|
|
|
|
err := ldapService.Init()
|
|
|
|
if err == nil {
|
|
services.ldapService = ldapService
|
|
} else {
|
|
tlog.App.Warn().Err(err).Msg("Failed to initialize LDAP service, continuing without it")
|
|
}
|
|
|
|
dockerService := service.NewDockerService()
|
|
|
|
err = dockerService.Init()
|
|
|
|
if err != nil {
|
|
return Services{}, err
|
|
}
|
|
|
|
services.dockerService = dockerService
|
|
|
|
accessControlsService := service.NewAccessControlsService(dockerService, app.config.Apps)
|
|
|
|
err = accessControlsService.Init()
|
|
|
|
if err != nil {
|
|
return Services{}, err
|
|
}
|
|
|
|
services.accessControlService = accessControlsService
|
|
|
|
authService := service.NewAuthService(service.AuthServiceConfig{
|
|
Users: app.context.users,
|
|
OauthWhitelist: app.config.OAuth.Whitelist,
|
|
SessionExpiry: app.config.Auth.SessionExpiry,
|
|
SessionMaxLifetime: app.config.Auth.SessionMaxLifetime,
|
|
SecureCookie: app.config.Auth.SecureCookie,
|
|
CookieDomain: app.context.cookieDomain,
|
|
LoginTimeout: app.config.Auth.LoginTimeout,
|
|
LoginMaxRetries: app.config.Auth.LoginMaxRetries,
|
|
SessionCookieName: app.context.sessionCookieName,
|
|
IP: app.config.Auth.IP,
|
|
}, dockerService, services.ldapService, queries)
|
|
|
|
err = authService.Init()
|
|
|
|
if err != nil {
|
|
return Services{}, err
|
|
}
|
|
|
|
services.authService = authService
|
|
|
|
oauthBrokerService := service.NewOAuthBrokerService(app.context.oauthProviders)
|
|
|
|
err = oauthBrokerService.Init()
|
|
|
|
if err != nil {
|
|
return Services{}, err
|
|
}
|
|
|
|
services.oauthBrokerService = oauthBrokerService
|
|
|
|
return services, nil
|
|
}
|