Skip to content

Commit 079f0ff

Browse files
committed
prepping to rebuild
1 parent c9aa178 commit 079f0ff

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

app/api/deps/get_client_ip.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
from ipaddress import IPv4Address
12
from typing import Annotated
23

34
from fastapi import Depends, Request
5+
from pydantic import IPvAnyAddress
46

57

6-
def get_request_client_ip(request: Request) -> str:
8+
def get_request_client_ip(request: Request) -> IPv4Address:
79
forwarded_ip = request.headers.get("X-Forwarded-For")
810
if forwarded_ip:
9-
return forwarded_ip.split(",")[0]
11+
return IPv4Address(address=forwarded_ip.split(",")[0])
1012
elif request.client is not None:
11-
return request.client.host
12-
return "127.0.0.1" # pragma: no cover
13+
return IPv4Address(request.client.host)
14+
return IPv4Address("127.0.0.1") # pragma: no cover
1315

1416

15-
RequestClientIp = Annotated[str, Depends(get_request_client_ip)]
17+
RequestClientIp = Annotated[IPvAnyAddress, Depends(get_request_client_ip)]

app/core/security/auth/exceptions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ class HTTPAuth0Error(BaseModel):
2222

2323

2424
def configure_authorization_exceptions(app: FastAPI) -> None:
25-
2625
@app.exception_handler(Auth0UnauthenticatedException)
2726
async def auth0_unauthenticated_exception_handler(
2827
request: Request, exc: Auth0UnauthenticatedException
2928
) -> Response: # noqa: E501
30-
request_headers = {}
29+
request_headers: dict = {}
3130
if exc.headers is not None:
3231
request_headers.update(exc.headers) # pragma: no cover
3332
return await http_exception_handler(
@@ -43,7 +42,7 @@ async def auth0_unauthenticated_exception_handler(
4342
async def auth0_unauthorized_exception_handler(
4443
request: Request, exc: Auth0UnauthorizedException
4544
) -> Response: # noqa: E501
46-
request_headers = {}
45+
request_headers: dict = {}
4746
if exc.headers is not None:
4847
request_headers.update(exc.headers)
4948
return await http_exception_handler(

app/tasks/background.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def bg_task_create_client_data_bucket(
6969
logger.warning(e)
7070

7171

72-
async def bg_task_track_user_ipinfo(ip_address: str, user_id: str) -> None:
72+
async def bg_task_track_user_ipinfo(ip_address: IPvAnyAddress, user_id: str) -> None:
7373
"""A background task to track the IP Address of a user.
7474
7575
This function will:
@@ -80,7 +80,7 @@ async def bg_task_track_user_ipinfo(ip_address: str, user_id: str) -> None:
8080
"""
8181
try:
8282
user_uuid = parse_id(user_id)
83-
ip = IPvAnyAddress(ip_address)
83+
ip: IPvAnyAddress = ip_address
8484
ip_in_db: Ipaddress | None = await get_ipaddress_from_db(ip) # type: ignore
8585
if ip_in_db is None:
8686
ip_details: IpinfoResponse = get_ipinfo_details(ip) # type: ignore

tests/api/v1/clients/test_clients_delete.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from app.api.exceptions import ErrorCode
1010
from app.core.config import settings
11-
from app.models import User, UserClient
11+
from app.models import User
1212
from app.schemas import ClientRead
1313

1414
pytestmark = pytest.mark.asyncio
@@ -43,9 +43,7 @@ async def test_delete_client_by_id_as_client_a(
4343
db_session=db_session, email=settings.auth.first_client_a
4444
)
4545
a_client: ClientRead = await create_random_client(db_session)
46-
user_client: UserClient = await assign_user_to_client( # noqa: F841
47-
db_session, client_a, a_client
48-
)
46+
await assign_user_to_client(db_session, client_a, a_client)
4947
response: Response = await client.delete(
5048
f"clients/{a_client.id}",
5149
headers=client_a_token_headers,

0 commit comments

Comments
 (0)