fix(auth): allow auth module config to be injected#538
Conversation
WalkthroughThe authentication module's factory functions are refactored for improved modularity. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #538 +/- ##
==========================================
+ Coverage 29.11% 29.14% +0.03%
==========================================
Files 166 166
Lines 6711 6714 +3
==========================================
+ Hits 1954 1957 +3
Misses 4640 4640
Partials 117 117 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
auth/module.go (1)
37-56: Validate required configuration when enabled.When
cfg.Enabledis true but required fields likecfg.Issuerare empty, the OIDC discovery call at Line 46 will fail with a potentially unclear error. Consider adding explicit validation before attempting discovery.✅ Add validation for required fields
fx.Provide(func(cfg ModuleConfig, httpClient *http.Client) (oidc.KeySet, error) { if !cfg.Enabled { // this won't be used by the NoAuth return oidc.NewStaticKeySet(), nil } + if cfg.Issuer == "" { + return nil, fmt.Errorf("auth issuer is required when auth is enabled") + } retryableHttpClient := retryablehttp.NewClient()
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
auth/cli.goauth/module.go
🧰 Additional context used
🧬 Code graph analysis (1)
auth/module.go (3)
oidc/keyset.go (2)
KeySet(27-30)NewStaticKeySet(128-130)auth/middleware.go (1)
Authenticator(11-13)auth/no_auth.go (1)
NewNoAuth(11-13)
🔇 Additional comments (4)
auth/module.go (2)
24-30: LGTM! Clean separation of concerns.The refactoring successfully separates option construction (
ModuleOptions()) from module assembly, enabling external config injection while maintaining shared option logic.
60-72: LGTM! Correct conditional authentication provisioning.The authenticator correctly returns
NoAuthwhen disabled and JWT-based auth when enabled, properly utilizing all configuration fields includingCheckScopesandService.auth/cli.go (2)
25-40: LGTM! Clean flag-to-config translation.The exported
ModuleConfigFromFlagsfunction properly populates allModuleConfigfields from CLI flags, including the newly capturedCheckScopesandServicefields.
42-56: LGTM! Consistent usage of the new API.All call sites correctly use
ModuleConfigFromFlags(cmd)to populate configuration before passing it toModule(). TheAdditionalChecksappend pattern is preserved correctly in both organization-aware and custom-checks variants.
Fixes: EN-518