Skip to content

Commit

Permalink
Initial CRUD API for workspaces
Browse files Browse the repository at this point in the history
This adds a simple and unimplemented REST API for workspaces. Workspaces
will be the base for all other resources in terms of REST resource
mapping, so these go first.

These are initially left entirely unimplemented as
#600 needs to merge

Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
  • Loading branch information
JAORMX committed Jan 17, 2025
1 parent 85fd8eb commit 2cf1dda
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Empty file added src/codegate/api/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions src/codegate/api/v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from fastapi import APIRouter
from fastapi.routing import APIRoute

from codegate.api import v1_models

v1 = APIRouter()


def uniq_name(route: APIRoute):
return f"v1_{route.name}"


@v1.get("/workspaces", tags=["Workspaces"], generate_unique_id_function=uniq_name)
async def list_workspaces() -> v1_models.ListWorkspacesResponse:
"""List all workspaces."""
raise NotImplementedError

@v1.get("/workspaces/active", tags=["Workspaces"], generate_unique_id_function=uniq_name)
async def list_active_workspaces() -> v1_models.ListActiveWorkspacesResponse:
"""List all active workspaces.
In it's current form, this function will only return one workspace. That is,
the globally active workspace."""
raise NotImplementedError

@v1.post("/workspaces", tags=["Workspaces"], generate_unique_id_function=uniq_name, status_code=201)
async def create_workspace(request: v1_models.CreateWorkspaceRequest):
"""Create a new workspace."""
raise NotImplementedError

@v1.get("/workspaces/{workspace_name}", tags=["Workspaces"], generate_unique_id_function=uniq_name)
async def get_workspace(workspace_name: str) -> v1_models.Workspace:
"""Get a workspace by name."""
raise NotImplementedError

@v1.delete("/workspaces/{workspace_name}", tags=["Workspaces"],
generate_unique_id_function=uniq_name, status_code=204)
async def delete_workspace(workspace_name: str):
"""Delete a workspace by name."""
raise NotImplementedError
20 changes: 20 additions & 0 deletions src/codegate/api/v1_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any

import pydantic


class Workspace(pydantic.BaseModel):
name: str

class ActiveWorkspace(Workspace):
# TODO: use a more specific type for last_updated
last_updated: Any

class ListWorkspacesResponse(pydantic.BaseModel):
workspaces: list[Workspace]

class ListActiveWorkspacesResponse(pydantic.BaseModel):
workspaces: list[ActiveWorkspace]

class CreateWorkspaceRequest(pydantic.BaseModel):
name: str
4 changes: 4 additions & 0 deletions src/codegate/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from starlette.middleware.errors import ServerErrorMiddleware

from codegate import __description__, __version__
from codegate.api.v1 import v1
from codegate.dashboard.dashboard import dashboard_router
from codegate.pipeline.factory import PipelineFactory
from codegate.providers.anthropic.provider import AnthropicProvider
Expand Down Expand Up @@ -97,4 +98,7 @@ async def health_check():
app.include_router(system_router)
app.include_router(dashboard_router)

# CodeGate API
app.include_router(v1, prefix="/api/v1", tags=["CodeGate API"])

return app

0 comments on commit 2cf1dda

Please sign in to comment.