ЛР 5 — БВТ2303 — Брезгунова — на 5

This commit is contained in:
2026-11-13 13:10:15 +03:00
parent 276dbdad8a
commit ab9161be3d
64 changed files with 5191 additions and 34 deletions
+30
View File
@@ -0,0 +1,30 @@
"""Shared dependencies. No raw credentials are printed or exposed through HTTP."""
import os
from pathlib import Path
import boto3
from botocore.config import Config
import psycopg
from psycopg.rows import dict_row
BUCKET = os.getenv('S3_BUCKET', 'messenger-attachments')
PREFIX = 'results/'
STORAGE_LOCK = 440004
def setting(name, default=''):
path = os.getenv(name + '_FILE')
return Path(path).read_text().strip() if path else os.getenv(name, default)
def db():
return psycopg.connect(setting('DATABASE_URL'), row_factory=dict_row,
connect_timeout=3, options='-c statement_timeout=15000 -c lock_timeout=10000')
def s3():
return boto3.client('s3', endpoint_url=os.getenv('S3_ENDPOINT', 'http://s3:9000'),
region_name=os.getenv('S3_REGION', 'us-east-1'),
aws_access_key_id=setting('S3_ACCESS_KEY_ID'),
aws_secret_access_key=setting('S3_SECRET_ACCESS_KEY'),
config=Config(connect_timeout=3, read_timeout=10, max_pool_connections=16,
retries={'total_max_attempts': 1}, s3={'addressing_style': 'path'}))