Exception based webdav_check; app startup
This commit is contained in:
parent
53dd8d74fa
commit
bb0115808d
3 changed files with 39 additions and 38 deletions
|
@ -1,14 +1,11 @@
|
||||||
from uvicorn import run as uvicorn_run
|
from uvicorn import run as uvicorn_run
|
||||||
|
|
||||||
from .dav_common import webdav_check
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""
|
"""
|
||||||
If the `main` script is run, `uvicorn` is used to run the app.
|
If the `main` script is run, `uvicorn` is used to run the app.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if webdav_check():
|
|
||||||
uvicorn_run(
|
uvicorn_run(
|
||||||
app="ovdashboard_api:app",
|
app="ovdashboard_api:app",
|
||||||
host="0.0.0.0",
|
host="0.0.0.0",
|
||||||
|
|
|
@ -10,6 +10,7 @@ from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
|
from .dav_common import webdav_check
|
||||||
from .routers.v1 import router as v1_router
|
from .routers.v1 import router as v1_router
|
||||||
from .settings import SETTINGS
|
from .settings import SETTINGS
|
||||||
|
|
||||||
|
@ -29,8 +30,11 @@ app = FastAPI(
|
||||||
redoc_url=SETTINGS.redoc_url,
|
redoc_url=SETTINGS.redoc_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
app.include_router(v1_router)
|
app.add_event_handler("startup", webdav_check)
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def add_middlewares() -> None:
|
||||||
if SETTINGS.production_mode:
|
if SETTINGS.production_mode:
|
||||||
# Mount frontend in production mode
|
# Mount frontend in production mode
|
||||||
app.mount(
|
app.mount(
|
||||||
|
@ -54,3 +58,5 @@ else:
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
expose_headers=["*"],
|
expose_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
app.include_router(v1_router)
|
||||||
|
|
|
@ -25,7 +25,7 @@ _WEBDAV_CLIENT = WebDAVclient({
|
||||||
_logger = getLogger(__name__)
|
_logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def webdav_check() -> bool:
|
def webdav_check() -> None:
|
||||||
"""
|
"""
|
||||||
Checks if base resources are available.
|
Checks if base resources are available.
|
||||||
"""
|
"""
|
||||||
|
@ -53,7 +53,7 @@ def webdav_check() -> bool:
|
||||||
"WebDAV connection to %s FAILED!",
|
"WebDAV connection to %s FAILED!",
|
||||||
repr(SETTINGS.webdav.url),
|
repr(SETTINGS.webdav.url),
|
||||||
)
|
)
|
||||||
return False
|
raise ConnectionError(SETTINGS.webdav.url)
|
||||||
|
|
||||||
_logger.debug("WebDAV connection ok.")
|
_logger.debug("WebDAV connection ok.")
|
||||||
|
|
||||||
|
@ -62,12 +62,10 @@ def webdav_check() -> bool:
|
||||||
"WebDAV prefix directory %s NOT FOUND, please create it!",
|
"WebDAV prefix directory %s NOT FOUND, please create it!",
|
||||||
repr(SETTINGS.webdav_prefix),
|
repr(SETTINGS.webdav_prefix),
|
||||||
)
|
)
|
||||||
return False
|
raise FileNotFoundError(SETTINGS.webdav_prefix)
|
||||||
|
|
||||||
_logger.debug("WebDAV prefix directory found.")
|
_logger.debug("WebDAV prefix directory found.")
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def webdav_ensure_path(remote_path: str) -> None:
|
def webdav_ensure_path(remote_path: str) -> None:
|
||||||
remote_path = f"{SETTINGS.webdav_prefix}/{remote_path}"
|
remote_path = f"{SETTINGS.webdav_prefix}/{remote_path}"
|
||||||
|
|
Loading…
Reference in a new issue