From 364c246ef4c907255a5c5329d57a47dbe7cc7749 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Fri, 3 Jul 2020 11:49:43 +0200 Subject: [PATCH] gestion des variables d'environement dans le cli --- halfapi/cli.py | 23 ++++++++++++++++++++++- halfapi/lib/query.py | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/halfapi/cli.py b/halfapi/cli.py index 4645657..6761799 100755 --- a/halfapi/cli.py +++ b/halfapi/cli.py @@ -17,7 +17,11 @@ from .models.api.route import Route from .models.api.acl_function import AclFunction from .models.api.acl import Acl +# module libraries +from halfapi.app import check_conf +HALFORM_DSN='' +HALFORM_SECRET='' CONTEXT_SETTINGS={ 'default_map':{'run': {'port': 8000}} } @@ -48,7 +52,24 @@ def run(host, port, debug, dev): Port : {port} Debug : {debug} Dev : {dev}''') - + + HALFORM_DSN=os.environ.get('HALFORM_DSN', '') + db_params = dsntodict(HALFORM_DSN) + if not hasattr(db_params, 'dbname'): + db_params['dbname'] = dbname + if not hasattr(db_params, 'host'): + db_params['host'] = dbhost + if not hasattr(db_params, 'port'): + db_params['port'] = dbport + if not hasattr(db_params, 'user'): + db_params['user'] = dbuser + if not hasattr(db_params, 'password'): + db_params['password'] = dbpassword + + os.environ['HALFORM_DSN'] = dicttodsn(db_params) + + check_conf() + sys.path.insert(0, os.getcwd()) click.echo(sys.path) uvicorn.run('halfapi.app:app', diff --git a/halfapi/lib/query.py b/halfapi/lib/query.py index 9150aee..b739916 100644 --- a/halfapi/lib/query.py +++ b/halfapi/lib/query.py @@ -56,7 +56,7 @@ def parse_query(q: str = ""): >>> parse_query('limit=10') Traceback (most recent call last): ... - fastapi.exceptions.HTTPException: 400 + starlette.exceptions.HTTPException: 400 """