Skip to content

Commit a0a044f

Browse files
authored
Merge branch 'main' into cline
2 parents a659370 + 781de22 commit a0a044f

9 files changed

+21
-1
lines changed

alembic.ini

+6
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ prepend_sys_path = .
1515
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
1616
version_path_separator = os # Use os.pathsep.
1717

18+
# template used to generate migration file names
19+
file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
20+
# timezone to use when rendering the date within the migration file
21+
# as well as the filename.
22+
timezone = UTC
23+
1824
# DB connection string
1925
sqlalchemy.url = sqlite:///codegate_volume/db/codegate.db

src/codegate/api/v1.py

+2
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

+2
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

+11-1
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)