Skip to content

Commit

Permalink
fixing some simple bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhi1992002 committed Nov 13, 2024
1 parent cf1c20e commit 52cc8c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
14 changes: 13 additions & 1 deletion autogpt_platform/backend/backend/server/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pydantic

import backend.data.graph

from backend.data.api_key import APIKeyPermission, APIKeyWithoutHash

class Methods(enum.Enum):
SUBSCRIBE = "subscribe"
Expand Down Expand Up @@ -37,5 +37,17 @@ class CreateGraph(pydantic.BaseModel):
graph: backend.data.graph.Graph | None = None


class CreateAPIKeyRequest(pydantic.BaseModel):
name: str
permissions: typing.List[APIKeyPermission]
description: typing.Optional[str] = None

class CreateAPIKeyResponse(pydantic.BaseModel):
api_key: APIKeyWithoutHash
plain_text_key: str

class SetGraphActiveVersion(pydantic.BaseModel):
active_graph_version: int

class UpdatePermissionsRequest(pydantic.BaseModel):
permissions: typing.List[APIKeyPermission]
22 changes: 4 additions & 18 deletions autogpt_platform/backend/backend/server/routers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
from backend.data.block import BlockInput, CompletedBlockOutput
from backend.data.credit import get_block_costs, get_user_credit_model
from backend.data.user import get_or_create_user
from backend.data.api import APIKeyPermission, APIKeyWithoutHash, generate_api_key, get_api_key_by_id, list_user_api_keys, revoke_api_key, suspend_api_key, update_api_key_permissions
from backend.data.api_key import APIKeyPermission, APIKeyWithoutHash, generate_api_key, get_api_key_by_id, list_user_api_keys, revoke_api_key, suspend_api_key, update_api_key_permissions
from backend.executor import ExecutionManager, ExecutionScheduler
from backend.server.model import CreateGraph, SetGraphActiveVersion
from backend.server.model import CreateAPIKeyRequest, CreateAPIKeyResponse, CreateGraph, SetGraphActiveVersion, UpdatePermissionsRequest
from backend.server.utils import get_user_id
from backend.util.service import get_service_client
from backend.util.settings import Settings
Expand Down Expand Up @@ -526,19 +526,9 @@ async def update_configuration(


########################################################
##################### API ##############################
##################### API KEY ##############################
########################################################

class CreateAPIKeyRequest(BaseModel):
name: str
permissions: List[APIKeyPermission]
description: Optional[str] = None

class CreateAPIKeyResponse(BaseModel):
api_key: APIKeyWithoutHash
plain_text_key: str


@v1_router.post(
"/api-keys",
response_model=CreateAPIKeyResponse,
Expand Down Expand Up @@ -619,13 +609,9 @@ async def suspend_key(
tags=["api-keys"],
dependencies=[Depends(auth_middleware)],
)

class UpdatePermissionsRequest(BaseModel):
permissions: List[APIKeyPermission]

async def update_permissions(
key_id: str,
request: UpdatePermissionsRequest,
request: UpdatePermissionsRequest ,
user_id: Annotated[str, Depends(get_user_id)]
) -> APIKeyWithoutHash:
"""Update API key permissions"""
Expand Down

0 comments on commit 52cc8c0

Please sign in to comment.