cloud-py-api / nc_py_api

Nextcloud Python Framework
https://cloud-py-api.github.io/nc_py_api/
Other
84 stars 4 forks source link

`set_handlers`: heartbeat_handler/init_handler params rework #226

Closed bigcat88 closed 6 months ago

bigcat88 commented 6 months ago

Old set_handlers


def set_handlers(
    fast_api_app: FastAPI,
    enabled_handler: typing.Callable[[bool, AsyncNextcloudApp | NextcloudApp], typing.Awaitable[str] | str],
    heartbeat_handler: typing.Callable[[], typing.Awaitable[str] | str] | None = None,
    init_handler: typing.Callable[[AsyncNextcloudApp | NextcloudApp], typing.Awaitable[None] | None] | None = None,
    models_to_fetch: dict[str, dict] | None = None,
    map_app_static: bool = True,
):

New set_handlers:


def set_handlers(
    fast_api_app: FastAPI,
    enabled_handler: typing.Callable[[bool, AsyncNextcloudApp | NextcloudApp], typing.Awaitable[str] | str],
    default_heartbeat: bool = True,
    default_init: bool = True,
    models_to_fetch: dict[str, dict] | None = None,
    map_app_static: bool = True,
):

Main change is now if you wish to define your own /init or /heartbeat just pass False to set_handlers and that's all, define those two routes or any of them.

This greatly simplifies a code, to be easy maintainable in future.

And from now documentation precisely says that recommend way is to use global auth AppAPIAuthMiddleware, to make developing of ExApps more simple.

Also disable_for parameter to AppAPIAuthMiddleware is now in fnmatch so for debug builds you just can pass ["*"] to disable auth.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (ee4b739) 99.83% compared to head (09e35ed) 99.83%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #226 +/- ## ========================================== - Coverage 99.83% 99.83% -0.01% ========================================== Files 42 42 Lines 4965 4943 -22 ========================================== - Hits 4957 4935 -22 Misses 8 8 ``` | [Files](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/226?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api) | Coverage Δ | | |---|---|---| | [nc\_py\_api/ex\_app/integration\_fastapi.py](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/226?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api#diff-bmNfcHlfYXBpL2V4X2FwcC9pbnRlZ3JhdGlvbl9mYXN0YXBpLnB5) | `100.00% <100.00%> (ø)` | | | [nc\_py\_api/nextcloud.py](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/226?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api#diff-bmNfcHlfYXBpL25leHRjbG91ZC5weQ==) | `98.56% <ø> (-0.08%)` | :arrow_down: |