This commit is contained in:
cheykrym 2025-07-10 19:17:47 +03:00
parent b0250a47aa
commit 93387d0677
4 changed files with 15 additions and 8 deletions

View File

@ -3,11 +3,12 @@ from uuid import UUID
from fastapi import HTTPException, status from fastapi import HTTPException, status
from typing import List, Dict from typing import List, Dict
from config import settings from config import settings
from .utils import ssl_transport
async def get_profile_by_user_id(user_id: UUID, token: str) -> dict: async def get_profile_by_user_id(user_id: UUID, token: str) -> dict:
try: try:
async with httpx.AsyncClient(timeout=5.0, verify=False) as client: async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0,) as client:
response = await client.get( response = await client.get(
f"{settings.PROFILE_SERVICE}/user_id/{user_id}", f"{settings.PROFILE_SERVICE}/user_id/{user_id}",
headers={"Authorization": f"Bearer {token}"} headers={"Authorization": f"Bearer {token}"}
@ -27,7 +28,7 @@ async def get_profile_by_user_id(user_id: UUID, token: str) -> dict:
async def get_profiles_by_user_ids(user_ids: List[UUID], token: str, user_id: UUID) -> Dict[str, dict]: async def get_profiles_by_user_ids(user_ids: List[UUID], token: str, user_id: UUID) -> Dict[str, dict]:
try: try:
async with httpx.AsyncClient(timeout=5.0, verify=False) as client: async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0,) as client:
response = await client.post( response = await client.post(
f"{settings.PROFILE_SERVICE}/user_ids/internal", f"{settings.PROFILE_SERVICE}/user_ids/internal",
headers={"Authorization": f"Bearer {token}"}, headers={"Authorization": f"Bearer {token}"},

View File

@ -1,3 +1,4 @@
from .utils import get_datetime from .utils import get_datetime
from .utils import ssl_transport
__all__ = ["get_datetime"] __all__ = ["get_datetime", "ssl_transport"]

View File

@ -6,6 +6,7 @@ from typing import List
from dataclasses import dataclass from dataclasses import dataclass
from config import settings from config import settings
from .utils import ssl_transport
auth_scheme = HTTPBearer() auth_scheme = HTTPBearer()
@ -27,11 +28,7 @@ async def _fetch_current_user(
user_agent = request.headers.get("User-Agent", "(unknown)") user_agent = request.headers.get("User-Agent", "(unknown)")
try: try:
async with httpx.AsyncClient( async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0,) as client:
verify=settings.CA_CERT,
cert=(settings.CLIENT_FULLCHAIN, settings.CLIENT_PRIVKEY),
timeout=5.0
) as client:
response = await client.post( response = await client.post(
f"{settings.TOKEN_SERVICE}/decode", f"{settings.TOKEN_SERVICE}/decode",
json={ json={

View File

@ -0,0 +1,8 @@
import ssl
import httpx
from config import settings
ctx = ssl.create_default_context(cafile=settings.CA_CERT)
ctx.load_cert_chain(certfile=settings.CLIENT_FULLCHAIN, keyfile=settings.CLIENT_PRIVKEY)
ssl_transport = httpx.AsyncHTTPTransport(verify=ctx, http2=True)