Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yelinz
Copy link
Member

@Yelinz Yelinz commented Mar 24, 2025

fix document clone storage usage

@Yelinz Yelinz requested review from fugal-dy and StephanH90 March 24, 2025 10:07
@Yelinz Yelinz self-assigned this Mar 24, 2025
@Yelinz Yelinz force-pushed the fix-ssec-storage branch from b58fdb9 to 5cb803d Compare March 25, 2025 07:06
fix document clone storage usage
@Yelinz Yelinz force-pushed the fix-ssec-storage branch from 5cb803d to b80853a Compare March 25, 2025 07:22
Comment on lines -175 to +179
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})
Copy link
Contributor

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__.

Comment on lines 8 to +16
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's cool

Comment on lines 27 to 31
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)
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants