Skip to content

Commit

Permalink
Add s3 file storage key prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Psykar committed Mar 1, 2019
1 parent 1a10aa3 commit 8d90730
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,4 @@ def immutable_file_test(path, url):
WHITENOISE_IMMUTABLE_FILE_TEST = immutable_file_test

S3_FILE_BUCKET = env.str('DJANGO_S3_FILE_BUCKET')
S3_FILE_PREFIX = env.str('DJANGO_S3_FILE_PREFIX', default='missioncontrol/filestorage/')
8 changes: 5 additions & 3 deletions missioncontrol/home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,16 @@ class S3File(models.Model, Serializable):
task_run = models.ForeignKey(TaskRun, to_field='uuid', related_name='files',
on_delete=models.PROTECT, null=True, blank=True)

# TODO prefix these keys
def get_prefix(self):
return f'{settings.S3_FILE_PREFIX}{self.cid}'

def get_download_url(self):
s3 = boto3.client('s3')
url = s3.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': self.bucket,
'Key': self.cid,
'Key': self.get_prefix(),
}
)

Expand All @@ -498,7 +500,7 @@ def get_upload_url(self):
s3 = boto3.client('s3')
post = s3.generate_presigned_post(
Bucket=self.bucket,
Key=self.cid
Key=self.get_prefix()
)

return post
Expand Down

0 comments on commit 8d90730

Please sign in to comment.