Merge pull request #3 from dato/export_job_inject_aws_endpoint_setting

Subclass boto3.Session to use AWS_S3_ENDPOINT_URL
This commit is contained in:
Hugh Rundle 2024-01-29 13:49:45 +11:00 committed by GitHub
commit f96ddaa3e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@
import logging
from uuid import uuid4
from boto3.session import Session as BotoSession
from s3_tar import S3Tar
from storages.backends.s3boto3 import S3Boto3Storage
@ -25,6 +26,14 @@ from bookwyrm.utils.tar import BookwyrmTarFile
logger = logging.getLogger(__name__)
class BookwyrmAwsSession(BotoSession):
"""a boto session that always uses settings.AWS_S3_ENDPOINT_URL"""
def client(service_name, **kwargs):
kwargs["endpoint_url"] = settings.AWS_S3_ENDPOINT_URL
return super().client(service_name, **kwargs)
class BookwyrmExportJob(ParentJob):
"""entry for a specific request to export a bookwyrm user"""
@ -211,6 +220,7 @@ class AddFileToTar(ChildJob):
s3_job = S3Tar(
settings.AWS_STORAGE_BUCKET_NAME,
f"exports/{filename}.tar.gz",
session=BookwyrmAwsSession(),
)
# save json file