Skip to content

Commit

Permalink
- code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-andriy committed Nov 28, 2024
1 parent 3fc6784 commit 9ba2170
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions addon_imps/storage/owncloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def get_external_account_id(self, auth_result_extras: dict[str, str]) -> s
response_xml = await response.text_content()
return self._parse_displayname(response_xml)

@property
def _fallback_username(self) -> str | None:
return "default-username"

Expand Down
32 changes: 20 additions & 12 deletions addon_service/common/waterbutler_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@ class JSONAPIMeta:
credentials = serializers.SerializerMethodField("_credentials_for_waterbutler")
config = serializers.SerializerMethodField("_config_for_waterbutler")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._wb_config_cache = {}

def _get_wb_config(self, configured_storage_addon):
cache_key = configured_storage_addon.id
if cache_key in self._wb_config_cache:
return self._wb_config_cache[cache_key]
else:
imp = get_storage_addon_instance__blocking(
configured_storage_addon.imp_cls,
configured_storage_addon.base_account,
configured_storage_addon.config,
)
wb_config = async_to_sync(imp.build_wb_config)()
self._wb_config_cache[cache_key] = wb_config
return wb_config

def _credentials_for_waterbutler(self, configured_storage_addon):
_creds_data = configured_storage_addon.credentials
imp = get_storage_addon_instance__blocking(
configured_storage_addon.imp_cls,
configured_storage_addon.base_account,
configured_storage_addon.config,
)
wb_config = async_to_sync(imp.build_wb_config)()
wb_config = self._get_wb_config(configured_storage_addon)

match type(_creds_data):
case credentials.AccessTokenCredentials:
Expand All @@ -50,10 +63,5 @@ def _credentials_for_waterbutler(self, configured_storage_addon):
raise ValueError(f"unknown credentials type: {_creds_data}")

def _config_for_waterbutler(self, configured_storage_addon: ConfiguredStorageAddon):
imp = get_storage_addon_instance__blocking(
configured_storage_addon.imp_cls,
configured_storage_addon.base_account,
configured_storage_addon.config,
)
wb_config = async_to_sync(imp.build_wb_config)()
wb_config = self._get_wb_config(configured_storage_addon)
return wb_config

0 comments on commit 9ba2170

Please sign in to comment.