Refactor code structure and fix APIBaseUrl naming#24
Open
marcschaeferger wants to merge 1 commit into
Open
Conversation
Signed-off-by: Marc Schäfer <git@marcschaeferger.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request refactors and improves the
badger.gomiddleware, focusing on code clarity, maintainability, and correctness. The main changes include extracting and modularizing logic for session verification and exchange, introducing better error handling, and standardizing naming conventions. Several helper functions were added, and the code now uses a shared HTTP client with timeouts. There are also improvements to security and test coverage.Refactoring and modularization:
handleSessionExchange,buildOriginalURL,buildVerifyBody,handleVerifyResponse, etc.), making the main handler (ServeHTTP) much clearer and easier to maintain. [1] [2] [3]http.Clientwith a timeout to theBadgerstruct for all outbound HTTP requests.Error handling and security improvements:
renderRedirectPage, reducing possible XSS vectors. [1] [2]Naming and API consistency:
APIBaseUrltoAPIBaseURLthroughout the codebase for consistency, including in struct fields, variables, and test cases. [1] [2] [3] [4]UserIdtoUserIDin all relevant types.Configuration and initialization:
validateConfigfunction to check for required configuration fields when forward auth is enabled, improving startup validation.parseTrustedIPsmethod, improving clarity and error handling.Testing:
Note:
PR Titel and Description generated by AI (Copilot). Code Changes 90% human + 10% AI based on golangci linting and coderabbit review