diff --git a/api/Dockerfile b/api/Dockerfile index af3cc5f..d35fd0c 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -16,4 +16,4 @@ RUN pip3 install --no-cache-dir --root-user-action ignore -r requirements.txt COPY . . -ENTRYPOINT [ "python", "main.py" ] +ENTRYPOINT [ "python", "api.py" ] diff --git a/api/main.py b/api/api.py similarity index 62% rename from api/main.py rename to api/api.py index 2174c3e..2e2ce06 100644 --- a/api/main.py +++ b/api/api.py @@ -3,31 +3,24 @@ # following the pattern described in # https://fastapi.tiangolo.com/tutorial/bigger-applications/ +API_VERSION = 'v1' + from fastapi import FastAPI import logging from internal import logger_init, check_env_vars, set_log_level -from routers import config - -logger = logging.getLogger('api') +from routers.configuration import router as configuration_router -# Define API app as 'api' -api = FastAPI() +# check env and use defaults if not present -# start API +env = check_env_vars() if __name__ == '__main__': - import uvicorn - - # stubs follow, this should be read from redis kvs for instance, section 'hamframe' - + logger = logging.getLogger('api') # logger = tooling.logger_init('DEBUG') - logger_init() - # check env and use defaults if not present - - env = check_env_vars() + logger_init() # set logger level based on what we got back @@ -37,14 +30,29 @@ for var in env: logger.debug(f'env: {var}={env[var]}') +else: + logger = logging.getLogger('uvicorn.error') - # add REST routes +# Define API app as 'api' - api.include_router( - config.router, - responses={418: {"description": "I'm a teapot"}}, - ) - logger.debug('config_router added') +api = FastAPI() + +# add REST routes + +api.include_router( + router = configuration_router, + prefix='/' + API_VERSION, +) +logger.debug('added routers.configuration') + +@api.get("/") +async def root(): + return {'message': 'You\'re a tea pot?'} + +# start API + +if __name__ == '__main__': + import uvicorn uvicorn.run( app='__main__:api', diff --git a/api/routers/configuration.py b/api/routers/configuration.py index 1f6fe80..6168393 100644 --- a/api/routers/configuration.py +++ b/api/routers/configuration.py @@ -4,10 +4,10 @@ router = APIRouter() -@router.get('/config/', tags=['configuration']) +@router.get('/config/') async def get_config(): return [{'instance': 'instance'}] -@router.get('/config/{instance}/{section}', tags=['configuration']) +@router.get('/config/{instance}/{section}') async def get_config_instance_section(): return [{'instance': 'instance'}, {'section': 'section'}]