Skip to content

Commit 459f385

Browse files
authored
for next AppEcosystem update (#18)
1 parent f31dd78 commit 459f385

File tree

7 files changed

+30
-19
lines changed

7 files changed

+30
-19
lines changed

.github/workflows/analysis-coverage.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ jobs:
136136
echo $! > /tmp/_install.pid
137137
cd ..
138138
sleep 5s
139-
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \
140-
--net=host --host="127.0.0.1" --expose="local"
139+
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0
141140
php occ app_ecosystem_v2:app:register \
142141
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_id\":1,\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"port\":$APP_PORT}" \
143142
-e --force-scopes --system-app
@@ -263,8 +262,7 @@ jobs:
263262
echo $! > /tmp/_install.pid
264263
cd ..
265264
sleep 5s
266-
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \
267-
--net=host --host="127.0.0.1" --expose="local"
265+
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0
268266
php occ app_ecosystem_v2:app:register \
269267
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_id\":1,\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"port\":$APP_PORT}" \
270268
-e --force-scopes --system-app
@@ -383,8 +381,7 @@ jobs:
383381
echo $! > /tmp/_install.pid
384382
cd ..
385383
sleep 5s
386-
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \
387-
--net=host --host="127.0.0.1" --expose="local"
384+
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0
388385
php occ app_ecosystem_v2:app:register \
389386
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_id\":1,\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"port\":$APP_PORT}" \
390387
-e --force-scopes --system-app

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

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

5+
## [0.0.23 - 2023-07-07]
6+
7+
### Fixed
8+
9+
- `nextcloud_url` can contain `/` at the end.
10+
- work of `logs` during `enable`/`disable` events.
11+
512
## [0.0.22 - 2023-07-05]
613

714
### Added

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ stop:
88
docker container stop to_gif
99

1010
register_app:
11-
nextcloud_url=http://nextcloud.local/index.php app_name=nc_py_api app_version=1.0.0 \
12-
app_secret=tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E\
13-
X1T8Pi+T5papEolTLxz3fJSPS8ffC4204YmggxPsbJdCkXHWNPHKWS9B+vTj2SIV \
11+
NEXTCLOUD_URL=http://nextcloud.local/index.php APP_ID=nc_py_api APP_VERSION=1.0.0 \
12+
APP_SECRET=tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E\
13+
X1T8Pi+T5papEolTLxz3fJSPS8ffC4204YmggxPsbJdCkXHWNPHKWS9B+vTj2SIV APP_PORT=9002 \
1414
python3 tests/_install.py
1515

1616
remove:

nc_py_api/_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BasicConfig:
3838

3939
def __init__(self, **kwargs):
4040
self.full_nc_url = self._get_value("nextcloud_url", **kwargs)
41-
self.endpoint = self.full_nc_url.removesuffix("/index.php")
41+
self.endpoint = self.full_nc_url.removesuffix("/index.php").removesuffix("/")
4242
self.dav_url_suffix = self._get_value("dav_url_suffix", raise_not_found=False, **kwargs)
4343
if not self.dav_url_suffix:
4444
self.dav_url_suffix = options.DAV_URL_SUFFIX

nc_py_api/integration_fastapi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Directly related stuff to FastAPI.
33
"""
44

5-
from typing import Annotated, Callable
5+
from typing import Annotated, Callable, Optional
66

77
from fastapi import Depends, FastAPI, HTTPException, Request, status
88
from fastapi.responses import JSONResponse
@@ -39,7 +39,10 @@ def enabled_handler(
3939
return JSONResponse(content={"error": r}, status_code=200)
4040

4141

42-
def enable_heartbeat(fast_api_app: FastAPI):
42+
def enable_heartbeat(fast_api_app: FastAPI, callback: Optional[Callable[[], str]] = None):
4343
@fast_api_app.get("/heartbeat")
4444
def heartbeat_handler():
45-
return JSONResponse(content={"status": "ok"}, status_code=200)
45+
return_status = "ok"
46+
if callback is not None:
47+
return_status = callback()
48+
return JSONResponse(content={"status": return_status}, status_code=200)

nc_py_api/nextcloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self, **kwargs):
8787
def log(self, log_lvl: LogLvl, content: str):
8888
if self.check_capabilities("app_ecosystem_v2"):
8989
return
90-
if int(log_lvl) < self.capabilities["app_ecosystem_v2"].get("loglevel", 4):
90+
if int(log_lvl) < self.capabilities["app_ecosystem_v2"].get("loglevel", 0):
9191
return
9292
self._session.ocs(
9393
method="POST", path=f"{APP_V2_BASIC_URL}/log", json={"level": int(log_lvl), "message": content}

tests/_install.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import uvicorn
44
from fastapi import FastAPI
55

6-
from nc_py_api import NextcloudApp, set_enabled_handler, ApiScope, set_scopes
6+
from nc_py_api import NextcloudApp, set_enabled_handler, ApiScope, set_scopes, enable_heartbeat, LogLvl
77

88
APP = FastAPI()
99

1010

11-
def enabled_handler(enabled: bool, _nc: NextcloudApp) -> str:
12-
print(f"enabled_handler: enabled={enabled}")
11+
def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
12+
print(f"enabled_handler: enabled={enabled}", flush=True)
13+
if enabled:
14+
nc.log(LogLvl.WARNING, f"Hello from {nc.app_cfg.app_name} :)")
15+
else:
16+
nc.log(LogLvl.WARNING, f"Bye bye from {nc.app_cfg.app_name} :(")
1317
return ""
1418

1519

@@ -30,10 +34,10 @@ def initialization():
3034
"optional": [],
3135
},
3236
)
37+
enable_heartbeat(APP)
3338

3439

3540
if __name__ == "__main__":
36-
app_host = environ.get("APP_HOST", "")
3741
uvicorn.run(
38-
"_install:APP", host=app_host if app_host else "0.0.0.0", port=int(environ["APP_PORT"]), log_level="trace"
42+
"_install:APP", host=environ.get("APP_HOST", "127.0.0.1"), port=int(environ["APP_PORT"]), log_level="trace"
3943
)

0 commit comments

Comments
 (0)