diff --git a/neon_hana/app/__init__.py b/neon_hana/app/__init__.py index 9fd7f1d..299f963 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.user import user_route from neon_hana.app.routers.util import util_route from neon_hana.app.routers.node_server import node_route from neon_hana.version import __version__ @@ -49,5 +50,6 @@ def create_app(config: dict): app.include_router(llm_route) app.include_router(util_route) app.include_router(node_route) + app.include_router(user_route) return app diff --git a/neon_hana/app/routers/user.py b/neon_hana/app/routers/user.py new file mode 100644 index 0000000..9d6b067 --- /dev/null +++ b/neon_hana/app/routers/user.py @@ -0,0 +1,45 @@ +# 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, Depends +from neon_hana.app.dependencies import jwt_bearer, mq_connector +from neon_hana.schema.user_requests import GetUserRequest, UpdateUserRequest +from neon_users_service.models import User + +user_route = APIRouter(tags=["user"], dependencies=[Depends(jwt_bearer)]) + + +@user_route.post("/get") +async def get_user(request: GetUserRequest, + token: str = Depends(jwt_bearer)) -> User: + return mq_connector.get_user_profile(access_token=token, **dict(request)) + + +@user_route.post("/update") +async def update_user(request: UpdateUserRequest, + token: str = Depends(jwt_bearer)) -> User: + return mq_connector.handle_update_user_request(access_token=token, + **dict(request)) diff --git a/neon_hana/mq_service_api.py b/neon_hana/mq_service_api.py index 69c1349..c1e4035 100644 --- a/neon_hana/mq_service_api.py +++ b/neon_hana/mq_service_api.py @@ -164,6 +164,21 @@ def update_user(self, user: User) -> User: raise HTTPException(status_code=code, detail=err_or_user) return err_or_user + def handle_update_user_request(self, user: User, access_token: str): + """ + Handle a request to update a user. This accepts an `auth_token` to + account for requests to change the password or registered tokens. + @param user: Updated User object to write to the database + @param access_token: JWT auth token submitted with the request + """ + stat, code, err_or_user = self._query_users_api("update", + username=user.username, + access_token=access_token, + user=user) + if not stat: + raise HTTPException(status_code=code, detail=err_or_user) + return err_or_user + def query_api_proxy(self, service_name: str, query_params: dict, timeout: int = 10): query_params['service'] = service_name diff --git a/neon_hana/schema/user_requests.py b/neon_hana/schema/user_requests.py new file mode 100644 index 0000000..ffb3993 --- /dev/null +++ b/neon_hana/schema/user_requests.py @@ -0,0 +1,49 @@ +# 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 pydantic import BaseModel + +from neon_users_service.models import User + + +class GetUserRequest(BaseModel): + username: str = "guest" + + model_config = { + "json_schema_extra": { + "examples": [{ + "username": "guest" + }]}} + + +class UpdateUserRequest(BaseModel): + user: User + + model_config = { + "json_schema_extra": { + "examples": [{ + "user": User(username="guest").model_dump() + }]}}