Skip to content

Commit e514f26

Browse files
authored
reworked app-scopes definition (#83)
CI will fail, waiting for AppEcosystem update Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 8ee8d64 commit e514f26

File tree

21 files changed

+213
-107
lines changed

21 files changed

+213
-107
lines changed

.github/workflows/analysis-coverage.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
cd ..
137137
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
138138
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
139-
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
139+
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
140140
-e --force-scopes
141141
kill -15 $(cat /tmp/_install.pid)
142142
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
@@ -290,7 +290,7 @@ jobs:
290290
cd ..
291291
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
292292
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
293-
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
293+
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
294294
-e --force-scopes
295295
kill -15 $(cat /tmp/_install.pid)
296296
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
@@ -429,7 +429,7 @@ jobs:
429429
cd ..
430430
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
431431
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
432-
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
432+
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
433433
-e --force-scopes
434434
kill -15 $(cat /tmp/_install.pid)
435435
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
@@ -549,7 +549,7 @@ jobs:
549549
cd ..
550550
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
551551
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
552-
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
552+
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":$APP_PORT,\"protocol\":\"http\",\"system_app\":1}" \
553553
-e --force-scopes
554554
kill -15 $(cat /tmp/_install.pid)
555555
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
@@ -794,7 +794,7 @@ jobs:
794794
cd ..
795795
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
796796
php occ app_ecosystem_v2:app:register $APP_ID manual_install --json-info \
797-
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"protocol\":\"http\",\"port\":$APP_PORT,\"system_app\":1}" \
797+
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"protocol\":\"http\",\"port\":$APP_PORT,\"system_app\":1}" \
798798
-e --force-scopes
799799
kill -15 $(cat /tmp/_install.pid)
800800
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null

.run/to_gif.run.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
<option name="INTERPRETER_OPTIONS" value="" />
55
<option name="PARENT_ENVS" value="true" />
66
<envs>
7+
<env name="PYTHONUNBUFFERED" value="1" />
78
<env name="APP_ID" value="to_gif" />
89
<env name="APP_PORT" value="9029" />
910
<env name="APP_SECRET" value="12345" />
1011
<env name="APP_VERSION" value="1.0.0" />
1112
<env name="NEXTCLOUD_URL" value="http://nextcloud.local/index.php" />
12-
<env name="PYTHONUNBUFFERED" value="1" />
1313
</envs>
1414
<option name="SDK_HOME" value="" />
1515
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
1616
<option name="IS_MODULE_SDK" value="true" />
1717
<option name="ADD_CONTENT_ROOTS" value="true" />
1818
<option name="ADD_SOURCE_ROOTS" value="true" />
1919
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
20-
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/examples/as_app/to_gif/main.py" />
20+
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/examples/as_app/to_gif/src/main.py" />
2121
<option name="PARAMETERS" value="" />
2222
<option name="SHOW_COMMAND_LINE" value="false" />
2323
<option name="EMULATE_TERMINAL" value="false" />

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- `Nextcloud.response_headers` property, to get headers from last response.
10+
### Changed
11+
12+
- Reworked `External API` declarations, skeleton made much simpler.
1013

1114
## [0.0.29 - 2023-08-13]
1215

examples/COPYING

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
MIT License
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.11.4-slim-bookworm
2+
3+
COPY requirements.txt /
4+
ADD /src/ /app/
5+
6+
RUN \
7+
python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt
8+
9+
WORKDIR /app
10+
ENTRYPOINT ["python3", "main.py"]

examples/as_app/skeleton/Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.DEFAULT_GOAL := help
2+
3+
.PHONY: help
4+
help:
5+
@echo "Welcome to app_python_skeleton example. Please use \`make <target>\` where <target> is one of"
6+
@echo " "
7+
@echo " Next commands are only for dev environment with nextcloud-docker-dev!"
8+
@echo " They should run from the host you are developing on(with activated venv) and not in the container with Nextcloud!"
9+
@echo " "
10+
@echo " build-push build image and upload to ghcr.io"
11+
@echo " "
12+
@echo " deploy deploy example to registered 'docker_dev'"
13+
@echo " "
14+
@echo " run28 install app_python_skeleton for Nextcloud 28"
15+
@echo " run27 install app_python_skeleton for Nextcloud 27"
16+
@echo " "
17+
@echo " For development of this example use PyCharm run configurations. Development is always set for last Nextcloud."
18+
@echo " First run 'app_python_skeleton' and then 'make manual_register', after that you can use/debug/develop it and easy test."
19+
@echo " "
20+
@echo " manual_register perform registration of running 'app_python_skeleton' into 'manual_install' deploy daemon."
21+
22+
.PHONY: build-push
23+
build-push:
24+
docker login ghcr.io
25+
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/cloud-py-api/py_app_v2-skeleton:latest .
26+
27+
.PHONY: deploy
28+
deploy:
29+
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:deploy app_python_skeleton docker_dev \
30+
--info-xml https://raw.githubusercontent.com/cloud-py-api/nc_py_api/main/examples/as_app/skeleton/appinfo/info.xml
31+
32+
.PHONY: run28
33+
run28:
34+
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent || true
35+
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_dev -e --force-scopes
36+
37+
.PHONY: run27
38+
run27:
39+
docker exec master-stable27-1 sudo -u www-data php occ app_ecosystem_v2:app:unregister app_python_skeleton --silent || true
40+
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton docker_dev -e --force-scopes
41+
42+
.PHONY: manual_register
43+
manual_register:
44+
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register app_python_skeleton manual_install --json-info \
45+
"{\"appid\":\"app_python_skeleton\",\"name\":\"App Python Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9029,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
46+
-e --force-scopes
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<info>
3+
<id>app_python_skeleton</id>
4+
<name>App Python Skeleton</name>
5+
<summary>Nextcloud Python Application Skeleton</summary>
6+
<description>
7+
<![CDATA[Example of the Nextcloud application written in python]]>
8+
</description>
9+
<version>1.0.0</version>
10+
<licence>MIT</licence>
11+
<author mail="andrey18106x@gmail.com" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
12+
<author mail="bigcat88@icloud.com" homepage="https://github.com/bigcat88">Alexander Piskun</author>
13+
<namespace>PyAppV2_skeleton</namespace>
14+
<category>tools</category>
15+
<website>https://github.com/cloud-py-api/nc_py_api</website>
16+
<bugs>https://github.com/cloud-py-api/nc_py_api/issues</bugs>
17+
<repository type="git">https://github.com/cloud-py-api/nc_py_api</repository>
18+
<dependencies>
19+
<nextcloud min-version="27" max-version="28"/>
20+
</dependencies>
21+
<ex-app>
22+
<docker-install>
23+
<registry>ghcr.io</registry>
24+
<image>cloud-py-api/py_app_v2-skeleton</image>
25+
<image-tag>latest</image-tag>
26+
</docker-install>
27+
<scopes>
28+
<required>
29+
</required>
30+
<optional>
31+
</optional>
32+
</scopes>
33+
<protocol>http</protocol>
34+
<system>0</system>
35+
</ex-app>
36+
</info>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nc_py_api[app]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Simplest example.
3+
"""
4+
5+
from fastapi import FastAPI
6+
7+
from nc_py_api import NextcloudApp
8+
from nc_py_api.ex_app import LogLvl, run_app
9+
10+
APP = FastAPI()
11+
12+
13+
def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
14+
# This will be called each time application is `enabled` or `disabled`
15+
# All scopes that application required already granted before this step.
16+
# NOTE: `user` is unavailable on this step, so all NC API calls that require it will fail as unauthorized.
17+
print(f"enabled={enabled}")
18+
if enabled:
19+
nc.log(LogLvl.WARNING, f"Hello from {nc.app_cfg.app_name} :)")
20+
else:
21+
nc.log(LogLvl.WARNING, f"Bye bye from {nc.app_cfg.app_name} :(")
22+
# In case of an error, a non-empty short string should be returned, which will be shown to the NC administrator.
23+
return ""
24+
25+
26+
if __name__ == "__main__":
27+
run_app(APP, enabled_handler, "main:APP", log_level="trace")

examples/as_app/to_gif/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
FROM python:3.11.4-bookworm
22

33
COPY requirements.txt /
4-
ADD main.py /app/
4+
ADD /src/ /app/
55

66
RUN \
77
apt-get update && \
88
apt-get install -y \
99
ffmpeg libsm6 libxext6 gifsicle
1010

1111
RUN \
12-
python3 -m pip install -r requirements.txt
12+
python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt
1313

1414
WORKDIR /app
1515
ENTRYPOINT ["python3", "main.py"]

0 commit comments

Comments
 (0)