Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在部分连接添加部分情况下未配置 Access Token 的警告 #26

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions network/v11/http.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
from network.authentication import verify_access_token
import utils.uvicorn_server as uvicorn_server
import fastapi
from utils.logger import get_logger
import call_action

BASE_CONFIG = {
"host": "0.0.0.0",
"port": 5700,
"access_token": None
}
logger = get_logger()

class HttpServer:

def __init__(self, config: dict) -> None:
self.config = BASE_CONFIG | config
self.app = fastapi.FastAPI()
self.app.add_route("/{action}", self.handle_request, ["GET", "POST"])
self.check_access_token()

def check_access_token(self) -> None:
if self.config["host"] == "0.0.0.0" or self.config["access_token"]:
logger.warning(f'[{self.config["host"]}:{self.config["port"]}] 未配置 Access Token !')

async def start_server(self) -> None:
await uvicorn_server.run(self.app, host=self.config["host"], port=self.config["port"])
Expand Down
5 changes: 5 additions & 0 deletions network/v11/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def __init__(self, config: dict) -> None:
self.app.add_websocket_route("/", self.handle_root_route)
self.app.add_websocket_route("/event", self.handle_event_route)
self.app.add_websocket_route("/api", self.handle_api_route)
self.check_access_token()

def check_access_token(self) -> None:
if self.config["host"] == "0.0.0.0" or self.config["access_token"]:
logger.warning(f'[{self.config["host"]}:{self.config["port"]}] 未配置 Access Token !')

async def start(self) -> None:
await uvicorn_server.run(
Expand Down
7 changes: 6 additions & 1 deletion network/v12/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ def __init__(self, config: dict) -> None:
self.event_list = []

if self.config["event_enabled"] and self.config["event_buffer_size"] <= 0:
logger.warning("警告: 事件缓冲区大小配置不正确,可能导致内存泄露!")
logger.warning(f"[{self.config['host']}:{self.config['port']}] 事件缓冲区大小配置不正确,可能导致内存泄露!")

self.app = fastapi.FastAPI()
self.app.add_route("/", self.handle_http_connection, ["post"])
self.check_access_token()

def check_access_token(self) -> None:
if self.config["host"] == "0.0.0.0" or self.config["access_token"]:
logger.warning(f'[HTTP {self.config["host"]}:{self.config["port"]}] 未配置 Access Token !')

async def start_server(self):
await uvicorn_server.run(self.app, self.config["port"], self.config["host"])
Expand Down
5 changes: 5 additions & 0 deletions network/v12/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def __init__(self, config: dict) -> None:
self.clients: list[fastapi.WebSocket] = []
self.app = fastapi.FastAPI()
self.app.add_websocket_route("/", self.handle_ws_connect)
self.check_access_token()

def check_access_token(self) -> None:
if self.config["host"] == "0.0.0.0" or self.config["access_token"]:
logger.warning(f'[{self.config["host"]}:{self.config["port"]}] 未配置 Access Token !')

async def start_server(self) -> None:
await uvicorn_server.run(self.app, self.config["port"], self.config["host"])
Expand Down
Loading