-
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?
Conversation
b58fdb9
to
5cb803d
Compare
fix document clone storage usage
5cb803d
to
b80853a
Compare
storage = File.content.field.storage | ||
storage_backend = settings.ALEXANDRIA_FILE_STORAGE | ||
if settings.ALEXANDRIA_ENABLE_AT_REST_ENCRYPTION: | ||
storage_backend = "alexandria.storages.backends.s3.SsecGlobalS3Storage" | ||
storage = storages.create_storage({"BACKEND": storage_backend}) |
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.
is this necessary?
File.content.field.storage
is not based on the setting? okay, that's cool. The actual question is: why does DynamicStorageFieldFile
logic not apply here. Or: do we get to decide on the storage to use at this point or not? A clone
method should not be concerned with storage details at all. so I guess we'll have to get more abstract here.
The File.content.field.storage
should do the exact same thing based on the setting ALEXANDRIA_ENABLE_AT_REST_ENCRYPTION
and the alexandria/storages/fields.py
in DynamicStorageFieldFile
's __init__
.
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" |
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.
that's cool
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) |
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.
that's a bit hard to grasp. storage
is not handled here but self.storage
is. aka in the super()
sth sth statement the storage arg is passed on or always None
or the default is None
which we clearly don't want, right? How are conflicting values of self.storage
and super().__init__(storage=storage)
behave
fix document clone storage usage