Skip to content

Commit

Permalink
Adjust config route
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarhindi committed Nov 5, 2024
1 parent 8f349d7 commit 626656c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
36 changes: 33 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from fastapi import FastAPI
import json
from fastapi import FastAPI, status, responses
from api.healthcheck import Healthcheck
from starlette.middleware import Middleware
from api.misc import IsDemoRest, IsManagedRest
Expand All @@ -16,7 +16,7 @@
CognitionImport,
CognitionPrepareProject,
)
from config_handler import SERVICES_TO_NOTIFY, init_config
from config_handler import SERVICES_TO_NOTIFY, init_config, change_config, get_config
from fast_api.routes.organization import router as org_router
from fast_api.routes.project import router as project_router
from fast_api.routes.project_setting import router as project_setting_router
Expand Down Expand Up @@ -65,12 +65,41 @@
from util import security, clean_up
from middleware import log_storage
from submodules.model import session
from fast_api.models import (
ChangeRequest,
)

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

fastapi_app = FastAPI()

"""
Config routes (un-routed exposure)
"""


@fastapi_app.post("/change_config")
def change(request: ChangeRequest) -> responses.PlainTextResponse:
if change_config(json.loads(request.dict_string)):
notify_others_about_change_thread(SERVICES_TO_NOTIFY)
return responses.PlainTextResponse(status_code=status.HTTP_200_OK)


@fastapi_app.get("/full_config")
def full_config() -> responses.JSONResponse:
return responses.JSONResponse(
status_code=status.HTTP_200_OK, content=get_config(False)
)


@fastapi_app.get("/base_config")
def base_config() -> responses.JSONResponse:
return responses.JSONResponse(
status_code=status.HTTP_200_OK, content=get_config(True)
)


fastapi_app.include_router(
org_router, prefix=PREFIX_ORGANIZATION, tags=["organization"]
)
Expand Down Expand Up @@ -117,6 +146,7 @@
fastapi_app_internal.include_router(
task_execution_router, prefix=PREFIX_TASK_EXECUTION, tags=["task-execution"]
)

routes = [
Route("/notify/{path:path}", Notify),
Route("/healthcheck", Healthcheck),
Expand Down
26 changes: 1 addition & 25 deletions fast_api/routes/misc.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import json
from fastapi import APIRouter, Body, Request, status, responses
from fastapi import APIRouter, Body, Request, status
from fastapi.responses import PlainTextResponse
from config_handler import SERVICES_TO_NOTIFY, change_config, get_config
from exceptions.exceptions import ProjectAccessError
from fast_api.models import (
CancelTaskBody,
ModelProviderDeleteModelBody,
ModelProviderDownloadModelBody,
CreateCustomerButton,
UpdateCustomerButton,
ChangeRequest,
)
from fast_api.routes.client_response import pack_json_result, SILENT_SUCCESS_RESPONSE
from typing import Dict, Optional
Expand All @@ -19,7 +17,6 @@
from controller.monitor import manager as controller_manager
from controller.model_provider import manager as model_provider_manager
from controller.task_master import manager as task_master_manager
from notify_handler import notify_others_about_change_thread
from submodules.model import enums
from submodules.model.global_objects import customer_button as customer_button_db_go
import util.user_activity
Expand Down Expand Up @@ -50,27 +47,6 @@ def get_is_demo(request: Request) -> Dict:
return pack_json_result({"data": {"isDemo": is_demo}})


@router.post("/change_config")
def change(request: ChangeRequest) -> responses.PlainTextResponse:
if change_config(json.loads(request.dict_string)):
notify_others_about_change_thread(SERVICES_TO_NOTIFY)
return responses.PlainTextResponse(status_code=status.HTTP_200_OK)


@router.get("/full_config")
def full_config() -> responses.JSONResponse:
return responses.JSONResponse(
status_code=status.HTTP_200_OK, content=get_config(False)
)


@router.get("/base_config")
def base_config() -> responses.JSONResponse:
return responses.JSONResponse(
status_code=status.HTTP_200_OK, content=get_config(True)
)


@router.get("/version-overview")
def get_version_overview(request: Request) -> Dict:
data = manager.get_version_overview()
Expand Down

0 comments on commit 626656c

Please sign in to comment.