Skip to content

Commit

Permalink
BI-5425 Allow for multiple PUBLIC_API_KEYs to enable its rotation (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantAnxiety authored Apr 16, 2024
1 parent 7d529bd commit 4c847ec
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
LOGGER = logging.getLogger(__name__)


def public_api_key_middleware(api_key: str) -> AIOHTTPMiddleware:
if not isinstance(api_key, str):
raise TypeError(f"API key must be a string, not '{type(api_key)}'")
def public_api_key_middleware(api_keys: tuple[str, ...]) -> AIOHTTPMiddleware:
if not isinstance(api_keys, tuple):
raise TypeError(f"API key must be a tuple, not '{type(api_keys)}'")

@web.middleware
@DSAPIRequest.use_dl_request
Expand All @@ -31,7 +31,7 @@ async def actual_public_api_key_middleware(dl_request: DSAPIRequest, handler: Ha
if inbound_api_key is None:
raise web.HTTPForbidden(reason="public api key required")

if inbound_api_key != api_key:
if inbound_api_key not in api_keys:
LOGGER.info("Invalid API key, rejecting request...")
raise web.HTTPForbidden(reason="invalid public api key")

Expand Down

0 comments on commit 4c847ec

Please sign in to comment.