diff --git a/neon_hana/app/__init__.py b/neon_hana/app/__init__.py index 5b7123c..bcaeeec 100644 --- a/neon_hana/app/__init__.py +++ b/neon_hana/app/__init__.py @@ -32,6 +32,7 @@ from neon_hana.app.routers.llm import llm_route from neon_hana.app.routers.mq_backend import mq_route from neon_hana.app.routers.auth import auth_route +from neon_hana.app.routers.util import util_route from neon_hana.version import __version__ @@ -45,5 +46,6 @@ def create_app(config: dict): app.include_router(proxy_route) app.include_router(mq_route) app.include_router(llm_route) + app.include_router(util_route) return app diff --git a/neon_hana/app/__main__.py b/neon_hana/app/__main__.py index a621e21..6726f9d 100644 --- a/neon_hana/app/__main__.py +++ b/neon_hana/app/__main__.py @@ -39,7 +39,7 @@ def main(): config = Configuration().get("hana", {}) app = create_app(config) uvicorn.run(app, host=config.get('server_host', "0.0.0.0"), - port=config.get('port', 8080)) + port=config.get('port', 8080), forwarded_allow_ips="*") if __name__ == "__main__": diff --git a/neon_hana/app/routers/util.py b/neon_hana/app/routers/util.py new file mode 100644 index 0000000..a4bf674 --- /dev/null +++ b/neon_hana/app/routers/util.py @@ -0,0 +1,44 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2021 Neongecko.com Inc. +# BSD-3 +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from fastapi import APIRouter, Request +from starlette.responses import PlainTextResponse + +from neon_hana.app.dependencies import client_manager + +util_route = APIRouter(prefix="/util", tags=["utilities"]) + + +@util_route.get("/client_ip", response_class=PlainTextResponse) +async def api_client_ip(request: Request) -> str: + client_manager.validate_auth("", request.client.host) + return request.client.host + + +@util_route.get("/headers") +async def api_headers(request: Request): + client_manager.validate_auth("", request.client.host) + return request.headers diff --git a/neon_hana/auth/client_manager.py b/neon_hana/auth/client_manager.py index 253b825..ab0caaa 100644 --- a/neon_hana/auth/client_manager.py +++ b/neon_hana/auth/client_manager.py @@ -132,7 +132,7 @@ def validate_auth(self, token: str, origin_ip: str) -> bool: max_tokens=self._rpm)) if not self.rate_limiter.consume(origin_ip) and self._rpm > 0: raise HTTPException(status_code=429, - detail=f"Requests limited to {self._rpm}/min" + detail=f"Requests limited to {self._rpm}/min " f"per client connection") if self._disable_auth: