feat: complete lab 7 for grade 4
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
sashadugina06
2026-12-04 13:55:32 +03:00
parent 20afc2c790
commit 11390b65fd
91 changed files with 10163 additions and 50 deletions
+40
View File
@@ -0,0 +1,40 @@
"""Private S3 access using bounded credentials and sanitized spans."""
import os
from threading import Lock
import boto3
from botocore.config import Config
from .credentials import credentials
from .telemetry import span
BUCKET = os.getenv("S3_BUCKET", "messenger-attachments")
class Storage:
def __init__(self):
self.lock = Lock()
self.keys = None
self.client = None
def __getattr__(self, name):
def call(*args, **kwargs):
with self.lock:
snapshot = credentials.get()
keys = snapshot["s3_user"], snapshot["s3_password"]
if keys != self.keys:
self.client = boto3.client(
"s3", endpoint_url="https://s3:9000", region_name="us-east-1",
aws_access_key_id=keys[0], aws_secret_access_key=keys[1],
verify=os.environ["TLS_CA_FILE"],
config=Config(connect_timeout=2, read_timeout=5,
retries={"total_max_attempts": 1}, s3={"addressing_style": "path"}),
)
self.keys = keys
client = self.client
with span(f"s3.{name}"):
return getattr(client, name)(*args, **kwargs)
return call
s3 = Storage()