[wip] 0.7.0
This commit is contained in:
parent
6bb6abcbd4
commit
0d0d49d257
2
Pipfile
2
Pipfile
|
@ -16,7 +16,7 @@ virtualenv = "*"
|
|||
|
||||
[packages]
|
||||
click = ">=7.1,<8"
|
||||
starlette = ">=0.17,<0.18"
|
||||
starlette = ">=0.19,<0.20"
|
||||
uvicorn = ">=0.13,<1"
|
||||
orjson = ">=3.4.7,<4"
|
||||
pyjwt = ">=2.3.0,<2.4.0"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
__version__ = '0.6.21-rc0'
|
||||
__version__ = '0.7.0'
|
||||
|
||||
def version():
|
||||
return f'HalfAPI version:{__version__}'
|
||||
|
|
|
@ -18,7 +18,7 @@ from ..half_domain import HalfDomain
|
|||
@click.option('--port', default=CONFIG.get('port'))
|
||||
@click.option('--reload', default=False)
|
||||
@click.option('--secret', default=CONFIG.get('secret'))
|
||||
@click.option('--production', default=CONFIG.get('secret'))
|
||||
@click.option('--production', default=CONFIG.get('production'))
|
||||
@click.option('--loglevel', default=CONFIG.get('loglevel'))
|
||||
@click.option('--prefix', default='/')
|
||||
@click.option('--check', default=True)
|
||||
|
|
|
@ -53,6 +53,9 @@ LOGLEVEL = 'info'
|
|||
CONF_FILE = os.environ.get('HALFAPI_CONF_FILE', '.halfapi/config')
|
||||
DRYRUN = bool(os.environ.get('HALFAPI_DRYRUN', False))
|
||||
|
||||
REDIS_HOST = ''
|
||||
REDIS_PORT = '6379'
|
||||
|
||||
SCHEMA = {}
|
||||
|
||||
CONF_DIR = environ.get('HALFAPI_CONF_DIR', '/etc/half_api')
|
||||
|
@ -146,9 +149,15 @@ try:
|
|||
except FileNotFoundError as exc:
|
||||
logger.info('Running without secret file: %s', SECRET or 'no file specified')
|
||||
|
||||
PRODUCTION = bool(CONFIG.get(
|
||||
'production',
|
||||
environ.get('HALFAPI_PROD', True)))
|
||||
PRODUCTION = CONFIG.get('production', None)
|
||||
if PRODUCTION is None:
|
||||
if environ.get('HALFAPI_PROD', True):
|
||||
PRODUCTION = not (
|
||||
environ.get('HALFAPI_PROD') in ('False', '0', 0, '', 'false'))
|
||||
else:
|
||||
PRODUCTION = True
|
||||
|
||||
|
||||
|
||||
LOGLEVEL = CONFIG.get(
|
||||
'loglevel',
|
||||
|
@ -158,9 +167,21 @@ BASE_DIR = CONFIG.get(
|
|||
'base_dir',
|
||||
environ.get('HALFAPI_BASE_DIR', '.'))
|
||||
|
||||
# Redis
|
||||
|
||||
REDIS_HOST = CONFIG.get(
|
||||
'redis_host',
|
||||
environ.get('HALFAPI_REDIS_HOST', REDIS_HOST))
|
||||
|
||||
REDIS_PORT = CONFIG.get(
|
||||
'redis_port',
|
||||
environ.get('HALFAPI_REDIS_PORT', REDIS_PORT))
|
||||
|
||||
CONFIG['project_name'] = PROJECT_NAME
|
||||
CONFIG['production'] = PRODUCTION
|
||||
CONFIG['secret'] = SECRET
|
||||
CONFIG['host'] = HOST
|
||||
CONFIG['port'] = PORT
|
||||
CONFIG['dryrun'] = DRYRUN
|
||||
if len(REDIS_HOST):
|
||||
CONFIG['redis_url'] = f'redis://{REDIS_HOST}:{REDIS_PORT}'
|
||||
|
|
|
@ -52,6 +52,7 @@ class HalfAPI(Starlette):
|
|||
SECRET = self.config.get('secret')
|
||||
PRODUCTION = self.config.get('production', True)
|
||||
DRYRUN = self.config.get('dryrun', False)
|
||||
REDIS = self.config.get('redis_url', False)
|
||||
|
||||
self.PRODUCTION = PRODUCTION
|
||||
self.SECRET = SECRET
|
||||
|
@ -86,6 +87,11 @@ class HalfAPI(Starlette):
|
|||
HalfAPI.wait_quit()
|
||||
)
|
||||
|
||||
if REDIS:
|
||||
startup_fcts.append(
|
||||
HalfAPI.connect_redis(REDIS)
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
debug=not PRODUCTION,
|
||||
routes=routes,
|
||||
|
@ -207,11 +213,22 @@ class HalfAPI(Starlette):
|
|||
def wait_quit():
|
||||
""" sleeps 1 second and quits. used in dry-run mode
|
||||
"""
|
||||
def wrapped():
|
||||
import time
|
||||
import sys
|
||||
time.sleep(1)
|
||||
sys.exit(0)
|
||||
|
||||
return wrapped
|
||||
|
||||
@staticmethod
|
||||
def connect_redis(redis_url):
|
||||
def wrapped():
|
||||
import redis
|
||||
connection = redis.from_url(redis_url)
|
||||
return wrapped
|
||||
|
||||
|
||||
def acls_route(self):
|
||||
module = None
|
||||
res = {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
LOGLEVEL = os.environ.get('HALFAPI_LOGLEVEL', 'INFO')
|
||||
DEFAULT_LEVEL = getattr(logging, LOGLEVEL, logging.INFO)
|
||||
|
||||
def config_logging(level=logging.INFO):
|
||||
def config_logging(level=DEFAULT_LEVEL):
|
||||
|
||||
# When run by 'uvicorn ...', a root handler is already
|
||||
# configured and the basicConfig below does nothing.
|
||||
|
|
2
setup.py
2
setup.py
|
@ -44,7 +44,7 @@ setup(
|
|||
python_requires=">=3.8",
|
||||
install_requires=[
|
||||
"PyJWT>=2.3.0,<2.4.0",
|
||||
"starlette>=0.17,<0.18",
|
||||
"starlette>=0.19,<0.20",
|
||||
"click>=7.1,<8",
|
||||
"uvicorn>=0.13,<1",
|
||||
"orjson>=3.4.7,<4",
|
||||
|
|
|
@ -4,3 +4,4 @@ def test_methods():
|
|||
assert 'application' in dir(HalfAPI)
|
||||
assert 'version' in dir(HalfAPI)
|
||||
assert 'version_async' in dir(HalfAPI)
|
||||
assert 'connect_redis' in dir(HalfAPI)
|
||||
|
|
Loading…
Reference in New Issue