Skip to content

Commit

Permalink
moved skeleton to a separate repo (#238)
Browse files Browse the repository at this point in the history
Skeleton repo from now lives here:
https://github.com/cloud-py-api/app-skeleton-python

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 authored Mar 29, 2024
1 parent a26c8db commit ee702ad
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 241 deletions.
31 changes: 0 additions & 31 deletions .run/Skeleton (27).run.xml

This file was deleted.

30 changes: 0 additions & 30 deletions .run/Skeleton (28).run.xml

This file was deleted.

30 changes: 0 additions & 30 deletions .run/Skeleton (last).run.xml

This file was deleted.

38 changes: 37 additions & 1 deletion docs/NextcloudApp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,41 @@ As a first step, let's take a look at the structure of a basic Python applicatio
Skeleton
--------

.. literalinclude:: ../examples/as_app/skeleton/lib/main.py
.. code-block:: python
from contextlib import asynccontextmanager
from fastapi import FastAPI
from nc_py_api import NextcloudApp
from nc_py_api.ex_app import AppAPIAuthMiddleware, LogLvl, run_app, set_handlers
@asynccontextmanager
async def lifespan(app: FastAPI):
set_handlers(app, enabled_handler)
yield
APP = FastAPI(lifespan=lifespan)
APP.add_middleware(AppAPIAuthMiddleware) # set global AppAPI authentication middleware
def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
# This will be called each time application is `enabled` or `disabled`
# NOTE: `user` is unavailable on this step, so all NC API calls that require it will fail as unauthorized.
print(f"enabled={enabled}")
if enabled:
nc.log(LogLvl.WARNING, f"Hello from {nc.app_cfg.app_name} :)")
else:
nc.log(LogLvl.WARNING, f"Bye bye from {nc.app_cfg.app_name} :(")
# In case of an error, a non-empty short string should be returned, which will be shown to the NC administrator.
return ""
if __name__ == "__main__":
# Wrapper around `uvicorn.run`.
# You are free to call it directly, with just using the `APP_HOST` and `APP_PORT` variables from the environment.
run_app("main:APP", log_level="trace")
What's going on in the skeleton?

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

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

Repository with the skeleton sources can be found here: `app-skeleton-python <https://github.com/cloud-py-api/app-skeleton-python>`_

Dockerfile
----------

Expand Down
15 changes: 0 additions & 15 deletions examples/as_app/skeleton/Dockerfile

This file was deleted.

65 changes: 0 additions & 65 deletions examples/as_app/skeleton/Makefile

This file was deleted.

31 changes: 0 additions & 31 deletions examples/as_app/skeleton/appinfo/info.xml

This file was deleted.

36 changes: 0 additions & 36 deletions examples/as_app/skeleton/lib/main.py

This file was deleted.

1 change: 0 additions & 1 deletion examples/as_app/skeleton/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/dev_register.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ echo "unregistering nc_py_api as an app for $1 container"
docker exec "$1" sudo -u www-data php occ app_api:app:unregister nc_py_api --silent --force || true
echo "registering nc_py_api as an app for $1 container"
docker exec "$1" sudo -u www-data php occ app_api:app:register nc_py_api manual_install --json-info \
"{\"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}" \
"{\"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}" \
--force-scopes --wait-finish
echo "nc_py_api for $1 is ready to use"

0 comments on commit ee702ad

Please sign in to comment.