fix: make NOTIFY_API_KEY optional — fall back to log-only email mode
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
NOTIFY_URL is a global platform credential; NOTIFY_API_KEY is project- scoped and may not be provisioned if notify setup failed or the notifyProvisioner wasn't configured. Previously the service would crash on startup with "invalid configuration: API key is required" when NOTIFY_URL was set but NOTIFY_API_KEY was missing. Now the condition checks both: only initialize the notify client when both NOTIFY_URL and NOTIFY_API_KEY are set. When either is absent, fall back to log-only mode with a warning (instead of os.Exit(1)). This is the correct behavior: email not delivered is survivable, but a service crash on startup breaks the entire application. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d91bfc50fa
commit
a843fd7ff4
@ -173,9 +173,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
logger.Info("email renderer loaded", "templates", len(emailRenderer.Purposes()))
|
logger.Info("email renderer loaded", "templates", len(emailRenderer.Purposes()))
|
||||||
|
|
||||||
// Create email sender — notify service in production (NOTIFY_URL set), log-only for dev.
|
// Create email sender — notify service in production (NOTIFY_URL + NOTIFY_API_KEY set), log-only for dev.
|
||||||
|
// NOTIFY_URL is a global platform credential; NOTIFY_API_KEY is project-scoped and may not be
|
||||||
|
// provisioned yet. If either is missing, fall back to log-only mode instead of crashing.
|
||||||
var emailSender port.EmailSender
|
var emailSender port.EmailSender
|
||||||
if cfg.NotifyURL != "" {
|
if cfg.NotifyURL != "" && cfg.NotifyAPIKey != "" {
|
||||||
notifyClient, err := notify.NewClient(notify.Config{
|
notifyClient, err := notify.NewClient(notify.Config{
|
||||||
URL: cfg.NotifyURL,
|
URL: cfg.NotifyURL,
|
||||||
APIKey: cfg.NotifyAPIKey,
|
APIKey: cfg.NotifyAPIKey,
|
||||||
@ -189,8 +191,12 @@ func main() {
|
|||||||
logger.Info("email sender initialized (notify)", "url", cfg.NotifyURL, "host", cfg.NotifyHost)
|
logger.Info("email sender initialized (notify)", "url", cfg.NotifyURL, "host", cfg.NotifyHost)
|
||||||
} else {
|
} else {
|
||||||
emailSender = emailadapter.NewLogSender(logger)
|
emailSender = emailadapter.NewLogSender(logger)
|
||||||
|
if cfg.NotifyURL != "" {
|
||||||
|
logger.Warn("email sender in log-only mode (NOTIFY_API_KEY not set)")
|
||||||
|
} else {
|
||||||
logger.Info("email sender initialized (log-only dev mode)")
|
logger.Info("email sender initialized (log-only dev mode)")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create services (business logic)
|
// Create services (business logic)
|
||||||
exampleService := service.NewExampleService(exampleRepo, logger)
|
exampleService := service.NewExampleService(exampleRepo, logger)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user