Skip to content

Commit 533f231

Browse files
authored
AppAPI 2.0 (#212)
See: nextcloud/app_api#213 1. _All Talk Bots should be updated to use AppAPI auth for input endpoints._ 2. Updated Documentation reflecting last changes. 3. CI will fail, until merge in AppAPI will finished. --------- Signed-off-by: Alexander Piskun <[email protected]>
1 parent a4f31b6 commit 533f231

File tree

26 files changed

+100
-126
lines changed

26 files changed

+100
-126
lines changed

.run/Skeleton (27).run.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Skeleton (27)" type="PythonConfigurationType" factoryName="Python">
33
<module name="nc_py_api" />
4+
<option name="ENV_FILES" value="" />
45
<option name="INTERPRETER_OPTIONS" value="" />
56
<option name="PARENT_ENVS" value="true" />
67
<envs>
8+
<env name="APP_HOST" value="0.0.0.0" />
79
<env name="APP_ID" value="skeleton" />
810
<env name="APP_PORT" value="9030" />
911
<env name="APP_SECRET" value="12345" />
1012
<env name="APP_VERSION" value="1.0.0" />
1113
<env name="NEXTCLOUD_URL" value="http://stable27.local/index.php" />
1214
<env name="PYTHONUNBUFFERED" value="1" />
13-
<env name="APP_HOST" value="0.0.0.0" />
1415
</envs>
1516
<option name="SDK_HOME" value="" />
1617
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/as_app/skeleton/lib" />

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [0.8.1 - 2024-01-xx]
5+
## [0.9.0 - 2024-01-25]
66

77
### Added
88

@@ -12,7 +12,9 @@ All notable changes to this project will be documented in this file.
1212

1313
### Changed
1414

15+
- **large amount of incompatible changes** for `AppAPI 2.0`, see PR for description. #212
1516
- class `Share`.raw_data marked as deprecated and changed to `_raw_data`. #206
17+
- `ex_app.talk_bot_app`/`ex_app.atalk_bot_app` renamed to `ex_app.talk_bot_msg`/`ex_app.atalk_bot_msg`.
1618

1719
## [0.8.0 - 2024-01-12]
1820

docs/NextcloudApp.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ First register ``manual_install`` daemon:
6666

6767
.. code-block:: shell
6868
69-
php occ app_api:daemon:register manual_install "Manual Install" manual-install 0 0 0
69+
php occ app_api:daemon:register manual_install "Manual Install" manual-install http host.docker.internal 0
7070
7171
Then, launch your application. Since this is a manual deployment, it's your responsibility to set minimum of the environment variables.
7272
Here they are:
@@ -86,7 +86,7 @@ After launching your application, execute the following command in the Nextcloud
8686
.. code-block:: shell
8787
8888
php occ app_api:app:register YOUR_APP_ID manual_install --json-info \
89-
"{\"appid\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"host\":\"host.docker.internal\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":SELECTED_PORT,\"protocol\":\"http\",\"system_app\":0}" \
89+
"{\"appid\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"scopes\":{\"required\":[\"ALL\"],\"optional\":[]},\"port\":SELECTED_PORT,\"system_app\":0}" \
9090
--force-scopes --wait-finish
9191
9292
You can see how **nc_py_api** registers in ``scripts/dev_register.sh``.
@@ -226,8 +226,7 @@ and since this is not directly related to working with NextCloud, we will skip t
226226
Using AppAPIAuthMiddleware
227227
--------------------------
228228

229-
If your application does not implement `Talk Bot` functionality and you most often do not need
230-
the ``NextcloudApp`` class returned after standard authentication with `Depends`:
229+
If in your application in most cases you don't really need the ``NextcloudApp`` class returned after standard authentication using `Depends`:
231230

232231
.. code-block:: python
233232

docs/NextcloudTalkBot.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ Afterward, using FastAPI, you can define endpoints that will be invoked by Talk:
4040
4141
@APP.post("/currency_talk_bot")
4242
async def currency_talk_bot(
43-
message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)],
43+
_nc: Annotated[NextcloudApp, Depends(nc_app)],
44+
message: Annotated[talk_bot.TalkBotMessage, Depends(atalk_bot_msg)],
4445
background_tasks: BackgroundTasks,
4546
):
4647
return Response()
4748
4849
.. note::
49-
You must include to each endpoint your bot provides the **Depends(talk_bot_app)**.
50-
**message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)]**
50+
You must include to each endpoint your bot provides the **Depends(nc_app)**.
5151

