Skip to content

Commit ee702ad

Browse files
authored
moved skeleton to a separate repo (#238)
Skeleton repo from now lives here: https://github.com/cloud-py-api/app-skeleton-python Signed-off-by: Alexander Piskun <[email protected]>
1 parent a26c8db commit ee702ad

File tree

10 files changed

+38
-241
lines changed

10 files changed

+38
-241
lines changed

.run/Skeleton (27).run.xml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.run/Skeleton (28).run.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.run/Skeleton (last).run.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/NextcloudApp.rst

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,41 @@ As a first step, let's take a look at the structure of a basic Python applicatio
88
Skeleton
99
--------
1010

11-
.. literalinclude:: ../examples/as_app/skeleton/lib/main.py
11+
.. code-block:: python
12+
13+
from contextlib import asynccontextmanager
14+
15+
from fastapi import FastAPI
16+
from nc_py_api import NextcloudApp
17+
from nc_py_api.ex_app import AppAPIAuthMiddleware, LogLvl, run_app, set_handlers
18+
19+
20+
@asynccontextmanager
21+
async def lifespan(app: FastAPI):
22+
set_handlers(app, enabled_handler)
23+
yield
24+
25+
26+
APP = FastAPI(lifespan=lifespan)
27+
APP.add_middleware(AppAPIAuthMiddleware) # set global AppAPI authentication middleware
28+
29+
30+
def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
31+
# This will be called each time application is `enabled` or `disabled`
32+
# NOTE: `user` is unavailable on this step, so all NC API calls that require it will fail as unauthorized.
33+
print(f"enabled={enabled}")
34+
if enabled:
35+
nc.log(LogLvl.WARNING, f"Hello from {nc.app_cfg.app_name} :)")
36+
else:
37+
nc.log(LogLvl.WARNING, f"Bye bye from {nc.app_cfg.app_name} :(")
38+
# In case of an error, a non-empty short string should be returned, which will be shown to the NC administrator.
39+
return ""
40+
41+
42+
if __name__ == "__main__":
43+
# Wrapper around `uvicorn.run`.
44+
# You are free to call it directly, with just using the `APP_HOST` and `APP_PORT` variables from the environment.
45+
run_app("main:APP", log_level="trace")
1246
1347
What's going on in the skeleton?
1448

@@ -49,6 +83,8 @@ With help of ``AppAPIAuthMiddleware`` you can add **global** AppAPI authenticati
4983

5084
.. note:: ``AppAPIAuthMiddleware`` supports **disable_for** optional argument, where you can list all routes for which authentication should be skipped.
5185

86+
Repository with the skeleton sources can be found here: `app-skeleton-python <https://github.com/cloud-py-api/app-skeleton-python>`_
87+
5288
Dockerfile
5389
----------
5490

examples/as_app/skeleton/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/as_app/skeleton/Makefile

Lines changed: 0 additions & 65 deletions
This file was deleted.

examples/as_app/skeleton/appinfo/info.xml

Lines changed: 0 additions & 31 deletions
This file was deleted.

examples/as_app/skeleton/lib/main.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

examples/as_app/skeleton/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/dev_register.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ echo "unregistering nc_py_api as an app for $1 container"
77
docker exec "$1" sudo -u www-data php occ app_api:app:unregister nc_py_api --silent --force || true
88
echo "registering nc_py_api as an app for $1 container"
99
docker exec "$1" sudo -u www-data php occ app_api:app:register nc_py_api manual_install --json-info \
10-
"{\"id\":\"nc_py_api\",\"name\":\"nc_py_api\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"scopes\":[\"ALL\"],\"port\":9009,\"system\":1}" \
10+
"{\"id\":\"nc_py_api\",\"name\":\"nc_py_api\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"scopes\":[\"ALL\"],\"port\":9009,\"system_app\":1}" \
1111
--force-scopes --wait-finish
1212
echo "nc_py_api for $1 is ready to use"

0 commit comments

Comments
 (0)