Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit d54b853

Browse files
committed
Handle reserved keywords for workspaces
This disallows the creation of workspaces with the names "default" and "active" Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent 8ae8b21 commit d54b853

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/codegate/api/v1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ async def create_workspace(request: v1_models.CreateWorkspaceRequest) -> v1_mode
6969
"Invalid workspace name. " "Please use only alphanumeric characters and dashes"
7070
),
7171
)
72+
except crud.WorkspaceCrudError as e:
73+
raise HTTPException(status_code=400, detail=str(e))
7274
except Exception:
7375
raise HTTPException(status_code=500, detail="Internal server error")
7476

src/codegate/pipeline/cli/commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ async def _add_workspace(self, flags: Dict[str, str], args: List[str]) -> str:
186186
return "Invalid workspace name: It should be alphanumeric and dashes"
187187
except AlreadyExistsError:
188188
return f"Workspace **{new_workspace_name}** already exists"
189+
except crud.WorkspaceCrudError:
190+
return "An error occurred while adding the workspace"
189191
except Exception:
190192
return "An error occurred while adding the workspace"
191193

src/codegate/workspaces/crud.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class WorkspaceAlreadyActiveError(WorkspaceCrudError):
1717
pass
1818

1919

20+
# These are reserved keywords that cannot be used for workspaces
21+
RESERVED_WORKSPACE_KEYWORDS = ["default", "active"]
22+
23+
2024
class WorkspaceCrud:
2125

2226
def __init__(self):
@@ -29,6 +33,10 @@ async def add_workspace(self, new_workspace_name: str) -> Workspace:
2933
Args:
3034
name (str): The name of the workspace
3135
"""
36+
if new_workspace_name == "":
37+
raise WorkspaceCrudError("Workspace name cannot be empty.")
38+
if new_workspace_name in RESERVED_WORKSPACE_KEYWORDS:
39+
raise WorkspaceCrudError(f"Workspace name {new_workspace_name} is reserved.")
3240
db_recorder = DbRecorder()
3341
workspace_created = await db_recorder.add_workspace(new_workspace_name)
3442
return workspace_created

0 commit comments

Comments
 (0)