52-
Depending on **talk_bot_app** serves as an automatic authentication handler for messages from the cloud, which returns the received message from Nextcloud upon successful authentication.
52+
Depending on **nc_app** serves as an automatic authentication handler for messages from the cloud.
53+
54+
**message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)]** - returns the received message from Nextcloud upon successful authentication.
5355

5456
Additionally, if your bot can provide quick and fixed execution times, you may not need to create background tasks.
5557
However, in most cases, it's recommended to segregate functionality and perform operations in the background, while promptly returning an empty response to Nextcloud.

examples/as_app/skeleton/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ run:
6969
register27:
7070
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister skeleton --silent --force || true
7171
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register skeleton manual_install --json-info \
72-
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
72+
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
7373
--force-scopes --wait-finish
7474

7575
.PHONY: register28
7676
register28:
7777
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister skeleton --silent --force || true
7878
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register skeleton manual_install --json-info \
79-
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
79+
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
8080
--force-scopes --wait-finish
8181

8282
.PHONY: register
8383
register:
8484
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister skeleton --silent --force || true
8585
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register skeleton manual_install --json-info \
86-
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
86+
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
8787
--force-scopes --wait-finish

examples/as_app/skeleton/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<optional>
3131
</optional>
3232
</scopes>
33-
<protocol>http</protocol>
3433
<system>false</system>
3534
</external-app>
3635
</info>

examples/as_app/talk_bot/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ run27:
5454
register:
5555
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister talk_bot --silent --force || true
5656
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot manual_install --json-info \
57-
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
57+
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
5858
--force-scopes --wait-finish
5959

6060
.PHONY: register27
6161
register27:
62-
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot --silent --force || true
62+
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot --force || true
6363
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot manual_install --json-info \
64-
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
64+
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
6565
--force-scopes --wait-finish

examples/as_app/talk_bot/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<optional>
3333
</optional>
3434
</scopes>
35-
<protocol>http</protocol>
3635
<system>false</system>
3736
</external-app>
3837
</info>

examples/as_app/talk_bot/lib/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from fastapi import BackgroundTasks, Depends, FastAPI, Response
99

1010
from nc_py_api import NextcloudApp, talk_bot
11-
from nc_py_api.ex_app import run_app, set_handlers, talk_bot_app
11+
from nc_py_api.ex_app import atalk_bot_msg, nc_app, run_app, set_handlers
1212

1313

1414
# The same stuff as for usual External Applications
@@ -66,7 +66,8 @@ def currency_talk_bot_process_request(message: talk_bot.TalkBotMessage):
6666

6767
@APP.post("/currency_talk_bot")
6868
async def currency_talk_bot(
69-
message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)],
69+
_nc: Annotated[NextcloudApp, Depends(nc_app)],
70+
message: Annotated[talk_bot.TalkBotMessage, Depends(atalk_bot_msg)],
7071
background_tasks: BackgroundTasks,
7172
):
7273
# As during converting, we do not process converting locally, we perform this in background, in the background task.

examples/as_app/talk_bot_ai/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ run27:
5454
register:
5555
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
5656
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot_ai manual_install --json-info \
57-
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
57+
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
5858
--force-scopes --wait-finish
5959

6060
.PHONY: register27
6161
register27:
6262
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
6363
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot_ai manual_install --json-info \
64-
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
64+
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
6565
--force-scopes --wait-finish

0 commit comments

Comments
 (0)