- Add SIGNED_URL_EXPIRATION environment variable (#8136)
- Update S3Storage to use configurable expiration time - Default remains 3600 seconds (1 hour) for backward compatibility - Add comprehensive unit tests with mocked S3 client - Update .env.example with documentation and examples
This commit is contained in:
parent
584a1aa725
commit
5f7ffcb37a
4 changed files with 214 additions and 3 deletions
|
|
@ -29,6 +29,8 @@ class S3Storage(S3Boto3Storage):
|
|||
self.aws_region = os.environ.get("AWS_REGION")
|
||||
# Use the AWS_S3_ENDPOINT_URL environment variable for the endpoint URL
|
||||
self.aws_s3_endpoint_url = os.environ.get("AWS_S3_ENDPOINT_URL") or os.environ.get("MINIO_ENDPOINT_URL")
|
||||
# Use the SIGNED_URL_EXPIRATION environment variable for the expiration time (default: 3600 seconds)
|
||||
self.signed_url_expiration = int(os.environ.get("SIGNED_URL_EXPIRATION", "3600"))
|
||||
|
||||
if os.environ.get("USE_MINIO") == "1":
|
||||
# Determine protocol based on environment variable
|
||||
|
|
@ -56,8 +58,10 @@ class S3Storage(S3Boto3Storage):
|
|||
config=boto3.session.Config(signature_version="s3v4"),
|
||||
)
|
||||
|
||||
def generate_presigned_post(self, object_name, file_type, file_size, expiration=3600):
|
||||
def generate_presigned_post(self, object_name, file_type, file_size, expiration=None):
|
||||
"""Generate a presigned URL to upload an S3 object"""
|
||||
if expiration is None:
|
||||
expiration = self.signed_url_expiration
|
||||
fields = {"Content-Type": file_type}
|
||||
|
||||
conditions = [
|
||||
|
|
@ -104,13 +108,15 @@ class S3Storage(S3Boto3Storage):
|
|||
def generate_presigned_url(
|
||||
self,
|
||||
object_name,
|
||||
expiration=3600,
|
||||
expiration=None,
|
||||
http_method="GET",
|
||||
disposition="inline",
|
||||
filename=None,
|
||||
):
|
||||
content_disposition = self._get_content_disposition(disposition, filename)
|
||||
"""Generate a presigned URL to share an S3 object"""
|
||||
if expiration is None:
|
||||
expiration = self.signed_url_expiration
|
||||
content_disposition = self._get_content_disposition(disposition, filename)
|
||||
try:
|
||||
response = self.s3_client.generate_presigned_url(
|
||||
"get_object",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue