Skip to content

Commit

Permalink
make gv helpers less storage-centric
Browse files Browse the repository at this point in the history
 * Include computing addons in the addons list from gravyvalet.

 * Suport other addon types when fetching wb credentials.

 [ENG-6825]
  • Loading branch information
felliott committed Jan 4, 2025
1 parent 7a83ac7 commit 7e6eae9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions osf/external/gravy_valet/request_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ACCOUNT_ENDPOINT = f'{API_BASE}authorized-storage-accounts/{{pk}}'
ADDONS_ENDPOINT = f'{API_BASE}configured-storage-addons'
GENERIC_ADDONS_ENDPOINT = f'{API_BASE}{{addon_type}}'
ADDON_ENDPOINT = f'{ADDONS_ENDPOINT}/{{pk}}'
ADDON_ENDPOINT = f'{GENERIC_ADDONS_ENDPOINT}/{{pk}}'
WB_CONFIG_ENDPOINT = f'{ADDON_ENDPOINT}/waterbutler-credentials'

USER_LIST_ENDPOINT = f'{API_BASE}user-references'
Expand All @@ -32,6 +32,8 @@
ADDON_EXTERNAL_SERVICE_PATH = 'base_account.external_storage_service'
ACCOUNT_EXTERNAL_CITATION_SERVICE_PATH = 'external_citation_service'
ADDON_EXTERNAL_CITATIONS_SERVICE_PATH = 'base_account.external_citation_service'
ACCOUNT_EXTERNAL_COMPUTING_SERVICE_PATH = 'external_computing_service'
ADDON_EXTERNAL_COMPUTING_SERVICE_PATH = 'base_account.external_computing_service'

CITATION_ITEM_TYPE_ALIASES = {
'COLLECTION': 'folder',
Expand Down Expand Up @@ -100,6 +102,11 @@ def iterate_accounts_for_user(requesting_user): # -> typing.Iterator[JSONAPIRes
requesting_user=requesting_user,
params={'include': f'{ACCOUNT_EXTERNAL_CITATION_SERVICE_PATH}'}
)
yield from iterate_gv_results(
endpoint_url=user_result.get_related_link('authorized_computing_accounts'),
requesting_user=requesting_user,
params={'include': f'{ACCOUNT_EXTERNAL_COMPUTING_SERVICE_PATH}'}
)


def iterate_addons_for_resource(requested_resource, requesting_user): # -> typing.Iterator[JSONAPIResultEntry]
Expand All @@ -124,11 +131,17 @@ def iterate_addons_for_resource(requested_resource, requesting_user): # -> typi
requested_resource=requested_resource,
params={'include': f'{ADDON_EXTERNAL_CITATIONS_SERVICE_PATH},{ACCOUNT_OWNER_PATH}'}
)
yield from iterate_gv_results(
endpoint_url=resource_result.get_related_link('configured_computing_addons'),
requesting_user=requesting_user,
requested_resource=requested_resource,
params={'include': f'{ADDON_EXTERNAL_COMPUTING_SERVICE_PATH},{ACCOUNT_OWNER_PATH}'}
)


def get_waterbutler_config(gv_addon_pk, requested_resource, requesting_user): # -> JSONAPIResultEntry
def get_waterbutler_config(gv_addon_pk, requested_resource, requesting_user, addon_type): # -> JSONAPIResultEntry
return get_gv_result(
endpoint_url=WB_CONFIG_ENDPOINT.format(pk=gv_addon_pk),
endpoint_url=WB_CONFIG_ENDPOINT.format(pk=gv_addon_pk, addon_type=addon_type),
requesting_user=requesting_user,
requested_resource=requested_resource
)
Expand Down
1 change: 1 addition & 0 deletions osf/external/gravy_valet/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def _fetch_wb_config(self):
gv_addon_pk=self.gv_data.resource_id,
requested_resource=self.configured_resource,
requesting_user=self.active_user,
addon_type=self.gv_data.resource_type,
)
self._credentials = result.get_attribute('credentials')
self._config = result.get_attribute('config')
Expand Down

0 comments on commit 7e6eae9

Please sign in to comment.