mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-01-15 20:02: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
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/steveiliop56/tinyauth/internal/config"
|
|
"github.com/steveiliop56/tinyauth/internal/utils/tlog"
|
|
)
|
|
|
|
type AccessControlsService struct {
|
|
docker *DockerService
|
|
static map[string]config.App
|
|
}
|
|
|
|
func NewAccessControlsService(docker *DockerService, static map[string]config.App) *AccessControlsService {
|
|
return &AccessControlsService{
|
|
docker: docker,
|
|
static: static,
|
|
}
|
|
}
|
|
|
|
func (acls *AccessControlsService) Init() error {
|
|
return nil // No initialization needed
|
|
}
|
|
|
|
func (acls *AccessControlsService) lookupStaticACLs(domain string) (config.App, error) {
|
|
for app, config := range acls.static {
|
|
if config.Config.Domain == domain {
|
|
tlog.App.Debug().Str("name", app).Msg("Found matching container by domain")
|
|
return config, nil
|
|
}
|
|
|
|
if strings.SplitN(domain, ".", 2)[0] == app {
|
|
tlog.App.Debug().Str("name", app).Msg("Found matching container by app name")
|
|
return config, nil
|
|
}
|
|
}
|
|
return config.App{}, errors.New("no results")
|
|
}
|
|
|
|
func (acls *AccessControlsService) GetAccessControls(domain string) (config.App, error) {
|
|
// First check in the static config
|
|
app, err := acls.lookupStaticACLs(domain)
|
|
|
|
if err == nil {
|
|
tlog.App.Debug().Msg("Using ACls from static configuration")
|
|
return app, nil
|
|
}
|
|
|
|
// Fallback to Docker labels
|
|
tlog.App.Debug().Msg("Falling back to Docker labels for ACLs")
|
|
return acls.docker.GetLabels(domain)
|
|
}
|