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

Commit 54b5201

Browse files
authored
Handle reserved keywords for workspaces (#672)
This disallows the creation of workspaces with the names "default" and "active" Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent e49c72f commit 54b5201

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class WorkspaceAlreadyActiveError(WorkspaceCrudError):
1717
pass
1818

1919

20+
DEFAULT_WORKSPACE_NAME = "default"
21+
22+
# These are reserved keywords that cannot be used for workspaces
23+
RESERVED_WORKSPACE_KEYWORDS = [DEFAULT_WORKSPACE_NAME, "active"]
24+
25+
2026
class WorkspaceCrud:
2127

2228
def __init__(self):
@@ -29,6 +35,10 @@ async def add_workspace(self, new_workspace_name: str) -> Workspace:
2935
Args:
3036
name (str): The name of the workspace
3137
"""
38+
if new_workspace_name == "":
39+
raise WorkspaceCrudError("Workspace name cannot be empty.")
40+
if new_workspace_name in RESERVED_WORKSPACE_KEYWORDS:
41+
raise WorkspaceCrudError(f"Workspace name {new_workspace_name} is reserved.")
3242
db_recorder = DbRecorder()
3343
workspace_created = await db_recorder.add_workspace(new_workspace_name)
3444
return workspace_created
@@ -102,7 +112,7 @@ async def soft_delete_workspace(self, workspace_name: str):
102112
"""
103113
if workspace_name == "":
104114
raise WorkspaceCrudError("Workspace name cannot be empty.")
105-
if workspace_name == "default":
115+
if workspace_name == DEFAULT_WORKSPACE_NAME:
106116
raise WorkspaceCrudError("Cannot delete default workspace.")
107117

108118
selected_workspace = await self._db_reader.get_workspace_by_name(workspace_name)

0 commit comments

Comments
 (0)