From a09fc5f2ad912ad2cf5b97a3fb62500d158ee714 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 29 Dec 2022 10:31:25 +0100 Subject: [PATCH] added some new endpoints and links in readme --- .DEBIAN/postinst | 2 +- .gitlab-ci.yml | 2 +- Dockerfile | 2 +- README.md | 21 ++++++++++++++------- app/main.py | 24 +++++++++++++++++------- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/.DEBIAN/postinst b/.DEBIAN/postinst index 2311b35..60e5dcb 100644 --- a/.DEBIAN/postinst +++ b/.DEBIAN/postinst @@ -75,7 +75,7 @@ if [[ -f $CONFIG_DIR/webserver.key ]]; then if [ -x "$(command -v curl)" ]; then echo "> Testing API ..." source $CONFIG_DIR/env - curl --insecure -X GET https://$DLS_URL:$DLS_PORT/status + curl --insecure -X GET https://$DLS_URL:$DLS_PORT/-/health else echo "> Testing API failed, curl not available. Please test manually!" fi diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cc50ffd..a137dee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -122,7 +122,7 @@ test: - FASTAPI_DLS_PID=$! - echo "Started service with pid $FASTAPI_DLS_PID" # testing service - - if [ "`curl --insecure -s https://127.0.0.1/status | jq .status`" != "up" ]; then echo "Success"; else "Error"; fi + - if [ "`curl --insecure -s https://127.0.0.1/-/health | jq .status`" != "up" ]; then echo "Success"; else "Error"; fi # cleanup - kill $FASTAPI_DLS_PID - apt-get purge -qq -y fastapi-dls diff --git a/Dockerfile b/Dockerfile index 5819ef5..6ffaee6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,5 +14,5 @@ COPY app /app COPY version.env /version.env COPY README.md /README.md -HEALTHCHECK --start-period=30s --interval=10s --timeout=5s --retries=3 CMD curl --insecure --fail https://localhost/status || exit 1 +HEALTHCHECK --start-period=30s --interval=10s --timeout=5s --retries=3 CMD curl --insecure --fail https://localhost/-/health || exit 1 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "443", "--app-dir", "/app", "--proxy-headers", "--ssl-keyfile", "/app/cert/webserver.key", "--ssl-certfile", "/app/cert/webserver.crt"] diff --git a/README.md b/README.md index f7af25d..92377fd 100644 --- a/README.md +++ b/README.md @@ -13,19 +13,27 @@ Only the clients need a connection to this service on configured port. ## Endpoints -### `GET /` +### [`GET /`](/) -HTML rendered README.md. +Redirect to `/-/readme`. -### `GET /status` +### [`GET /status`](/status) (deprecated: use `/-/health`) Status endpoint, used for *healthcheck*. Shows also current version and commit hash. -### `GET /docs` +### [`GET /-/health`](/-/health) -OpenAPI specifications rendered from `GET /openapi.json`. +Status endpoint, used for *healthcheck*. Shows also current version and commit hash. -### `GET /-/manage` +### [`GET /-/readme`](/-/readme) + +HTML rendered README.md. + +### [`GET /-/docs`](/-/docs), [`GET /-/redocs`](/-/redocs) + +OpenAPI specifications rendered from `GET /-/openapi.json`. + +### [`GET /-/manage`](/-/manage) Shows a very basic UI to delete origins or leases. @@ -413,7 +421,6 @@ Dec 20 17:53:34 ubuntu-grid-server nvidia-gridd[10354]: License acquired success - # Credits Thanks to vGPU community and all who uses this project and report bugs. diff --git a/app/main.py b/app/main.py index 2bcb4c3..8dc55ae 100644 --- a/app/main.py +++ b/app/main.py @@ -63,19 +63,29 @@ def get_token(request: Request) -> dict: return jwt.decode(token=token, key=jwt_decode_key, algorithms=ALGORITHMS.RS256, options={'verify_aud': False}) -@app.get('/') +@app.get('/', summary='* Index') async def index(): + return RedirectResponse('/-/readme') + + +@app.get('/status', summary='* Status', description='Returns current service status, version (incl. git-commit) and some variables.', deprecated=True) +async def status(request: Request): + return JSONResponse({'status': 'up', 'version': VERSION, 'commit': COMMIT, 'debug': DEBUG}) + + +@app.get('/-/health', summary='* Health') +async def _health(request: Request): + return JSONResponse({'status': 'up', 'version': VERSION, 'commit': COMMIT, 'debug': DEBUG}) + + +@app.get('/-/readme', summary='* Readme') +async def _readme(): from markdown import markdown content = load_file('../README.md').decode('utf-8') return HTMLResponse(markdown(text=content, extensions=['tables', 'fenced_code', 'md_in_html', 'nl2br', 'toc'])) -@app.get('/status') -async def status(request: Request): - return JSONResponse({'status': 'up', 'version': VERSION, 'commit': COMMIT, 'debug': DEBUG}) - - -@app.get('/-/manage') +@app.get('/-/manage', summary='* Management UI') async def _manage(request: Request): response = '''