-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove api brain secrets and schemas on delete (#1621)
Issue: #1573
- Loading branch information
1 parent
ee864e6
commit 8ed0adf
Showing
9 changed files
with
142 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from uuid import UUID | ||
|
||
from fastapi import HTTPException | ||
from models.brain_entity import BrainType | ||
from models.settings import get_supabase_db | ||
|
||
from repository.api_brain_definition.delete_api_brain_definition import ( | ||
delete_api_brain_definition, | ||
) | ||
from repository.brain import get_brain_by_id | ||
from repository.brain.delete_brain_secrets import delete_brain_secrets | ||
from repository.knowledge.remove_brain_all_knowledge import ( | ||
remove_brain_all_knowledge, | ||
) | ||
|
||
|
||
def delete_brain(brain_id: UUID) -> dict[str, str]: | ||
supabase_db = get_supabase_db() | ||
|
||
brain_to_delete = get_brain_by_id(brain_id=brain_id) | ||
if brain_to_delete is None: | ||
raise HTTPException(status_code=404, detail="Brain not found.") | ||
|
||
if brain_to_delete.brain_type == BrainType.API: | ||
delete_brain_secrets( | ||
brain_id=brain_id, | ||
) | ||
delete_api_brain_definition(brain_id=brain_id) | ||
else: | ||
remove_brain_all_knowledge(brain_id) | ||
|
||
supabase_db.delete_brain_vector(str(brain_id)) | ||
supabase_db.delete_brain_users(str(brain_id)) | ||
supabase_db.delete_brain(str(brain_id)) | ||
|
||
return {"message": "Brain deleted."} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from uuid import UUID | ||
|
||
from fastapi import HTTPException | ||
from models.settings import get_supabase_db | ||
|
||
from repository.api_brain_definition.get_api_brain_definition import ( | ||
get_api_brain_definition, | ||
) | ||
from repository.external_api_secret import delete_secret | ||
|
||
|
||
def delete_brain_secrets(brain_id: UUID) -> None: | ||
supabase_db = get_supabase_db() | ||
|
||
brain_definition = get_api_brain_definition(brain_id=brain_id) | ||
|
||
if brain_definition is None: | ||
raise HTTPException(status_code=404, detail="Brain definition not found.") | ||
|
||
secrets = brain_definition.secrets | ||
|
||
if len(secrets) > 0: | ||
brain_users = supabase_db.get_brain_users(brain_id=brain_id) | ||
for user in brain_users: | ||
for secret in secrets: | ||
delete_secret( | ||
user_id=user.user_id, | ||
brain_id=brain_id, | ||
secret_name=secret.name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from uuid import UUID | ||
|
||
from models.brain_entity import BrainUser | ||
from models.settings import get_supabase_db | ||
|
||
|
||
def get_brain_users(brain_id: UUID) -> list[BrainUser]: | ||
supabase_db = get_supabase_db() | ||
|
||
return supabase_db.get_brain_users(brain_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters