Skip to content

Commit

Permalink
Displays api-key secret-name in registration editor (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
markwaddle authored Oct 21, 2024
1 parent 4d1c4b4 commit ceae651
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
31 changes: 23 additions & 8 deletions workbench-app/src/routes/AssistantServiceRegistrationEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button, Card, Checkbox, Field, Input, Textarea, makeStyles, tokens } fr
import React from 'react';
import { useParams } from 'react-router-dom';
import { AppView } from '../components/App/AppView';
import { CopyButton } from '../components/App/CopyButton';
import { Loading } from '../components/App/Loading';
import { AssistantServiceRegistrationApiKeyReset } from '../components/AssistantServiceRegistrations/AssistantServiceRegistrationApiKeyReset';
import {
Expand Down Expand Up @@ -103,14 +104,28 @@ export const AssistantServiceRegistrationEditor: React.FC = () => {
<Field label="Name">
<Input className={classes.input} value={name} onChange={(_event, data) => setName(data.value)} />
</Field>
<Field label="API Key (read-only)">
<div className={classes.row}>
<Input className={classes.input} value={assistantServiceRegistration.apiKey} readOnly />
<AssistantServiceRegistrationApiKeyReset
assistantServiceRegistration={assistantServiceRegistration}
/>
</div>
</Field>
{assistantServiceRegistration.apiKeyName && (
<>
<Field label="API Key (read-only)">
<div className={classes.row}>
<Input className={classes.input} value={assistantServiceRegistration.apiKey} readOnly />
<AssistantServiceRegistrationApiKeyReset
assistantServiceRegistration={assistantServiceRegistration}
/>
</div>
</Field>
<Field label="API Key secret name (read-only)">
<div className={classes.row}>
<Input
className={classes.input}
value={assistantServiceRegistration.apiKeyName}
readOnly
/>
<CopyButton data={assistantServiceRegistration.apiKeyName} />
</div>
</Field>
</>
)}
<Checkbox
label="Include this assistant service in everyone's create assistant list"
checked={includeInListing}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ async def create_registration(

await session.commit()

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 get_registrations(
self, user_ids: set[str], assistant_service_online: bool | None = None
Expand All @@ -117,7 +119,9 @@ async def get_registrations(

assistant_services = await session.exec(query_registrations)

return convert.assistant_service_registration_list_from_db(assistant_services)
return convert.assistant_service_registration_list_from_db(
assistant_services, include_api_key_name=self._registration_is_secured
)

async def get_registration(self, assistant_service_id: str) -> AssistantServiceRegistration:
async with self._get_session() as session:
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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
]
)


Expand Down

0 comments on commit ceae651

Please sign in to comment.