Skip to content

Commit

Permalink
Implement configuration aod Docker with default overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Jan 17, 2024
1 parent 5939be6 commit 3ce54b4
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 13 deletions.
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.9-slim

LABEL vendor=neon.ai \
ai.neon.name="diana-services-api"

ENV OVOS_CONFIG_BASE_FOLDER neon
ENV OVOS_CONFIG_FILENAME diana.yaml
ENV XDG_CONFIG_HOME /config

COPY docker_overlay/ /

WORKDIR /app
COPY . /app
RUN pip install /app

CMD ["python3", "/app/diana_services_api/app/__main__.py"]
4 changes: 2 additions & 2 deletions diana_services_api/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@


def create_app(config: dict):
title = config.get('title') or "Diana Services API"
summary = config.get('summary') or "HTTP component of the Device Independent API for Neon Applications (DIANA)"
title = config.get('fastapi_title') or "Diana Services API"
summary = config.get('fastapi_summary') or ""
version = __version__
app = FastAPI(title=title, summary=summary, version=version)
app.include_router(auth_route)
Expand Down
8 changes: 5 additions & 3 deletions diana_services_api/app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@

import uvicorn

from ovos_config.config import Configuration

from diana_services_api.app import create_app


def main():
config = dict()
config = Configuration().get("diana_services_api")
app = create_app(config)
# TODO: host, port from config
uvicorn.run(app, host="0.0.0.0", port=8080)
uvicorn.run(app, host=config.get('server_host', "0.0.0.0"),
port=config.get('port', 8080))


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion diana_services_api/app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

config = dict() # TODO
config = Configuration().get("diana_services_api") or dict()
mq_connector = MQServiceManager(config)
client_manager = ClientManager(config)
jwt_bearer = UserTokenAuth(client_manager)
9 changes: 5 additions & 4 deletions diana_services_api/auth/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ def __init__(self, config: dict):
self._access_token_lifetime = config.get("access_token_ttl", 3600 * 24)
self._refresh_token_lifetime = config.get("refresh_token_ttl",
3600 * 24 * 7)
self._access_secret = config.get("access_token_secret",
'a800445648142061fc238d1f84e96200da87f4f9f784108ac90db8b4391b117b')
self._refresh_secret = config.get("refresh_token_secret",
'833d369ac73d883123743a44b4a7fe21203cffc956f4c8a99be6e71aafa8e1aa')
self._access_secret = config.get("access_token_secret")
self._refresh_secret = config.get("refresh_token_secret")
self._disable_auth = config.get("disable_auth")
self._jwt_algo = "HS256"

def check_auth_request(self, client_id: str, username: str,
Expand All @@ -69,6 +68,8 @@ def check_auth_request(self, client_id: str, username: str,
return auth

def validate_auth(self, token: str) -> bool:
if self._disable_auth:
return True
try:
auth = jwt.decode(token, self._access_secret, self._jwt_algo)
if auth['expire'] < time():
Expand Down
2 changes: 1 addition & 1 deletion diana_services_api/mq_service_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class APIError(HTTPException):
class MQServiceManager:
def __init__(self, config: dict):
self.mq_default_timeout = config.get('mq_default_timeout', 10)
self.mq_cliend_id = str(uuid4())
self.mq_cliend_id = config.get('mq_client_id') or str(uuid4())

def _validate_api_proxy_response(self, response: dict):
if response['status_code'] == 200:
Expand Down
Empty file.
28 changes: 28 additions & 0 deletions docker_overlay/etc/neon/diana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
log_level: INFO
logs:
level_overrides:
error:
- pika
warning:
- filelock
info:
- openai
debug: []
MQ:
server: neon-rabbitmq
port: 5672
users:
mq_handler:
user: neon_api_utils
password: Klatchat2021
diana_services_api:
mq_default_timeout: 10
access_token_ttl: 86400 # 1 day
refresh_token_ttl: 604800 # 1 week
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
3 changes: 2 additions & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ fastapi~=0.95
uvicorn~=0.25
pydantic~=2.5
pyjwt~=2.8
neon_mq_connector~=0.7
neon-mq-connector~=0.7
ovos-config~=0.0.12
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from setuptools import setup, find_packages
from os import getenv, path, walk
from os import getenv, path

BASE_PATH = path.abspath(path.dirname(__file__))

Expand Down

0 comments on commit 3ce54b4

Please sign in to comment.