Реализовать уровень 3: приватное S3, вложения и сохранность при отказах
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
"""S3 operations with bounded timeouts and immutable server-generated keys."""
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
from src.config import setting
|
||||
|
||||
def client():
|
||||
return boto3.client('s3', endpoint_url=setting('S3_ENDPOINT','http://s3:9000'),
|
||||
aws_access_key_id=setting('S3_ACCESS_KEY'), aws_secret_access_key=setting('S3_SECRET_KEY'),
|
||||
region_name='us-east-1', config=Config(connect_timeout=2,read_timeout=5,
|
||||
retries={'total_max_attempts':1},s3={'addressing_style':'path'}))
|
||||
|
||||
BUCKET = setting('S3_BUCKET','attachments')
|
||||
|
||||
def object_lock(conn, key, wait=True):
|
||||
fn = 'pg_advisory_xact_lock' if wait else 'pg_try_advisory_xact_lock'
|
||||
row = conn.execute('SELECT '+fn+'(hashtextextended(%s,42)) AS locked',(key,)).fetchone()
|
||||
return wait or row['locked']
|
||||
Reference in New Issue
Block a user