diff --git a/.github/workflows/propose_release.yml b/.github/workflows/propose_release.yml index eeb6de6..68d6440 100644 --- a/.github/workflows/propose_release.yml +++ b/.github/workflows/propose_release.yml @@ -16,7 +16,7 @@ jobs: branch: dev release_type: ${{ inputs.release_type }} update_changelog: True - version_file: "neon_diana_utils/version.py" + version_file: "neon_hana/version.py" on_version_change: "scripts/sync_chart_app_version.py" pull_changes: uses: neongeckocom/.github/.github/workflows/pull_master.yml@master diff --git a/.github/workflows/publish_test_build.yml b/.github/workflows/publish_test_build.yml index d871d93..26d8bde 100644 --- a/.github/workflows/publish_test_build.yml +++ b/.github/workflows/publish_test_build.yml @@ -6,7 +6,7 @@ on: branches: - dev paths-ignore: - - 'neon_diana_utils/version.py' + - 'neon_hana/version.py' - '**/Chart.yaml' jobs: diff --git a/Dockerfile b/Dockerfile index aeb839d..f8095c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.9-slim LABEL vendor=neon.ai \ - ai.neon.name="diana-services-api" + ai.neon.name="neon-hana" ENV OVOS_CONFIG_BASE_FOLDER neon ENV OVOS_CONFIG_FILENAME diana.yaml @@ -13,4 +13,4 @@ WORKDIR /app COPY . /app RUN pip install /app -CMD ["python3", "/app/diana_services_api/app/__main__.py"] \ No newline at end of file +CMD ["python3", "/app/neon_hana/app/__main__.py"] \ No newline at end of file diff --git a/README.md b/README.md index 00064e9..f1c130f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,42 @@ -# Diana Services API -This package provides an HTTP front-end for accessing services in a -[Neon DIANA](https://github.com/NeonGeckoCom/neon-diana-utils) deployment. This -should generally be hosted as part of a Diana deployment to safely expose services -via HTTP. +# HANA +HANA (HTTP API for Neon Applications) provides a unified front-end for +accessing services in a [Neon DIANA](https://github.com/NeonGeckoCom/neon-diana-utils) deployment. This API should generally +be hosted as part of a Diana deployment to safely expose services to outside +traffic. + +Full API documentation is automatically generated and accessible at `/docs`. + +## Configuration +User configuration belongs in `diana.yaml`, mounted in the container path +`/config/neon/`. An example user configuration could be: +```yaml +MQ: + server: mq.mydomain.com +hana: + mq_default_timeout: 10 + access_token_ttl: 86400 # 1 day + refresh_token_ttl: 604800 # 1 week + requests_per_minute: 60 + access_token_secret: a800445648142061fc238d1f84e96200da87f4f9fa7835cac90db8b4391b117b + refresh_token_secret: 833d369ac73d883123743a44b4a7fe21203cffc956f4c8fec712e71aafa8e1aa + fastapi_title: "My HANA API Host" + fastapi_summary: "Personal HTTP API to access my DIANA backend." + disable_auth: True +``` +It is recommended to generate unique values for configured tokens, these are 32 +bytes in hexadecimal representation. + +## Deployment +You can build a Docker container from this repository, or pull a built container +from the GitHub Container Registry. Start Hana via: +```shell +docker run -p 8080:8080 -v ~/.config/neon:/config/neon ghcr.io/neongeckocom/neon-hana +``` +> This assumes you have configuration defined in `~/.config/neon/diana.yaml` and + are using the default port 8080 + +## Usage +Full API documentation is available at `/docs`. The `/auth/login` endpoint should +be used to generate a `client_id`, `access_token`, and `refresh_token`. The +`access_token` should be included in every request and upon expiration of the +`access_token`, a new token can be obtained from the `auth/refresh` endpoint. diff --git a/docker_overlay/etc/neon/diana.yaml b/docker_overlay/etc/neon/diana.yaml index eb972ca..8c9821b 100644 --- a/docker_overlay/etc/neon/diana.yaml +++ b/docker_overlay/etc/neon/diana.yaml @@ -15,14 +15,14 @@ MQ: mq_handler: user: neon_api_utils password: Klatchat2021 -diana_services_api: +hana: mq_default_timeout: 10 access_token_ttl: 86400 # 1 day refresh_token_ttl: 604800 # 1 week + requests_per_minute: 60 access_token_secret: a800445648142061fc238d1f84e96200da87f4f9f784108ac90db8b4391b117b refresh_token_secret: 833d369ac73d883123743a44b4a7fe21203cffc956f4c8a99be6e71aafa8e1aa server_host: "0.0.0.0" server_port: 8080 - fastapi_title: "Diana Services API" - fastapi_summary: "HTTP component of the Device Independent API for Neon Applications (DIANA)" - disable_auth: True \ No newline at end of file + fastapi_title: "HANA: HTTP API for Neon Applications" + fastapi_summary: "HTTP component of the Device Independent API for Neon Applications (DIANA)" \ No newline at end of file diff --git a/diana_services_api/__init__.py b/neon_hana/__init__.py similarity index 100% rename from diana_services_api/__init__.py rename to neon_hana/__init__.py diff --git a/diana_services_api/app/__init__.py b/neon_hana/app/__init__.py similarity index 82% rename from diana_services_api/app/__init__.py rename to neon_hana/app/__init__.py index d251d06..8d6c9b1 100644 --- a/diana_services_api/app/__init__.py +++ b/neon_hana/app/__init__.py @@ -26,16 +26,16 @@ from fastapi import FastAPI -from diana_services_api.app.dependencies import client_manager, jwt_bearer, mq_connector -from diana_services_api.app.routers.api_proxy import proxy_route -from diana_services_api.app.routers.llm import llm_route -from diana_services_api.app.routers.mq_backend import mq_route -from diana_services_api.app.routers.auth import auth_route -from diana_services_api.version import __version__ +from neon_hana.app.dependencies import client_manager, jwt_bearer, mq_connector +from neon_hana.app.routers.api_proxy import proxy_route +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.version import __version__ def create_app(config: dict): - title = config.get('fastapi_title') or "Diana Services API" + title = config.get('fastapi_title') or "HANA: HTTP API for Neon Applications" summary = config.get('fastapi_summary') or "" version = __version__ app = FastAPI(title=title, summary=summary, version=version) diff --git a/diana_services_api/app/__main__.py b/neon_hana/app/__main__.py similarity index 94% rename from diana_services_api/app/__main__.py rename to neon_hana/app/__main__.py index 59bf4a6..d004f9b 100644 --- a/diana_services_api/app/__main__.py +++ b/neon_hana/app/__main__.py @@ -28,11 +28,11 @@ from ovos_config.config import Configuration -from diana_services_api.app import create_app +from neon_hana.app import create_app def main(): - config = Configuration().get("diana_services_api", {}) + 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)) diff --git a/diana_services_api/app/dependencies.py b/neon_hana/app/dependencies.py similarity index 90% rename from diana_services_api/app/dependencies.py rename to neon_hana/app/dependencies.py index 720a99c..0c9dcf5 100644 --- a/diana_services_api/app/dependencies.py +++ b/neon_hana/app/dependencies.py @@ -26,10 +26,10 @@ from ovos_config.config import Configuration -from diana_services_api.mq_service_api import MQServiceManager -from diana_services_api.auth.client_manager import ClientManager, UserTokenAuth +from neon_hana.mq_service_api import MQServiceManager +from neon_hana.auth.client_manager import ClientManager, UserTokenAuth -config = Configuration().get("diana_services_api") or dict() +config = Configuration().get("hana") or dict() mq_connector = MQServiceManager(config) client_manager = ClientManager(config) jwt_bearer = UserTokenAuth(client_manager) diff --git a/diana_services_api/app/routers/__init__.py b/neon_hana/app/routers/__init__.py similarity index 100% rename from diana_services_api/app/routers/__init__.py rename to neon_hana/app/routers/__init__.py diff --git a/diana_services_api/app/routers/api_proxy.py b/neon_hana/app/routers/api_proxy.py similarity index 94% rename from diana_services_api/app/routers/api_proxy.py rename to neon_hana/app/routers/api_proxy.py index d263338..de37194 100644 --- a/diana_services_api/app/routers/api_proxy.py +++ b/neon_hana/app/routers/api_proxy.py @@ -25,9 +25,9 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from fastapi import APIRouter, Depends -from diana_services_api.schema.api_requests import * -from diana_services_api.schema.api_responses import * -from diana_services_api.app.dependencies import jwt_bearer, mq_connector +from neon_hana.schema.api_requests import * +from neon_hana.schema.api_responses import * +from neon_hana.app.dependencies import jwt_bearer, mq_connector proxy_route = APIRouter(prefix="/proxy", tags=["backend"], diff --git a/diana_services_api/app/routers/auth.py b/neon_hana/app/routers/auth.py similarity index 94% rename from diana_services_api/app/routers/auth.py rename to neon_hana/app/routers/auth.py index 374b9e8..5145f69 100644 --- a/diana_services_api/app/routers/auth.py +++ b/neon_hana/app/routers/auth.py @@ -26,8 +26,8 @@ from fastapi import APIRouter -from diana_services_api.app.dependencies import client_manager -from diana_services_api.schema.auth_requests import * +from neon_hana.app.dependencies import client_manager +from neon_hana.schema.auth_requests import * auth_route = APIRouter(prefix="/auth", tags=["authentication"]) diff --git a/diana_services_api/app/routers/llm.py b/neon_hana/app/routers/llm.py similarity index 95% rename from diana_services_api/app/routers/llm.py rename to neon_hana/app/routers/llm.py index 9c5e575..a18d86f 100644 --- a/diana_services_api/app/routers/llm.py +++ b/neon_hana/app/routers/llm.py @@ -25,8 +25,8 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from fastapi import APIRouter, Depends -from diana_services_api.schema.llm_requests import * -from diana_services_api.app.dependencies import jwt_bearer, mq_connector +from neon_hana.schema.llm_requests import * +from neon_hana.app.dependencies import jwt_bearer, mq_connector llm_route = APIRouter(prefix="/llm", tags=["backend"], diff --git a/diana_services_api/app/routers/mq_backend.py b/neon_hana/app/routers/mq_backend.py similarity index 93% rename from diana_services_api/app/routers/mq_backend.py rename to neon_hana/app/routers/mq_backend.py index 1d11546..6430dff 100644 --- a/diana_services_api/app/routers/mq_backend.py +++ b/neon_hana/app/routers/mq_backend.py @@ -25,9 +25,9 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from fastapi import APIRouter, Depends -from diana_services_api.schema.api_requests import * -from diana_services_api.schema.api_responses import * -from diana_services_api.app.dependencies import jwt_bearer, mq_connector +from neon_hana.schema.api_requests import * +from neon_hana.schema.api_responses import * +from neon_hana.app.dependencies import jwt_bearer, mq_connector mq_route = APIRouter(tags=["backend"], dependencies=[Depends(jwt_bearer)]) diff --git a/diana_services_api/auth/__init__.py b/neon_hana/auth/__init__.py similarity index 100% rename from diana_services_api/auth/__init__.py rename to neon_hana/auth/__init__.py diff --git a/diana_services_api/auth/client_manager.py b/neon_hana/auth/client_manager.py similarity index 100% rename from diana_services_api/auth/client_manager.py rename to neon_hana/auth/client_manager.py diff --git a/diana_services_api/mq_service_api.py b/neon_hana/mq_service_api.py similarity index 97% rename from diana_services_api/mq_service_api.py rename to neon_hana/mq_service_api.py index 925b1c4..642beae 100644 --- a/diana_services_api/mq_service_api.py +++ b/neon_hana/mq_service_api.py @@ -125,7 +125,7 @@ def get_stt(self, b64_audio: str, lang: str, timeout: int = 20): "data": {"audio_data": b64_audio, "utterances": [""], # TODO: Compat "lang": lang}, - "context": {"source": "diana_services_api"}} + "context": {"source": "hana"}} response = send_mq_request("/neon_chat_api", request_data, "neon_chat_api_request", timeout=timeout) return response @@ -138,7 +138,7 @@ def get_tts(self, string: str, lang: str, gender: str, timeout: int = 20): "gender": gender, "lang": lang}, "lang": lang}, - "context": {"source": "diana_services_api"}} + "context": {"source": "hana"}} response = send_mq_request("/neon_chat_api", request_data, "neon_chat_api_request", timeout=timeout) return response diff --git a/diana_services_api/schema/__init__.py b/neon_hana/schema/__init__.py similarity index 100% rename from diana_services_api/schema/__init__.py rename to neon_hana/schema/__init__.py diff --git a/diana_services_api/schema/api_requests.py b/neon_hana/schema/api_requests.py similarity index 100% rename from diana_services_api/schema/api_requests.py rename to neon_hana/schema/api_requests.py diff --git a/diana_services_api/schema/api_responses.py b/neon_hana/schema/api_responses.py similarity index 100% rename from diana_services_api/schema/api_responses.py rename to neon_hana/schema/api_responses.py diff --git a/diana_services_api/schema/auth_requests.py b/neon_hana/schema/auth_requests.py similarity index 100% rename from diana_services_api/schema/auth_requests.py rename to neon_hana/schema/auth_requests.py diff --git a/diana_services_api/schema/llm_requests.py b/neon_hana/schema/llm_requests.py similarity index 100% rename from diana_services_api/schema/llm_requests.py rename to neon_hana/schema/llm_requests.py diff --git a/diana_services_api/version.py b/neon_hana/version.py similarity index 100% rename from diana_services_api/version.py rename to neon_hana/version.py diff --git a/setup.py b/setup.py index 3a4f814..eb6c40d 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ def get_requirements(requirements_filename: str): with open(path.join(BASE_PATH, "README.md"), "r") as f: long_description = f.read() -with open(path.join(BASE_PATH, "diana_services_api", +with open(path.join(BASE_PATH, "hana", "version.py"), "r", encoding="utf-8") as v: for line in v.readlines(): if line.startswith("__version__"): @@ -63,12 +63,12 @@ def get_requirements(requirements_filename: str): setup( - name='diana-services-api', + name='neon-hana', version=version, - description='Web API to access Neon DIANA Services', + description='Web API to access DIANA Services', long_description=long_description, long_description_content_type="text/markdown", - url='https://github.com/NeonGeckoCom/diana-services-api', + url='https://github.com/NeonGeckoCom/neon-hana', author='NeonGecko', author_email='developers@neon.ai', license='BSD-3-Clause', diff --git a/tests/test_auth.py b/tests/test_auth.py index f535005..589234a 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -29,7 +29,7 @@ class TestClientManager(unittest.TestCase): - from diana_services_api.auth.client_manager import ClientManager + from neon_hana.auth.client_manager import ClientManager client_manager = ClientManager({}) def test_check_auth_request(self):