-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(storages): use ssec storage at correct times #798
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,17 @@ | |
from django.db.models.fields.files import FieldFile | ||
from storages.backends.s3 import S3Storage | ||
|
||
from alexandria.storages.backends.s3 import SsecGlobalS3Storage | ||
|
||
|
||
class DynamicStorageFieldFile(FieldFile): | ||
def __init__(self, instance, field, name): | ||
super().__init__(instance, field, name) | ||
self.storage = storages.create_storage( | ||
{"BACKEND": settings.ALEXANDRIA_FILE_STORAGE} | ||
) | ||
storage_backend = settings.ALEXANDRIA_FILE_STORAGE | ||
if settings.ALEXANDRIA_ENABLE_AT_REST_ENCRYPTION: | ||
from alexandria.core.models import File | ||
|
||
if instance.encryption_status == File.EncryptionStatus.SSEC_GLOBAL_KEY: | ||
self.storage = SsecGlobalS3Storage() | ||
storage_backend = "alexandria.storages.backends.s3.SsecGlobalS3Storage" | ||
self.storage = storages.create_storage({"BACKEND": storage_backend}) | ||
|
||
|
||
class DynamicStorageFileField(models.FileField): | ||
|
@@ -28,7 +25,9 @@ class DynamicStorageFileField(models.FileField): | |
# of Alexandria: https://github.com/projectcaluma/alexandria/issues/480 | ||
|
||
def __init__(self, storage=None, **kwargs): | ||
storage = storages.create_storage({"BACKEND": settings.ALEXANDRIA_FILE_STORAGE}) | ||
self.storage = storages.create_storage( | ||
{"BACKEND": settings.ALEXANDRIA_FILE_STORAGE} | ||
) | ||
super().__init__(storage=storage, **kwargs) | ||
Comment on lines
27
to
31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a bit hard to grasp. This is probably a noop. The whole thing might still work because of |
||
|
||
def pre_save(self, instance, add): | ||
|
@@ -56,8 +55,9 @@ def pre_save(self, instance, add): | |
"Set `ALEXANDRIA_FILE_STORAGE` to `alexandria.storages.s3.S3Storage`." | ||
) | ||
raise ImproperlyConfigured(msg) | ||
storage = SsecGlobalS3Storage() | ||
if instance.encryption_status == File.EncryptionStatus.SSEC_GLOBAL_KEY: | ||
self.storage = storage | ||
self.storage = storages.create_storage( | ||
{"BACKEND": "alexandria.storages.backends.s3.SsecGlobalS3Storage"} | ||
) | ||
_file = super().pre_save(instance, add) | ||
return _file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
clone
method appears to bypass the whole django-storages implementation. shouldn't that create a newFile
aka copy thelatest_original.content
for the clonedDocument
?