generated from Luis/nextjs-python-web-template
backend: Fully working roles field. Added get_entity_by_roles #50
@@ -1,12 +1,8 @@
|
|||||||
import dataclasses
|
host = "127.0.0.1"
|
||||||
|
port_dlg = 7000
|
||||||
|
port_ap = 7500
|
||||||
@dataclasses.dataclass
|
port_client_base = 8000
|
||||||
class Config:
|
dlg_url = f"http://{host}:{port_dlg}/docs"
|
||||||
host: str
|
ap_url = f"http://{host}:{port_ap}/docs"
|
||||||
port_dlg: int
|
c1_url = f"http://{host}:{port_client_base}/docs"
|
||||||
port_ap: int
|
c2_url = f"http://{host}:{port_client_base + 1}/docs"
|
||||||
port_client_base: int
|
|
||||||
|
|
||||||
|
|
||||||
config = Config(host="127.0.0.1", port_dlg=6000, port_ap=6600, port_client_base=7000)
|
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ from datetime import datetime
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.responses import HTMLResponse, JSONResponse
|
from fastapi.responses import HTMLResponse, JSONResponse
|
||||||
|
|
||||||
|
import clan_cli.config as config
|
||||||
from clan_cli.webui.schemas import Resolution
|
from clan_cli.webui.schemas import Resolution
|
||||||
|
|
||||||
from .config import config
|
app_dlg = FastAPI(swagger_ui_parameters={"tryItOutEnabled": True})
|
||||||
|
app_ap = FastAPI(swagger_ui_parameters={"tryItOutEnabled": True})
|
||||||
app_dlg = FastAPI()
|
app_c1 = FastAPI(swagger_ui_parameters={"tryItOutEnabled": True})
|
||||||
app_ap = FastAPI()
|
app_c2 = FastAPI(swagger_ui_parameters={"tryItOutEnabled": True})
|
||||||
app_c1 = FastAPI()
|
|
||||||
app_c2 = FastAPI()
|
|
||||||
|
|
||||||
apps = [
|
apps = [
|
||||||
(app_dlg, config.port_dlg),
|
(app_dlg, config.port_dlg),
|
||||||
@@ -24,21 +23,41 @@ apps = [
|
|||||||
|
|
||||||
|
|
||||||
#### HEALTHCHECK
|
#### HEALTHCHECK
|
||||||
|
@app_c1.get("/")
|
||||||
|
async def root_c1() -> str:
|
||||||
|
return "C1 is alive"
|
||||||
|
|
||||||
|
|
||||||
@app_c1.get("/health")
|
@app_c1.get("/health")
|
||||||
async def healthcheck_c1() -> str:
|
async def healthcheck_c1() -> str:
|
||||||
return "200 OK"
|
return "200 OK"
|
||||||
|
|
||||||
|
|
||||||
|
@app_c2.get("/")
|
||||||
|
async def root_c2() -> str:
|
||||||
|
return "C2 is alive"
|
||||||
|
|
||||||
|
|
||||||
@app_c2.get("/health")
|
@app_c2.get("/health")
|
||||||
async def healthcheck_c2() -> str:
|
async def healthcheck_c2() -> str:
|
||||||
return "200 OK"
|
return "200 OK"
|
||||||
|
|
||||||
|
|
||||||
|
@app_dlg.get("/")
|
||||||
|
async def root_dlg() -> str:
|
||||||
|
return "DLG is alive"
|
||||||
|
|
||||||
|
|
||||||
@app_dlg.get("/health")
|
@app_dlg.get("/health")
|
||||||
async def healthcheck_dlg() -> str:
|
async def healthcheck_dlg() -> str:
|
||||||
return "200 OK"
|
return "200 OK"
|
||||||
|
|
||||||
|
|
||||||
|
@app_ap.get("/")
|
||||||
|
async def root_ap() -> str:
|
||||||
|
return "AP is alive"
|
||||||
|
|
||||||
|
|
||||||
@app_ap.get("/health")
|
@app_ap.get("/health")
|
||||||
async def healthcheck_ap() -> str:
|
async def healthcheck_ap() -> str:
|
||||||
return "200 OK"
|
return "200 OK"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from typing import List, Optional
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi import APIRouter, BackgroundTasks, Depends, Query
|
from fastapi import APIRouter, BackgroundTasks, Depends, Query
|
||||||
|
from fastapi.responses import HTMLResponse
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from ...errors import ClanError
|
from ...errors import ClanError
|
||||||
@@ -291,3 +292,31 @@ def get_all_eventmessages(
|
|||||||
) -> List[sql_models.Eventmessage]:
|
) -> List[sql_models.Eventmessage]:
|
||||||
eventmessages = sql_crud.get_eventmessages(db, skip=skip, limit=limit)
|
eventmessages = sql_crud.get_eventmessages(db, skip=skip, limit=limit)
|
||||||
return eventmessages
|
return eventmessages
|
||||||
|
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# #
|
||||||
|
# EMULATED API ENDPOINTS #
|
||||||
|
# #
|
||||||
|
##############################
|
||||||
|
@router.get("/emulate", response_class=HTMLResponse)
|
||||||
|
@router.get("/emu", response_class=HTMLResponse)
|
||||||
|
def get_emulated_enpoints() -> HTMLResponse:
|
||||||
|
from clan_cli.config import ap_url, c1_url, c2_url, dlg_url
|
||||||
|
|
||||||
|
html_content = f"""
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Emulated API</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Emulated API</h1>
|
||||||
|
<p>Emulated API endpoints for testing purposes.</p>
|
||||||
|
<p>DLG: <a href="{dlg_url}" >{dlg_url} </a></p>
|
||||||
|
<p>AP: <a href="{ap_url}">{ap_url}</a></p>
|
||||||
|
<p>C1: <a href="{c1_url}">{c1_url} </a></p>
|
||||||
|
<p>C2: <a href="{c2_url}">{c2_url}</a></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
return HTMLResponse(content=html_content, status_code=200)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import uvicorn
|
|||||||
from pydantic import AnyUrl, IPvAnyAddress
|
from pydantic import AnyUrl, IPvAnyAddress
|
||||||
from pydantic.tools import parse_obj_as
|
from pydantic.tools import parse_obj_as
|
||||||
|
|
||||||
|
import clan_cli.config as config
|
||||||
from clan_cli.emulate_fastapi import apps, get_health
|
from clan_cli.emulate_fastapi import apps, get_health
|
||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
|
|
||||||
@@ -128,8 +129,8 @@ def start_server(args: argparse.Namespace) -> None:
|
|||||||
cmd = ["pytest", "-s", str(test_db_api)]
|
cmd = ["pytest", "-s", str(test_db_api)]
|
||||||
subprocess.run(cmd, check=True)
|
subprocess.run(cmd, check=True)
|
||||||
|
|
||||||
|
config.host = args.host
|
||||||
if args.emulate:
|
if args.emulate:
|
||||||
urls = list()
|
|
||||||
# start servers as processes (dlg, ap, c1 and c2 for tests)
|
# start servers as processes (dlg, ap, c1 and c2 for tests)
|
||||||
for app, port in apps:
|
for app, port in apps:
|
||||||
proc = mp.Process(
|
proc = mp.Process(
|
||||||
@@ -143,9 +144,7 @@ def start_server(args: argparse.Namespace) -> None:
|
|||||||
daemon=True,
|
daemon=True,
|
||||||
)
|
)
|
||||||
proc.start()
|
proc.start()
|
||||||
urls.append(f"http://{args.host}:{port}")
|
url = f"http://{args.host}:{port}"
|
||||||
# check server health
|
|
||||||
for url in urls:
|
|
||||||
res = get_health(url=url + "/health")
|
res = get_health(url=url + "/health")
|
||||||
if res is None:
|
if res is None:
|
||||||
raise Exception(f"Couldn't reach {url} after starting server")
|
raise Exception(f"Couldn't reach {url} after starting server")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from fastapi.testclient import TestClient
|
|||||||
from openapi_client import ApiClient, Configuration
|
from openapi_client import ApiClient, Configuration
|
||||||
from ports import PortFunction
|
from ports import PortFunction
|
||||||
|
|
||||||
from clan_cli.config import config
|
import clan_cli.config as config
|
||||||
from clan_cli.webui.app import app
|
from clan_cli.webui.app import app
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from openapi_client.models import (
|
|||||||
Status,
|
Status,
|
||||||
)
|
)
|
||||||
|
|
||||||
from clan_cli.config import config
|
import clan_cli.config as config
|
||||||
|
|
||||||
random.seed(42)
|
random.seed(42)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user