Skip to content

Commit

Permalink
fix imp instantiation for computing addons
Browse files Browse the repository at this point in the history
  • Loading branch information
felliott committed Dec 31, 2024
1 parent c31da07 commit d00a0ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions addon_service/addon_imp/instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
CitationConfig,
)
from addon_toolkit.interfaces.computing import (
ComputingAddonClientRequestorImp,
ComputingAddonHttpRequestorImp,
ComputingAddonImp,
ComputingConfig,
)
Expand Down Expand Up @@ -113,14 +115,22 @@ async def get_computing_addon_instance(
"""create an instance of a `ComputingAddonImp`"""

assert issubclass(imp_cls, ComputingAddonImp)
return imp_cls(
config=config,
network=GravyvaletHttpRequestor(
client_session=await get_singleton_client_session(),
prefix_url=config.external_api_url,
account=account,
),
)
assert (
imp_cls is not ComputingAddonImp
), "Addons shouldn't directly extend ComputingAddonImp"
if issubclass(imp_cls, ComputingAddonHttpRequestorImp):
imp = imp_cls(
config=config,
network=GravyvaletHttpRequestor(
client_session=await get_singleton_client_session(),
prefix_url=config.external_api_url,
account=account,
),
)
if issubclass(imp_cls, ComputingAddonClientRequestorImp):
imp = imp_cls(credentials=await account.get_credentials__async(), config=config)

return imp


get_computing_addon_instance__blocking = async_to_sync(get_computing_addon_instance)
2 changes: 1 addition & 1 deletion addon_service/authorized_account/computing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def execute_post_auth_hook(self, auth_extras: dict | None = None):
imp = await get_computing_addon_instance(
self.imp_cls,
self,
self.computing_imp_config,
self.config,
)
self.external_account_id = await imp.get_external_account_id(auth_extras or {})
await self.asave()
Expand Down

0 comments on commit d00a0ff

Please sign in to comment.