Refactor auth and authz

This commit is contained in:
2025-10-26 02:25:24 -07:00
parent 9ff782f7b6
commit abe7b6beee
22 changed files with 8018 additions and 62 deletions
+16 -14
View File
@@ -87,6 +87,15 @@ func main() {
logger.Fatalf("Queue type %s not implemented yet", cfg.Queue.Type)
}
// Initialize authentication if enabled (must be before service creation for RBAC)
var authStore *auth.APIKeyStore
var authz *auth.NotifierAuthz
if cfg.Auth.Enabled {
authStore = auth.NewAPIKeyStore()
authz = auth.NewNotifierAuthz()
logger.Info("API authentication enabled")
}
// Initialize notifier factory and register notifiers
factory := notifier.NewFactory()
registerNotifiers(cfg, factory, logger)
@@ -98,8 +107,13 @@ func main() {
logger.Infof("Supported notification types: %v", factory.SupportedTypes())
// Create notification service (pass config as account resolver)
svc := service.NewNotificationService(factory, q, cfg.Queue.WorkerCount, cfg, logger)
// Register authorization rules for notifiers (after factory registration)
if authz != nil {
registerAuthorizationRules(cfg, authz, logger)
}
// Create notification service (pass config as account resolver and authz for RBAC)
svc := service.NewNotificationService(factory, q, cfg.Queue.WorkerCount, cfg, authz, logger)
// Configure notification retention if enabled
if err := svc.WithRetentionConfig(cfg.Retention); err != nil {
@@ -117,18 +131,6 @@ func main() {
}
logger.Infof("Started %d worker(s)", cfg.Queue.WorkerCount)
// Initialize authentication if enabled
var authStore *auth.APIKeyStore
var authz *auth.NotifierAuthz
if cfg.Auth.Enabled {
authStore = auth.NewAPIKeyStore()
authz = auth.NewNotifierAuthz()
logger.Info("API authentication enabled")
// Register authorization rules for notifiers
registerAuthorizationRules(cfg, authz, logger)
}
// Wait group for both servers
var wg sync.WaitGroup