Реализовать ЛР 7 на оценку 3

This commit is contained in:
2026-12-04 14:27:18 +03:00
parent 31d441184b
commit 7996ebbb48
59 changed files with 2236 additions and 498 deletions
+4 -5
View File
@@ -2,6 +2,7 @@ from __future__ import annotations
import asyncio
import certifi
import os
from dataclasses import dataclass
from datetime import datetime
from typing import BinaryIO, Iterator
@@ -66,7 +67,7 @@ class S3Storage:
timeout=Timeout(connect=2, read=5),
retries=Retry(total=1, connect=1, read=1, backoff_factor=0.1),
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
ca_certs=os.environ.get('TLS_CA_FILE') or certifi.where(),
),
)
self.bucket = bucket
@@ -82,14 +83,12 @@ class S3Storage:
async def ping(self) -> None:
try:
with tracer.start_as_current_span(
's3 bucket exists', kind=SpanKind.CLIENT,
's3 readiness object', kind=SpanKind.CLIENT,
attributes={'db.system': 's3', 's3.bucket.name': self.bucket},
):
exists = await asyncio.to_thread(self._client.bucket_exists, self.bucket)
await asyncio.to_thread(self._client.stat_object, self.bucket, 'originals/.health')
except Exception as error:
self._translate(error)
if not exists:
raise Unavailable('bucket объектного хранилища не создан')
async def put(self, key: str, source: BinaryIO, length: int, content_type: str) -> None:
source.seek(0)