From d9bc378822c74ff0fdf75a0fdfd233667c460741 Mon Sep 17 00:00:00 2001 From: Mark Waddle Date: Mon, 21 Oct 2024 17:55:07 +0000 Subject: [PATCH] Conditional display of API key Show the API key, and API key secret name, when "secure" registrations are configured in the service --- .../AssistantServiceRegistrationEditor.tsx | 34 +++++++++++-------- .../assistant_service_registration.py | 24 +++++++++---- .../controller/convert.py | 9 +++-- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/workbench-app/src/routes/AssistantServiceRegistrationEditor.tsx b/workbench-app/src/routes/AssistantServiceRegistrationEditor.tsx index 7692fb59..101ba1f7 100644 --- a/workbench-app/src/routes/AssistantServiceRegistrationEditor.tsx +++ b/workbench-app/src/routes/AssistantServiceRegistrationEditor.tsx @@ -104,21 +104,27 @@ export const AssistantServiceRegistrationEditor: React.FC = () => { setName(data.value)} /> - -
- - -
-
{assistantServiceRegistration.apiKeyName && ( - -
- - -
-
+ <> + +
+ + +
+
+ +
+ + +
+
+ )} AssistantServiceRegistration: async with self._get_session() as session: @@ -134,7 +138,9 @@ async def get_registration(self, assistant_service_id: str) -> AssistantServiceR api_key = await self._api_key_store.get(registration.api_key_name) masked_api_key = self.mask_api_key(api_key) - return convert.assistant_service_registration_from_db(registration, api_key=masked_api_key) + return convert.assistant_service_registration_from_db( + registration, api_key=masked_api_key, include_api_key_name=self._registration_is_secured + ) @staticmethod def mask_api_key(api_key: str | None) -> str | None: @@ -187,7 +193,9 @@ async def update_registration( await session.commit() await session.refresh(registration) - return convert.assistant_service_registration_from_db(registration) + return convert.assistant_service_registration_from_db( + registration, include_api_key_name=self._registration_is_secured + ) async def update_assistant_service_url( self, @@ -238,7 +246,9 @@ async def update_assistant_service_url( await session.commit() await session.refresh(registration) - return convert.assistant_service_registration_from_db(registration), background_task_args + return convert.assistant_service_registration_from_db( + registration, include_api_key_name=self._registration_is_secured + ), background_task_args async def _update_participants( self, @@ -290,7 +300,9 @@ async def reset_api_key( api_key = await self._api_key_store.reset(registration.api_key_name) - return convert.assistant_service_registration_from_db(registration, api_key=api_key) + return convert.assistant_service_registration_from_db( + registration, api_key=api_key, include_api_key_name=self._registration_is_secured + ) async def check_assistant_service_online_expired(self) -> None: async with self._get_session() as session: diff --git a/workbench-service/semantic_workbench_service/controller/convert.py b/workbench-service/semantic_workbench_service/controller/convert.py index 5ad6833b..b3bcf02d 100644 --- a/workbench-service/semantic_workbench_service/controller/convert.py +++ b/workbench-service/semantic_workbench_service/controller/convert.py @@ -52,6 +52,7 @@ def user_list_from_db(models: Iterable[db.User]) -> UserList: def assistant_service_registration_from_db( model: db.AssistantServiceRegistration, + include_api_key_name: bool, api_key: str | None = None, ) -> AssistantServiceRegistration: return AssistantServiceRegistration( @@ -62,7 +63,7 @@ def assistant_service_registration_from_db( name=model.name, description=model.description, include_in_listing=model.include_in_listing, - api_key_name=model.api_key_name, + api_key_name=model.api_key_name if include_api_key_name else "", api_key=api_key, assistant_service_url=model.assistant_service_url, assistant_service_online=model.assistant_service_online, @@ -71,10 +72,12 @@ def assistant_service_registration_from_db( def assistant_service_registration_list_from_db( - models: Iterable[db.AssistantServiceRegistration], + models: Iterable[db.AssistantServiceRegistration], include_api_key_name: bool ) -> AssistantServiceRegistrationList: return AssistantServiceRegistrationList( - assistant_service_registrations=[assistant_service_registration_from_db(model=a) for a in models] + assistant_service_registrations=[ + assistant_service_registration_from_db(model=a, include_api_key_name=include_api_key_name) for a in models + ] )