nextcloud / app_api

Nextcloud AppAPI
https://apps.nextcloud.com/apps/app_api
GNU Affero General Public License v3.0
71 stars 6 forks source link

ExApp routes (public/user/admin) support #327

Closed andrey18106 closed 1 month ago

andrey18106 commented 2 months ago

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.

In your ExApp info.xml - external-app add the routes declaration, e.g.:

<routes>
    <route>
        <url>.*</url>
        <verb>GET,POST,PUT,DELETE</verb>
        <access_level>USER</access_level>
        <headers_to_exclude>[]</headers_to_exclude>
    </route>
</routes>

allows all routes, or more specific:

<routes>
    <route>
        <url>img\/.*</url>
        <verb>GET</verb>
        <access_level>USER</access_level>
        <headers_to_exclude>[]</headers_to_exclude>
    </route>
    <route>
        <url>js\/.*</url>
        <verb>GET</verb>
        <access_level>USER</access_level>
        <headers_to_exclude>[]</headers_to_exclude>
    </route>
    <route>
        <url>css\/.*</url>
        <verb>GET</verb>
        <access_level>USER</access_level>
        <headers_to_exclude>[]</headers_to_exclude>
    </route>
    <route>
        <url>api\/.*</url>
        <verb>GET,POST,PUT,DELETE</verb>
        <access_level>USER</access_level>
        <headers_to_exclude>[]</headers_to_exclude>
    </route>
</routes>
bigcat88 commented 1 month ago

Logs are full of errors:

{"file":"/home/runner/work/app_api/app_api/lib/private/DB/QueryBuilder/QueryBuilder.php","line":270,"function":"executeQuery","class":"OC\\DB\\ConnectionAdapter","type":"->","args":["SELECT `exs`.* FROM `*PREFIX*ex_task_processing` `exs` INNER JOIN `*PREFIX*ex_apps` `exa` ON `exa`.`appid` = `exs`.`app_id` WHERE `exa`.`enabled` = :dcValue1",[1],[1]]},{"file":"/home/runner/work/app_api/app_api/apps/app_api/lib/Db/TaskProcessing/TaskProcessingProviderMapper.php","line":32,"function":"executeQuery","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/home/runner/work/app_api/app_api/apps/app_api/lib/Service/ProvidersAI/TaskProcessingService.php","line":44,"function":"findAllEnabled","class":"OCA\\AppAPI\\Db\\TaskProcessing\\TaskProcessingProviderMapper","type":"->","args":[]},{"file":"/home/runner/work/app_api/app_api/apps/app_api/lib/Service/ProvidersAI/TaskProcessingService.php","line":132,"function":"getRegisteredTaskProcessingProviders","class":"OCA\\AppAPI\\Service\\ProvidersAI\\TaskProcessingService","type":"->","args":[]},{"file":"/home/runner/work/app_api/app_api/apps/app_api/lib/AppInfo/Application.php","line":98,"function":"registerExAppTaskProcessingProviders","class":"OCA\\AppAPI\\Service\\ProvidersAI\\TaskProcessingService","type":"->","args":[["OCP\\AppFramework\\Bootstrap\\IRegistrationContext@anonymous\u0000/home/runner/work/app_api/app_api/lib/private/AppFramework/Bootstrap/RegistrationContext.php:161$5e"],["OC\\Server"]]},{"file":"/home/runner/work/app_api/app_api/lib/private/AppFramework/Bootstrap/Coordinator.php","line":99,"function":"register","class":"OCA\\AppAPI\\AppInfo\\Application","type":"->","args":[["OCP\\AppFramework\\Bootstrap\\IRegistrationContext@anonymous\u0000/home/runner/work/app_api/app_api/lib/private/AppFramework/Bootstrap/RegistrationContext.php:161$5e"]]},{"file":"/home/runner/work/app_api/app_api/lib/private/AppFramework/Bootstrap/Coordinator.php","line":52,"function":"registerApps","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->","args":[["app_api"]]},{"file":"/home/runner/work/app_api/app_api/lib/private/Installer.php","line":95,"function":"runLazyRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->","args":["app_api"]},{"file":"/home/runner/work/app_api/app_api/core/Command/App/Enable.php","line":93,"function":"installApp","class":"OC\\Installer","type":"->","args":["app_api",true]},{"file":"/home/runner/work/app_api/app_api/core/Command/App/Enable.php","line":63,"function":"enableApp","class":"OC\\Core\\Command\\App\\Enable","type":"->","args":["app_api",[],true,["Symfony\\Component\\Console\\Output\\ConsoleOutput"]]},{"file":"/home/runner/work/app_api/app_api/3rdparty/symfony/console/Command/Command.php","line":298,"function":"execute","class":"OC\\Core\\Command\\App\\Enable","type":"->","args":[["Symfony\\Component\\Console\\Input\\ArgvInput"],["Symfony\\Component\\Console\\Output\\ConsoleOutput"]]},{"file":"/home/runner/work/app_api/app_api/3rdparty/symfony/console/Application.php","line":1040,"function":"run","class":"Symfony\\Component\\Console\\Command\\Command","type":"->","args":[["Symfony\\Component\\Console\\Input\\ArgvInput"],["Symfony\\Component\\Console\\Output\\ConsoleOutput"]]},{"file":"/home/runner/work/app_api/app_api/3rdparty/symfony/console/Application.php","line":301,"function":"doRunCommand","class":"Symfony\\Component\\Console\\Application","type":"->","args":[["OC\\Core\\Command\\App\\Enable"],["Symfony\\Component\\Console\\Input\\ArgvInput"],["Symfony\\Component\\Console\\Output\\ConsoleOutput"]]},{"file":"/home/runner/work/app_api/app_api/3rdparty/symfony/console/Application.php","line":171,"function":"doRun","class":"Symfony\\Component\\Console\\Application","type":"->","args":[["Symfony\\Component\\Console\\Input\\ArgvInput"],["Symfony\\Component\\Console\\Output\\ConsoleOutput"]]},{"file":"/home/runner/work/app_api/app_api/lib/private/Console/Application.php","line":183,"function":"run","class":"Symfony\\Component\\Console\\Application","type":"->","args":[["Symfony\\Component\\Console\\Input\\ArgvInput"],["Symfony\\Component\\Console\\Output\\ConsoleOutput"]]},{"file":"/home/runner/work/app_api/app_api/console.php","line":87,"function":"run","class":"OC\\Console\\Application","type":"->","args":[["Symfony\\Component\\Console\\Input\\ArgvInput"]]},{"file":"/home/runner/work/app_api/app_api/occ","line":11,"args":["/home/runner/work/app_api/app_api/console.php"],"function":"require_once"}],"File":"/home/runner/work/app_api/app_api/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php","Line":130}}},"message":"An exception occurred while executing a query: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"oc_ex_task_processing\" does not exist\nLINE 1: SELECT \"exs\".* FROM \"oc_ex_task_processing\" \"exs\" INNER JOIN...\n                            ^","exception":{},"CustomMessage":"An exception occurred while executing a query: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"oc_ex_task_processing\" does not exist\nLINE 1: SELECT \"exs\".* FROM \"oc_ex_task_processing\" \"exs\" INNER JOIN...\n                            ^"}}

which is preventing to see clear why the DeployTests are failing when they should not...

bigcat88 commented 1 month ago

what happens when ExApp get update - in which place routes get updated?

andrey18106 commented 1 month ago

what happens when ExApp get update - in which place routes get updated?

Before update the ExApp is being disabled, which should unregister the routes, after install of new ExApp container and enable procedure - the new ExApp routes then should be registered. This won'twork if it's already disabled though..

bigcat88 commented 1 month ago

after install of new ExApp container and enable procedure

does this will work even if ExApp defines routes only in info.xml file and not register them with API?

andrey18106 commented 1 month ago

after install of new ExApp container and enable procedure

does this will work even if ExApp defines routes only in info.xml file and not register them with API?

It must be registered via API, there is no routes in info.xml.

bigcat88 commented 1 month ago

It should be registered via API, there is no routes in info.xml.

there is, you implemented it.

$appInfo['external-app']['routes'] allow it to be in info.xml