Commit Graph

215 Commits

Author SHA1 Message Date
f15c6ea1d9 fix(AppAPIService): encode query parameter arrays via http_build_query (#412)
Resolves #384. If the checks still pass and this gets merged, perhaps we
should take a look at other apps to see if they need to be updated in
the same way.

Signed-off-by: Edward Ly <contact@edward.ly>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-10-08 16:50:43 +03:00
f0a44bfd48 feat: add removal of webhook listeners during ExApp unregister (#382)
Resolves: #377 

Add webhooks removal during ExApp unregister only for NC30+ version.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-09-10 13:00:41 +03:00
575b3d4f74 removed not used last_check_time field (#375)
Also drops no longer used field `api_scopes` from the DB

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-09-05 14:29:38 +03:00
1eab9f6814 feat: remove ApiScopes (#373)
Ongoing optimization, unnecessary stuff removal to reduce the number of
requests during AppAPIAuth.

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-09-04 20:37:02 +03:00
7c0587e8f2 call throttler->resetDelay if only when delay present (#369)
This will require **one less network request** for each successful
request from ExApp

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-08-22 22:15:17 +03:00
daffdc6a2a fix(TopMenuEntry): correct admin check (#358)
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-08-15 12:02:32 +03:00
666f5be310 added logging of ExApp requests made on behalf of user (#360)
1. Logs are written to a separate file
2. Log level - Warning
3. Only for those requests where "user" is set

Reference:
https://github.com/nextcloud/server/pull/46539#pullrequestreview-2182378157

this is how logs look like:

```json
{"reqId":"t9ThOI2CheVn6sDUsUKO","level":2,"time":"2024-08-13T10:08:42+00:00","remoteAddr":"192.168.65.1","user":"admin","app":"nc_py_api","method":"GET","url":"/ocs/v1.php/cloud/capabilities?format=json","message":"impersonation request","userAgent":"python-httpx/0.25.2","version":"30.0.0.7","data":{"app":"nc_py_api"}}
{"reqId":"tVtHIEwQ5YKhbWUFTmKF","level":2,"time":"2024-08-13T10:08:42+00:00","remoteAddr":"192.168.65.1","user":"admin","app":"nc_py_api","method":"PROPFIND","url":"/remote.php/dav/files/admin","message":"impersonation request","userAgent":"python-httpx/0.25.2","version":"30.0.0.7","data":{"app":"nc_py_api"}}
```

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-08-15 10:58:45 +03:00
c054c4c2ac feat: Add enum and default value support in task processing (#359)
All related PRs:
https://github.com/cloud-py-api/nc_py_api/pull/284
https://github.com/cloud-py-api/app_api/pull/359
https://github.com/nextcloud/translate2/pull/11

Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-08-12 09:32:16 +00:00
b5f8caf865 fix: disable caching if APCu detected (#348)
We do not disable caches in other places as in CLI only `/ex_apps` cache
is used.

Linked issue: https://github.com/cloud-py-api/app_api/issues/291

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-08-05 15:23:47 +03:00
7cbca1a23b enh: use distributed cache only when available (#347)
It's a refactoring, it doesn't really fix anything(?), but it makes
working with caches in the style of a Nextcloud server repository.

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-08-03 14:10:09 +03:00
a005bb75db fix(TaskProcessing): do not log in get providers
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-08-02 18:48:02 +03:00
65003cd5d1 ExApp routes (public/user/admin) support (#327)
This PR introduces new (mandatory if you use the ExApp proxy) registration of the routes that are allowed to call on ExApp via AppAPI ExApp proxy.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-08-02 16:47:06 +03:00
f43ad47ec5 do not disable ExApp on lower version (#341)
1. Will be required for future AI ExApps with scaling
2. Will be required for future ExApps with federated support
3. Requited by **WorkflowEngine project** at it's current stage
4. This will make developing of ExApps easier, as usual in
"manual"registration" we use different app version(constant "1.0.0")

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-08-01 23:13:06 +03:00
5da22289d5 fix: Quick fix for taskprocessing API in nc 30 (#336) 2024-07-26 13:34:12 +02:00
14fb2ff8ad fix: preserve original Authentication to be swapped later in HaProxy (#334)
Ref: https://github.com/cloud-py-api/docker-socket-proxy/pull/33

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-07-23 14:03:32 +03:00
636d7b873f feat(TaskProcessing): Allow defining custom task types (#324)
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-07-14 09:07:55 +02:00
eea14dc504 optimization: system flag and ex_app_users removal (#323)
The system flag and extra table for that `ex_app_users` is removed to
optimize database usage and simplify the system logic.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-07-11 17:08:52 +00:00
1e71efd3ef Set the default timeout for requests to ExApps if none is set. (#277) 2024-07-10 12:19:56 +00:00
1ac1d66dcb added new setAppInitProgress function (#319) 2024-07-10 14:45:50 +03:00
7820f655b2 speed: removed debug logging to aa_debug.log (#320)
For every incoming request to the cloud, we do an extra read from the
database.
For every outgoing request, we do the same.

Anyway, we haven’t used this thing once in a year; it’s easier to remove
it than to transfer this flag to the ex_app table to optimize speed.

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-07-10 13:53:40 +03:00
e1bc72ed89 allow for disabled ExApp to get "enabled" flag state (#318)
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-07-05 22:19:35 +03:00
15db25c7db feat: Add task processing API (#294)
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-07-05 19:50:28 +02:00
26d61a40bd UIProxy: fixed incorrect the Domain of cookie (#305)
Currently cookies always rejected when ExApp is installed in DSP with
`HTTPS` - this is now fixed.

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-06-12 14:18:46 +03:00
962a81f0e4 corrected ExApp status reset during enabling (#302)
Changes in this PullRequest:

* moved `resetCaches` into `updateExApp`
* always reset all ex_app cache when fail writing to DB
* always update ExApp `status` in DB when enabling ExApp

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-06-10 21:17:43 +03:00
0a80c686df ExApp proxy adjustments and fixes (#296)
This PR made a few changes to ExApp proxy:

1. Fix Get requests proxy to preserve the url params
2. Add pass of cookies to the ExApp with request
3. Fixes Proxy work with multipart requests and files using separate
internal version of requestToExApp with slightly adjusted handling of
query and body params
4. Remove default caching for json requests

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-06-10 20:50:42 +03:00
5503b80879 Add occ command for sending events truly async (#295)
This PR introduces our internal occ command for sending a request to
ExApp with notification about an event happened. The occ command is
needed to perform the HTTP request in a truly async maner not blocking
the original PHP process during request, that have to improve the user
experience.
The request is limited to 2s timeout, so that this occ command process
shouldn't live too long to not exceed the limits.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-05-22 19:23:00 +03:00
de235e2b48 WIP: add async requestToExApp, OCS API endpoints (#290)
This PR introduces async requestToExApp Public functions + two OCS
endpoints for requestToExApp and exAppRequestWithUserInit.
Some logging level adjustments.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-05-10 13:09:05 +00:00
139e79312f feat: file actions redirect, v2 api version (#284)
This PR introduces a simple File Actions menu redirect option to open
ExApp UI page with the context of selected files.

Resolves: #136

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-05-08 12:20:46 +00:00
3d503b3403 drop ExApp scopes table, rewrite code of it (#285)
This is ongoing part of optimizations of reducing the number of
database/cache requests.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-05-07 10:50:51 +03:00
af00e1787f Test deploy adjustments (#280)
Test Deploy fixes, timeout logic adjustments, docs.
2024-04-30 13:59:54 +03:00
3bf5132211 feat: Test deploy feature (#279)
This PR introduces a "Test deploy" button for each Daemon configuration
to verify each step and identify the error.

Resolves: https://github.com/cloud-py-api/app_api/issues/174

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-04-29 13:36:32 +03:00
3b06bd789f fix(occ): incorrect type of field in ExAppOccCommand (#278)
Should fix incorrect type handling by different DBMS during ExApp occ
command registration.

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-04-23 21:12:15 +03:00
052e3a000c ExApp occ commands API (#272)
This PR introduces API for registering OCC commands for ExApps.

Note: **Passing file contents as the input argument is not supported**

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-04-19 10:15:22 +00:00
e391299335 fixed ExApp with one scope(llm2 for example) installation error (#275)
In our current code, `$appInfo['external-app']['scopes']['value']` is
sometimes an array and sometimes not, depending on the data.

To ensure that `$appInfo['external-app']['scopes']` is always an array,
even if it's just one value, we use the is_array() function to check the
type and then adjust accordingly.

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-04-17 17:04:04 +03:00
7391eeea65 initial support for Docker Healthcheck (#273)
Before this, we didn’t have a `healthcheck` at all, but instead there
was simply a check to see if the container was running.

Checking whether the container is running has been moved to Deploy stage
and now occurs at the end of the deployment process.
And between deployment and “init” there is now a correct health check.
Applications are not required to support healthcheck at all, so it is
only checked if `['State']['Health']['Status']` is present.

Without a timeout, the timeout must be set by the application itself, as
it is usually done for Docker containers healthcheck.

During a healthcheck, an application, for example, can now install some
of its own packages or do something other with its docker container.

It should not communicate with the Nextcloud itself at this
stage(healthcheck), because application is not considered enabled.

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Co-authored-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-04-17 11:41:04 +03:00
b82394cf82 Additional options for daemon deploy config (#269)
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-04-10 11:50:05 +00:00
cb4dfa2868 added cache reset for ExApp events listeners (#264)
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-04-04 14:18:40 +03:00
36c2db5835 removed "ex_apps_api_scopes" table (#262)
We hold pre-defined API Scopes in memory only.

Anyway we currently do not supporting defining API Scopes at runtime and
not sure that we will in future, so better to make it simpler and faster
for now.

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-04-04 12:05:23 +03:00
1917ca85ee secrets appear on errors in logfile (#261)
With PHP>=8.2 they will appear like this:

```
/var/www/html/apps-extra/app_api/lib/Service/AppAPIService.php
line 89
OCA\AppAPI\Service\AppAPIService->requestToExAppInternal(
  [
    "OCA\\AppAPI\\Db\\ExApp",
    3
  ],
  "POST",
  "http://host.docker.internal:9031/video_to_gif",
  [
    "SensitiveParameterValue"
  ]
)
```

Also adjustments in the Nextcloud Server required, to hide headers in
`IClient` calls, we cannot do it from AppAPI side.

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-04-02 16:28:24 +03:00
46a51fc637 EventsListener API (#259)
Node Events
***********

``node_event`` - events about File `Nodes`

Supported event sub-types:

* NodeCreatedEvent
* NodeTouchedEvent
* NodeWrittenEvent
* NodeDeletedEvent
* NodeRenamedEvent
* NodeCopiedEvent

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-04-02 11:09:09 +03:00
e2af6b43cc corrected error handling for occ:app:register and "update" (#258)
Without this it just throws exception where nothing is clear, better to
return correct error description.

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-03-29 14:11:03 +03:00
f7eefb801b performance: store API scopes as a list in the main table (#254)
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-03-27 19:24:34 +03:00
8c0664382f ExApp caching: "exApp_" -> "ex_apps" (#253)
Should significantly improve the performance of anything that uses the
getExAppsList function:

1. Admin page
2. ExAppUIL10N middleware
3. And in many other places where there were multiple cyclic calls to
`getExApp`

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-03-20 15:14:10 +03:00
e0779c9b88 Check for AppAPI Auth header (#251)
1. In `AppAPIAuthMiddleware` we should check for `AUTHORIZATION-APP-API`
header to not first perform request to DB.
2. In `validateExAppRequestToNC` we should do the same but for
'EX-APP-ID' header.
3. Removed debug log from `getExApp`, to not spam logs.

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-03-18 12:06:34 +03:00
0fbc77e4e2 added text-processing and translation api scopes (#249)
Also removed from docs on that make mention of already removed
`optional` Api Scopes.

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-03-17 12:42:17 +00:00
d5235e15a6 Added app_api_system flag to "session" for SysApps (#248)
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-03-13 11:42:16 +03:00
2a0c19c9dc changed loglvl from "error" to "debug" (#243)
It is not an error, but just usual situation.

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-02-21 22:39:34 +03:00
daf2315513 always reset cache during ExApp unregister (#241)
subj, a little more code, but more secure when "MYSQL Server has gone
away" error occurs

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-02-21 16:10:02 +00:00
4e44e4a2e4 add ISpeechToTextProviderWithUserId interface (#240)
Adding `ISpeechToTextProviderWithUserId` interface to STT implementation
after it is merged and available in server.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
2024-02-21 15:04:37 +00:00
8f1f784dd4 exAppRequestWithUserInit can accept empty userId (#238)
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
2024-02-21 17:37:45 +03:00