Skip to content

Conversation

@samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Oct 21, 2025

  • call changeProjectState when you edit or delete a project
  • call changeProjectState for all associated projects when you edit or delete a user
  • call changeProjectState for all associated projects when you edit or delete a provider
  • call deleteApiKeyCache when you edit or delete an api key

@ddanielcruzz ddanielcruzz requested a review from Copilot October 22, 2025 05:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a cache invalidation system for API key authentication to ensure consistency when projects, users, providers, or API keys are modified. The changes introduce a project state-based cache invalidation mechanism that uses random UUIDs to track project state changes and verify cache validity.

Key changes:

  • Replaced simple API key caching with a project state-based invalidation system
  • Added new exported functions (setProjectState, deleteApiKeyCache, setApiKeyCache) for cache management
  • Modified apiKeyAuth to accept an ExecutionContext parameter for async cache operations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
gateway/src/auth.ts Implements project state-based cache invalidation logic with changeProjectState, setApiKeyCache, and deleteApiKeyCache functions
gateway/src/gateway.ts Updates function calls to use renamed functions and pass ExecutionContext to apiKeyAuth
gateway/src/index.ts Exports new cache management functions for external use
gateway/test/auth.spec.ts Adds comprehensive tests verifying cache behavior and invalidation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


const CACHE_VERSION = 1
const CACHE_TTL = 86400
const CACHE_TTL = 86400 * 30
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

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

The magic number 30 should be extracted to a named constant (e.g., CACHE_TTL_DAYS) to clarify that this represents 30 days in seconds. This improves readability and maintainability: const CACHE_TTL_DAYS = 30; const CACHE_TTL = 86400 * CACHE_TTL_DAYS

Suggested change
const CACHE_TTL = 86400 * 30
const CACHE_TTL_DAYS = 30
const CACHE_TTL = 86400 * CACHE_TTL_DAYS

Copilot uses AI. Check for mistakes.
@Kludex Kludex merged commit b67b0da into main Oct 22, 2025
3 checks passed
@Kludex Kludex deleted the double-cache-api-key branch October 22, 2025 08:09
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.

3 participants