Skip to content

Conversation

@Thushani-Jayasekera
Copy link
Contributor

Relates to : wso2/gateway-controllers#36

#968

Summary

  • Enhance ValidateAPIKey to return API key details on successful validation
  • Update all test cases to handle the new return signature
  • Add test assertions to verify returned API key details

Changes

common/apikey/store.go

  • Modified ValidateAPIKey method signature to return (bool, *APIKey, error) instead
    of (bool, error)
  • Now returns the full APIKey object when validation succeeds, allowing callers to
    access metadata like CreatedBy, ExpiresAt, etc.
  • Updated all return statements throughout the method to include the API key object
    or nil as appropriate

common/apikey/api_key_hash_test.go

  • Updated all ValidateAPIKey call sites to handle the new three-value return
    signature
  • Added test assertions to verify the returned API key details contain expected
    values (e.g., CreatedBy field)
  • Used blank identifier _ where API key details aren't needed in negative test cases

Motivation

This enhancement provides callers with access to the full API key metadata after
successful validation, enabling use cases such as audit logging, usage tracking, and
authorization decisions based on key properties without requiring additional lookups

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Warning

Rate limit exceeded

@Thushani-Jayasekera has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@Thushani-Jayasekera Thushani-Jayasekera changed the title Refactor API key validation to return API key details [Discussion WIP] Refactor API key validation to return API key details Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant