forked from mtusi2026/mtusi2026lab7
feat: completed tasks for grade 4
This commit is contained in:
+18
-11
@@ -13,6 +13,23 @@ from app.core.tls import client_context
|
||||
from app.schemas.job import JobMessage
|
||||
|
||||
|
||||
async def connect_broker(settings: JobSettings):
|
||||
context = client_context(settings.broker_ca_file)
|
||||
if context is None:
|
||||
raise ValueError("RabbitMQ требует CA и клиентский сертификат")
|
||||
context.load_cert_chain(settings.broker_cert_file, settings.broker_key_file)
|
||||
return await aio_pika.connect(
|
||||
host=settings.broker_host,
|
||||
port=settings.broker_port,
|
||||
virtualhost=settings.broker_vhost,
|
||||
ssl=True,
|
||||
ssl_context=context,
|
||||
auth="external",
|
||||
timeout=5,
|
||||
heartbeat=30,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Delivery:
|
||||
id: AbstractIncomingMessage
|
||||
@@ -37,17 +54,7 @@ class JobBroker:
|
||||
or self.channel.is_closed
|
||||
):
|
||||
await self.aclose()
|
||||
self.connection = await aio_pika.connect(
|
||||
host=self.settings.broker_host,
|
||||
port=self.settings.broker_port,
|
||||
login=self.settings.broker_user,
|
||||
password=self.settings.broker_password_file.read_text().strip(),
|
||||
virtualhost=self.settings.broker_vhost,
|
||||
ssl=bool(self.settings.broker_ca_file),
|
||||
ssl_context=client_context(self.settings.broker_ca_file),
|
||||
timeout=5,
|
||||
heartbeat=30,
|
||||
)
|
||||
self.connection = await connect_broker(self.settings)
|
||||
self.channel = await self.connection.channel(
|
||||
publisher_confirms=True, on_return_raises=True
|
||||
)
|
||||
|
||||
+11
-1
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Collection
|
||||
from uuid import UUID
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.user import User
|
||||
@@ -45,3 +45,13 @@ async def get_existing_user_ids(
|
||||
result = await session.execute(stmt)
|
||||
existing_ids = set(result.scalars().all())
|
||||
return existing_ids
|
||||
|
||||
|
||||
async def replace_password_hash(
|
||||
session: AsyncSession, user_id: UUID, previous: str, replacement: str
|
||||
) -> None:
|
||||
await session.execute(
|
||||
update(User)
|
||||
.where(User.id == user_id, User.password_hash == previous)
|
||||
.values(password_hash=replacement)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user