Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,23 @@ async def premium(user: CloudflareUser = Depends(require_full)):
"""

def dependency(request: Request) -> CloudflareUser:
"""Validate that the current user meets ``minimum_tier``.

Resolved as a FastAPI dependency by :func:`require_tier`. The user is
loaded from request state via :func:`get_current_user`; tiers are
ordered ``LIMITED < FULL < ADMIN``.

Args:
request: Incoming FastAPI/Starlette request.

Returns:
The authenticated :class:`CloudflareUser`.

Raises:
HTTPException: ``403`` if the user's tier is below
``minimum_tier``; ``401`` (via :func:`get_current_user`) if
the request is unauthenticated.
"""
user = get_current_user(request)

tier_order = {
Expand Down
14 changes: 13 additions & 1 deletion packages/cloudflare-auth/src/cloudflare_auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,19 @@ def mask_sensitive_data(
'Contact ***@***.*** for help'
"""

def mask_match(match):
def mask_match(match: re.Match[str]) -> str:
"""Replace a regex match with a masked representation.

For email-like matches (containing ``@``), masks the local and domain
parts separately. For all other matches, replaces every character
with ``*``.

Args:
match: Regex match object produced by :func:`re.sub`.

Returns:
Masked replacement string for the matched text.
"""
matched = match.group(0)
if "@" in matched:
# Email-like pattern
Expand Down
6 changes: 6 additions & 0 deletions src/python_libs/middleware/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Middleware components for Python Libs.

This namespace package is reserved for middleware modules (request/response
hooks, ASGI/WSGI middleware, instrumentation). It is currently empty; submodules
will be added here as middleware features are introduced.
"""
Loading