Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Documentation

- Filled in remaining missing docstrings to reach 100% interrogate coverage
(up from 99.2%): module docstring for `python_libs.middleware`, docstring +
type annotations for the `mask_match` inner callback in
`cloudflare_auth.utils.mask_sensitive_data`, and docstring for the
`dependency` closure returned by `cloudflare_auth.middleware_enhanced.require_tier`.

### Changed

- Migrated `sonarcloud.yml` to use `python-sonarcloud.yml` reusable workflow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,22 @@ 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 require_tier. The user is loaded
from request state via get_current_user; tiers are ordered
LIMITED < FULL < ADMIN.

Args:
request: Incoming FastAPI/Starlette request.

Returns:
The authenticated CloudflareUser object.

Raises:
HTTPException: 403 if the user's tier is below minimum_tier; 401
(via 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 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 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