Skip to content

Commit

Permalink
restructuring main
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuhtz committed Jul 23, 2024
1 parent 60c8557 commit 50b7331
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
48 changes: 28 additions & 20 deletions api/main.py → api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions api/routers/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}]

0 comments on commit 50b7331

Please sign in to comment.