Skip to content

Commit

Permalink
* Allow the user to set and exipration on the exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroff committed Nov 1, 2018
1 parent 5313523 commit a916727
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions django_kala/django_kala/platforms/aws/documents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import datetime

from django.conf import settings
from django.utils import timezone
from uuid import uuid4

import boto3
Expand All @@ -25,7 +28,8 @@ def upload_document(self, content, key):
Body=content,
Bucket=settings.S3_STORAGE_BUCKET,
Key='media/documents/{0}'.format(key),
ServerSideEncryption='AES256'
ServerSideEncryption='AES256',

)

def get_export_url(self, export):
Expand All @@ -42,12 +46,16 @@ def get_export_url(self, export):

def upload_export(self, export_path):
key = 'exports/{0}'.format(uuid4())
expires = timezone.now() + datetime.timedelta(days=settings.EXPORT_EXPIRATION_IN_DAYS)

s3 = boto3.resource('s3')
s3.meta.client.upload_file(
export_path,
settings.S3_STORAGE_BUCKET,
key
Filename=export_path,
Bucket=settings.S3_STORAGE_BUCKET,
Key=key,
ExtraArgs={
'Expires': expires
}
)

return {'Key': key}
Expand Down
2 changes: 2 additions & 0 deletions django_kala/django_kala/settings/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

if not DEBUG:
DEFAULT_FILE_STORAGE = 'django_kala.storage.MediaStorage'

EXPORT_EXPIRATION_IN_DAYS=5

0 comments on commit a916727

Please sign in to comment.