Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "🔥 feat: Add support for context.Context in keyauth middleware" #3364

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sixcolors
Copy link
Member

Reverts #3287

Reversion of Middleware Changes in Fiber v3

Following discussions in issue #3358, we have reverted changes that attempted to copy values into context.Context within various middlewares. These changes were removed to maintain Fiber’s lightweight design, improve performance, and avoid unnecessary complexity for users who do not require context.Context.

Why Were These Changes Reverted?

  • Fiber prioritizes performance, and modifying context.Context for every request introduces unnecessary overhead.
  • Values are already accessible via c.Locals(), making context modifications redundant.
  • Users who need context.Context values can implement a trivial custom middleware without affecting default behavior.

@sixcolors sixcolors requested a review from a team as a code owner March 19, 2025 15:05
@sixcolors sixcolors requested review from gaby, ReneWerner87 and efectn and removed request for a team March 19, 2025 15:05
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

The pull request simplifies token extraction in the key authentication middleware by eliminating context handling via the standard library’s context.Context and focusing solely on the use of fiber.Ctx. The function now directly retrieves the token from fiber.Ctx’s locals, and test cases have been updated accordingly by removing nested tests and the invalid context type scenario.

Changes

File(s) Change Summary
middleware/keyauth/keyauth.go Removed the use of context.Context by deleting context.WithValue and related context setting. Updated TokenFromContext to accept only fiber.Ctx and streamlined token retrieval from locals.
middleware/keyauth/keyauth_test.go Simplified tests by removing nested sub-tests for context.Context and invalid context type checks. Now only tests token extraction from fiber.Ctx using the Authorization header.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client Request
    participant FC as fiber.Ctx
    participant TK as TokenFromContext
    C->>FC: Send request with Authorization header
    FC->>TK: Invoke TokenFromContext(Fiber.Ctx)
    TK->>FC: Retrieve token from Locals
    TK-->>FC: Return token (or empty string)
Loading

Possibly related issues

Suggested labels

📒 Documentation, v3

Suggested reviewers

  • gaby
  • ReneWerner87
  • efectn

Poem

I hopped through bits and bytes with care,
Removing contexts floating in the air.
With fiber as my trusty guide,
The token now in locals does reside.
A rabbit’s cheer in code so neat,
Hop along to make our middleware complete! 🐇

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87f3f0c and 811732c.

📒 Files selected for processing (2)
  • middleware/keyauth/keyauth.go (1 hunks)
  • middleware/keyauth/keyauth_test.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
middleware/keyauth/keyauth.go (1)
middleware/csrf/csrf.go (3) (3)
  • TokenFromContext (190-196)
  • token (97-97)
  • tokenKey (39-39)
middleware/keyauth/keyauth_test.go (2)
middleware/keyauth/keyauth.go (4) (4)
  • New (33-67)
  • TokenFromContext (71-77)
  • err (39-39)
  • err (83-83)
middleware/keyauth/config.go (1) (1)
  • Config (12-45)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Compare
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.24.x, macos-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: repeated
🔇 Additional comments (2)
middleware/keyauth/keyauth.go (1)

71-76: Function signature simplified to only accept fiber.Ctx

The TokenFromContext function has been simplified to only accept fiber.Ctx rather than a generic interface type, which aligns with the PR objective of removing unnecessary context.Context support. The implementation now directly retrieves the token from Locals storage, which is a more straightforward approach.

middleware/keyauth/keyauth_test.go (1)

505-533: Test simplified to focus only on fiber.Ctx

The test case has been appropriately simplified to match the updated TokenFromContext function signature. The test now focuses solely on validating token retrieval from fiber.Ctx without additional complexity of testing multiple context types, which aligns with the PR's goal of removing context.Context support.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Mar 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.72%. Comparing base (87f3f0c) to head (811732c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3364      +/-   ##
==========================================
- Coverage   83.73%   83.72%   -0.02%     
==========================================
  Files         118      118              
  Lines       11728    11718      -10     
==========================================
- Hits         9821     9811      -10     
  Misses       1481     1481              
  Partials      426      426              
Flag Coverage Δ
unittests 83.72% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 811732c Previous: 87f3f0c Ratio
Benchmark_Compress_Levels/Brotli_LevelBestCompression - B/op 6 B/op 0 B/op +∞

This comment was automatically generated by workflow using github-action-benchmark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant