2023-03-17 15:33:48 +01:00
< ? php
2024-07-01 16:26:50 +02:00
use App\Http\Controllers\Api\ApplicationsController ;
2025-11-25 09:52:08 +01:00
use App\Http\Controllers\Api\CloudProviderTokensController ;
2024-07-01 16:26:50 +02:00
use App\Http\Controllers\Api\DatabasesController ;
use App\Http\Controllers\Api\DeployController ;
2025-09-22 15:11:30 +02:00
use App\Http\Controllers\Api\GithubController ;
2025-11-25 09:52:08 +01:00
use App\Http\Controllers\Api\HetznerController ;
2024-07-06 14:34:15 +02:00
use App\Http\Controllers\Api\OtherController ;
2024-07-01 16:26:50 +02:00
use App\Http\Controllers\Api\ProjectController ;
use App\Http\Controllers\Api\ResourcesController ;
2026-02-16 22:26:58 +03:00
use App\Http\Controllers\Api\ScheduledTasksController ;
2024-07-01 16:26:50 +02:00
use App\Http\Controllers\Api\SecurityController ;
use App\Http\Controllers\Api\ServersController ;
2024-07-02 16:12:04 +02:00
use App\Http\Controllers\Api\ServicesController ;
2024-07-01 16:26:50 +02:00
use App\Http\Controllers\Api\TeamController ;
use App\Http\Middleware\ApiAllowed ;
2024-10-14 12:07:37 +02:00
use App\Jobs\PushServerUpdateJob ;
use App\Models\Server ;
2023-03-17 15:33:48 +01:00
use Illuminate\Support\Facades\Route ;
2024-01-25 13:45:17 +01:00
2024-07-06 14:34:15 +02:00
Route :: get ( '/health' , [ OtherController :: class , 'healthcheck' ]);
2025-04-22 11:05:55 +02:00
Route :: group ([
'prefix' => 'v1' ,
], function () {
Route :: get ( '/health' , [ OtherController :: class , 'healthcheck' ]);
});
2024-02-16 21:56:38 +01:00
2026-04-19 14:41:47 +02:00
Route :: post ( '/feedback' , [ OtherController :: class , 'feedback' ])
-> middleware ( 'throttle:feedback' );
2025-04-23 20:59:20 +02:00
2023-10-20 14:51:01 +02:00
Route :: group ([
2024-12-09 10:28:34 +01:00
'middleware' => [ 'auth:sanctum' , 'api.ability:write' ],
2024-06-10 20:43:34 +00:00
'prefix' => 'v1' ,
2024-07-01 16:26:50 +02:00
], function () {
2024-07-06 14:34:15 +02:00
Route :: get ( '/enable' , [ OtherController :: class , 'enable_api' ]);
Route :: get ( '/disable' , [ OtherController :: class , 'disable_api' ]);
2026-04-29 10:30:43 +02:00
Route :: get ( '/mcp/enable' , [ OtherController :: class , 'enable_mcp' ]);
Route :: get ( '/mcp/disable' , [ OtherController :: class , 'disable_mcp' ]);
2024-07-01 16:26:50 +02:00
});
Route :: group ([
2024-12-09 11:10:35 +01:00
'middleware' => [ 'auth:sanctum' , ApiAllowed :: class , 'api.sensitive' ],
2024-07-01 16:26:50 +02:00
'prefix' => 'v1' ,
2023-10-20 14:51:01 +02:00
], function () {
2024-12-17 12:17:50 +01:00
2024-12-09 10:28:34 +01:00
Route :: get ( '/version' , [ OtherController :: class , 'version' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/teams' , [ TeamController :: class , 'teams' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/teams/current' , [ TeamController :: class , 'current_team' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/teams/current/members' , [ TeamController :: class , 'current_team_members' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/teams/{id}' , [ TeamController :: class , 'team_by_id' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/teams/{id}/members' , [ TeamController :: class , 'members_by_id' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/projects' , [ ProjectController :: class , 'projects' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/projects/{uuid}' , [ ProjectController :: class , 'project_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2025-08-16 18:27:38 +02:00
Route :: get ( '/projects/{uuid}/environments' , [ ProjectController :: class , 'get_environments' ]) -> middleware ([ 'api.ability:read' ]);
2024-12-17 13:42:16 +01:00
Route :: get ( '/projects/{uuid}/{environment_name_or_uuid}' , [ ProjectController :: class , 'environment_details' ]) -> middleware ([ 'api.ability:read' ]);
2025-08-16 18:27:38 +02:00
Route :: post ( '/projects/{uuid}/environments' , [ ProjectController :: class , 'create_environment' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/projects/{uuid}/environments/{environment_name_or_uuid}' , [ ProjectController :: class , 'delete_environment' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
2026-02-24 14:57:32 +01:00
Route :: post ( '/projects' , [ ProjectController :: class , 'create_project' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
Route :: patch ( '/projects/{uuid}' , [ ProjectController :: class , 'update_project' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/projects/{uuid}' , [ ProjectController :: class , 'delete_project' ]) -> middleware ([ 'api.ability:write' ]);
Route :: get ( '/security/keys' , [ SecurityController :: class , 'keys' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/security/keys' , [ SecurityController :: class , 'create_key' ]) -> middleware ([ 'api.ability:write' ]);
Route :: get ( '/security/keys/{uuid}' , [ SecurityController :: class , 'key_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
Route :: patch ( '/security/keys/{uuid}' , [ SecurityController :: class , 'update_key' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/security/keys/{uuid}' , [ SecurityController :: class , 'delete_key' ]) -> middleware ([ 'api.ability:write' ]);
2025-11-25 09:52:08 +01:00
Route :: get ( '/cloud-tokens' , [ CloudProviderTokensController :: class , 'index' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/cloud-tokens' , [ CloudProviderTokensController :: class , 'store' ]) -> middleware ([ 'api.ability:write' ]);
Route :: get ( '/cloud-tokens/{uuid}' , [ CloudProviderTokensController :: class , 'show' ]) -> middleware ([ 'api.ability:read' ]);
Route :: patch ( '/cloud-tokens/{uuid}' , [ CloudProviderTokensController :: class , 'update' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/cloud-tokens/{uuid}' , [ CloudProviderTokensController :: class , 'destroy' ]) -> middleware ([ 'api.ability:write' ]);
2026-03-10 22:00:26 +01:00
Route :: post ( '/cloud-tokens/{uuid}/validate' , [ CloudProviderTokensController :: class , 'validateToken' ]) -> middleware ([ 'api.ability:write' ]);
2025-11-25 09:52:08 +01:00
2025-06-24 17:17:48 +02:00
Route :: match ([ 'get' , 'post' ], '/deploy' , [ DeployController :: class , 'deploy' ]) -> middleware ([ 'api.ability:deploy' ]);
2024-12-09 10:28:34 +01:00
Route :: get ( '/deployments' , [ DeployController :: class , 'deployments' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/deployments/{uuid}' , [ DeployController :: class , 'deployment_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2025-10-16 11:01:56 +02:00
Route :: post ( '/deployments/{uuid}/cancel' , [ DeployController :: class , 'cancel_deployment' ]) -> middleware ([ 'api.ability:deploy' ]);
2025-03-31 12:31:17 +01:00
Route :: get ( '/deployments/applications/{uuid}' , [ DeployController :: class , 'get_application_deployments' ]) -> middleware ([ 'api.ability:read' ]);
2024-12-09 10:28:34 +01:00
Route :: get ( '/servers' , [ ServersController :: class , 'servers' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/servers/{uuid}' , [ ServersController :: class , 'server_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/servers/{uuid}/domains' , [ ServersController :: class , 'domains_by_server' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/servers/{uuid}/resources' , [ ServersController :: class , 'resources_by_server' ]) -> middleware ([ 'api.ability:read' ]);
2026-03-10 22:00:26 +01:00
Route :: get ( '/servers/{uuid}/validate' , [ ServersController :: class , 'validate_server' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
2026-02-24 14:57:32 +01:00
Route :: post ( '/servers' , [ ServersController :: class , 'create_server' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
Route :: patch ( '/servers/{uuid}' , [ ServersController :: class , 'update_server' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/servers/{uuid}' , [ ServersController :: class , 'delete_server' ]) -> middleware ([ 'api.ability:write' ]);
2025-11-25 09:52:08 +01:00
Route :: get ( '/hetzner/locations' , [ HetznerController :: class , 'locations' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/hetzner/server-types' , [ HetznerController :: class , 'serverTypes' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/hetzner/images' , [ HetznerController :: class , 'images' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/hetzner/ssh-keys' , [ HetznerController :: class , 'sshKeys' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/servers/hetzner' , [ HetznerController :: class , 'createServer' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
Route :: get ( '/resources' , [ ResourcesController :: class , 'resources' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/applications' , [ ApplicationsController :: class , 'applications' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/applications/public' , [ ApplicationsController :: class , 'create_public_application' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/applications/private-github-app' , [ ApplicationsController :: class , 'create_private_gh_app_application' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/applications/private-deploy-key' , [ ApplicationsController :: class , 'create_private_deploy_key_application' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/applications/dockerfile' , [ ApplicationsController :: class , 'create_dockerfile_application' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/applications/dockerimage' , [ ApplicationsController :: class , 'create_dockerimage_application' ]) -> middleware ([ 'api.ability:write' ]);
2026-01-10 22:44:52 +01:00
/**
* @deprecated Use POST /api/v1/services instead. This endpoint creates a Service, not an Application and is a unstable duplicate of POST /api/v1/services.
2026-02-18 11:53:58 +01:00
*/
2024-12-09 10:28:34 +01:00
Route :: post ( '/applications/dockercompose' , [ ApplicationsController :: class , 'create_dockercompose_application' ]) -> middleware ([ 'api.ability:write' ]);
Route :: get ( '/applications/{uuid}' , [ ApplicationsController :: class , 'application_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
Route :: patch ( '/applications/{uuid}' , [ ApplicationsController :: class , 'update_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/applications/{uuid}' , [ ApplicationsController :: class , 'delete_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
Route :: get ( '/applications/{uuid}/envs' , [ ApplicationsController :: class , 'envs' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/applications/{uuid}/envs' , [ ApplicationsController :: class , 'create_env' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/applications/{uuid}/envs/bulk' , [ ApplicationsController :: class , 'create_bulk_envs' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/applications/{uuid}/envs' , [ ApplicationsController :: class , 'update_env_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/applications/{uuid}/envs/{env_uuid}' , [ ApplicationsController :: class , 'delete_env_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2025-02-02 13:43:31 +00:00
Route :: get ( '/applications/{uuid}/logs' , [ ApplicationsController :: class , 'logs_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2026-03-16 15:34:27 +01:00
Route :: get ( '/applications/{uuid}/storages' , [ ApplicationsController :: class , 'storages' ]) -> middleware ([ 'api.ability:read' ]);
2026-03-23 15:15:02 +01:00
Route :: post ( '/applications/{uuid}/storages' , [ ApplicationsController :: class , 'create_storage' ]) -> middleware ([ 'api.ability:write' ]);
2026-03-16 15:34:27 +01:00
Route :: patch ( '/applications/{uuid}/storages' , [ ApplicationsController :: class , 'update_storage' ]) -> middleware ([ 'api.ability:write' ]);
2026-03-23 15:15:02 +01:00
Route :: delete ( '/applications/{uuid}/storages/{storage_uuid}' , [ ApplicationsController :: class , 'delete_storage' ]) -> middleware ([ 'api.ability:write' ]);
2024-10-30 19:06:50 +11:00
2026-02-23 12:12:10 +01:00
Route :: match ([ 'get' , 'post' ], '/applications/{uuid}/start' , [ ApplicationsController :: class , 'action_deploy' ]) -> middleware ([ 'api.ability:deploy' ]);
Route :: match ([ 'get' , 'post' ], '/applications/{uuid}/restart' , [ ApplicationsController :: class , 'action_restart' ]) -> middleware ([ 'api.ability:deploy' ]);
Route :: match ([ 'get' , 'post' ], '/applications/{uuid}/stop' , [ ApplicationsController :: class , 'action_stop' ]) -> middleware ([ 'api.ability:deploy' ]);
2024-10-30 19:06:50 +11:00
2026-04-17 13:29:11 +02:00
Route :: delete ( '/applications/{uuid}/previews/{pull_request_id}' , [ ApplicationsController :: class , 'delete_preview_by_pull_request_id' ]) -> middleware ([ 'api.ability:write' ]);
2025-10-16 13:19:05 +02:00
Route :: get ( '/github-apps' , [ GithubController :: class , 'list_github_apps' ]) -> middleware ([ 'api.ability:read' ]);
2025-09-22 15:11:30 +02:00
Route :: post ( '/github-apps' , [ GithubController :: class , 'create_github_app' ]) -> middleware ([ 'api.ability:write' ]);
2025-09-22 15:28:18 +02:00
Route :: patch ( '/github-apps/{github_app_id}' , [ GithubController :: class , 'update_github_app' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/github-apps/{github_app_id}' , [ GithubController :: class , 'delete_github_app' ]) -> middleware ([ 'api.ability:write' ]);
2025-09-22 15:11:30 +02:00
Route :: get ( '/github-apps/{github_app_id}/repositories' , [ GithubController :: class , 'load_repositories' ]) -> middleware ([ 'api.ability:read' ]);
Route :: get ( '/github-apps/{github_app_id}/repositories/{owner}/{repo}/branches' , [ GithubController :: class , 'load_branches' ]) -> middleware ([ 'api.ability:read' ]);
2024-12-09 10:28:34 +01:00
Route :: get ( '/databases' , [ DatabasesController :: class , 'databases' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/databases/postgresql' , [ DatabasesController :: class , 'create_database_postgresql' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/databases/mysql' , [ DatabasesController :: class , 'create_database_mysql' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/databases/mariadb' , [ DatabasesController :: class , 'create_database_mariadb' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/databases/mongodb' , [ DatabasesController :: class , 'create_database_mongodb' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/databases/redis' , [ DatabasesController :: class , 'create_database_redis' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/databases/clickhouse' , [ DatabasesController :: class , 'create_database_clickhouse' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/databases/dragonfly' , [ DatabasesController :: class , 'create_database_dragonfly' ]) -> middleware ([ 'api.ability:write' ]);
Route :: post ( '/databases/keydb' , [ DatabasesController :: class , 'create_database_keydb' ]) -> middleware ([ 'api.ability:write' ]);
2024-10-30 19:06:50 +11:00
2024-12-09 10:28:34 +01:00
Route :: get ( '/databases/{uuid}' , [ DatabasesController :: class , 'database_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2025-04-23 20:59:20 +02:00
Route :: get ( '/databases/{uuid}/backups' , [ DatabasesController :: class , 'database_backup_details_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2025-09-22 13:14:45 +02:00
Route :: get ( '/databases/{uuid}/backups/{scheduled_backup_uuid}/executions' , [ DatabasesController :: class , 'list_backup_executions' ]) -> middleware ([ 'api.ability:read' ]);
2024-12-09 10:28:34 +01:00
Route :: patch ( '/databases/{uuid}' , [ DatabasesController :: class , 'update_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2025-10-16 11:01:56 +02:00
Route :: post ( '/databases/{uuid}/backups' , [ DatabasesController :: class , 'create_backup' ]) -> middleware ([ 'api.ability:write' ]);
2025-09-22 13:14:45 +02:00
Route :: patch ( '/databases/{uuid}/backups/{scheduled_backup_uuid}' , [ DatabasesController :: class , 'update_backup' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
Route :: delete ( '/databases/{uuid}' , [ DatabasesController :: class , 'delete_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2025-09-22 13:14:45 +02:00
Route :: delete ( '/databases/{uuid}/backups/{scheduled_backup_uuid}' , [ DatabasesController :: class , 'delete_backup_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/databases/{uuid}/backups/{scheduled_backup_uuid}/executions/{execution_uuid}' , [ DatabasesController :: class , 'delete_execution_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2024-10-30 19:06:50 +11:00
2026-03-23 15:15:02 +01:00
Route :: get ( '/databases/{uuid}/storages' , [ DatabasesController :: class , 'storages' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/databases/{uuid}/storages' , [ DatabasesController :: class , 'create_storage' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/databases/{uuid}/storages' , [ DatabasesController :: class , 'update_storage' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/databases/{uuid}/storages/{storage_uuid}' , [ DatabasesController :: class , 'delete_storage' ]) -> middleware ([ 'api.ability:write' ]);
2026-03-19 23:29:50 +01:00
Route :: get ( '/databases/{uuid}/envs' , [ DatabasesController :: class , 'envs' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/databases/{uuid}/envs' , [ DatabasesController :: class , 'create_env' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/databases/{uuid}/envs/bulk' , [ DatabasesController :: class , 'create_bulk_envs' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/databases/{uuid}/envs' , [ DatabasesController :: class , 'update_env_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/databases/{uuid}/envs/{env_uuid}' , [ DatabasesController :: class , 'delete_env_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2026-02-23 12:12:10 +01:00
Route :: match ([ 'get' , 'post' ], '/databases/{uuid}/start' , [ DatabasesController :: class , 'action_deploy' ]) -> middleware ([ 'api.ability:deploy' ]);
Route :: match ([ 'get' , 'post' ], '/databases/{uuid}/restart' , [ DatabasesController :: class , 'action_restart' ]) -> middleware ([ 'api.ability:deploy' ]);
Route :: match ([ 'get' , 'post' ], '/databases/{uuid}/stop' , [ DatabasesController :: class , 'action_stop' ]) -> middleware ([ 'api.ability:deploy' ]);
2024-10-30 19:06:50 +11:00
2024-12-09 10:28:34 +01:00
Route :: get ( '/services' , [ ServicesController :: class , 'services' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/services' , [ ServicesController :: class , 'create_service' ]) -> middleware ([ 'api.ability:write' ]);
2024-10-30 19:06:50 +11:00
2024-12-09 10:28:34 +01:00
Route :: get ( '/services/{uuid}' , [ ServicesController :: class , 'service_by_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2025-04-22 11:16:45 +02:00
Route :: patch ( '/services/{uuid}' , [ ServicesController :: class , 'update_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
Route :: delete ( '/services/{uuid}' , [ ServicesController :: class , 'delete_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2024-10-30 19:06:50 +11:00
2026-03-23 15:15:02 +01:00
Route :: get ( '/services/{uuid}/storages' , [ ServicesController :: class , 'storages' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/services/{uuid}/storages' , [ ServicesController :: class , 'create_storage' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/services/{uuid}/storages' , [ ServicesController :: class , 'update_storage' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/services/{uuid}/storages/{storage_uuid}' , [ ServicesController :: class , 'delete_storage' ]) -> middleware ([ 'api.ability:write' ]);
2024-12-09 10:28:34 +01:00
Route :: get ( '/services/{uuid}/envs' , [ ServicesController :: class , 'envs' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/services/{uuid}/envs' , [ ServicesController :: class , 'create_env' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/services/{uuid}/envs/bulk' , [ ServicesController :: class , 'create_bulk_envs' ]) -> middleware ([ 'api.ability:write' ]);
Route :: patch ( '/services/{uuid}/envs' , [ ServicesController :: class , 'update_env_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
Route :: delete ( '/services/{uuid}/envs/{env_uuid}' , [ ServicesController :: class , 'delete_env_by_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2024-10-30 19:06:50 +11:00
2026-02-23 12:12:10 +01:00
Route :: match ([ 'get' , 'post' ], '/services/{uuid}/start' , [ ServicesController :: class , 'action_deploy' ]) -> middleware ([ 'api.ability:deploy' ]);
Route :: match ([ 'get' , 'post' ], '/services/{uuid}/restart' , [ ServicesController :: class , 'action_restart' ]) -> middleware ([ 'api.ability:deploy' ]);
Route :: match ([ 'get' , 'post' ], '/services/{uuid}/stop' , [ ServicesController :: class , 'action_stop' ]) -> middleware ([ 'api.ability:deploy' ]);
2026-02-16 22:26:58 +03:00
Route :: get ( '/applications/{uuid}/scheduled-tasks' , [ ScheduledTasksController :: class , 'scheduled_tasks_by_application_uuid' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/applications/{uuid}/scheduled-tasks' , [ ScheduledTasksController :: class , 'create_scheduled_task_by_application_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2026-02-17 02:18:08 +03:00
Route :: patch ( '/applications/{uuid}/scheduled-tasks/{task_uuid}' , [ ScheduledTasksController :: class , 'update_scheduled_task_by_application_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2026-02-17 01:33:46 +03:00
Route :: delete ( '/applications/{uuid}/scheduled-tasks/{task_uuid}' , [ ScheduledTasksController :: class , 'delete_scheduled_task_by_application_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2026-02-18 11:53:58 +01:00
Route :: get ( '/applications/{uuid}/scheduled-tasks/{task_uuid}/executions' , [ ScheduledTasksController :: class , 'executions_by_application_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2026-02-16 22:26:58 +03:00
Route :: get ( '/services/{uuid}/scheduled-tasks' , [ ScheduledTasksController :: class , 'scheduled_tasks_by_service_uuid' ]) -> middleware ([ 'api.ability:read' ]);
Route :: post ( '/services/{uuid}/scheduled-tasks' , [ ScheduledTasksController :: class , 'create_scheduled_task_by_service_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2026-02-17 02:18:08 +03:00
Route :: patch ( '/services/{uuid}/scheduled-tasks/{task_uuid}' , [ ScheduledTasksController :: class , 'update_scheduled_task_by_service_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2026-02-17 01:33:46 +03:00
Route :: delete ( '/services/{uuid}/scheduled-tasks/{task_uuid}' , [ ScheduledTasksController :: class , 'delete_scheduled_task_by_service_uuid' ]) -> middleware ([ 'api.ability:write' ]);
2026-02-18 11:53:58 +01:00
Route :: get ( '/services/{uuid}/scheduled-tasks/{task_uuid}/executions' , [ ScheduledTasksController :: class , 'executions_by_service_uuid' ]) -> middleware ([ 'api.ability:read' ]);
2023-10-20 14:51:01 +02:00
});
2023-09-25 20:57:52 +02:00
2024-10-14 12:07:37 +02:00
Route :: group ([
'prefix' => 'v1' ,
], function () {
Route :: post ( '/sentinel/push' , function () {
$token = request () -> header ( 'Authorization' );
2024-10-14 13:32:36 +02:00
if ( ! $token ) {
2026-04-28 14:50:37 +02:00
auditLogWebhookFailure ( 'sentinel' , 'token_missing' );
2024-10-14 12:07:37 +02:00
return response () -> json ([ 'message' => 'Unauthorized' ], 401 );
}
$naked_token = str_replace ( 'Bearer ' , '' , $token );
2025-01-10 11:54:45 +01:00
try {
$decrypted = decrypt ( $naked_token );
$decrypted_token = json_decode ( $decrypted , true );
2026-04-17 13:29:11 +02:00
} catch ( Exception $e ) {
2026-04-28 14:50:37 +02:00
auditLogWebhookFailure ( 'sentinel' , 'decrypt_failed' );
2025-01-10 11:54:45 +01:00
return response () -> json ([ 'message' => 'Invalid token' ], 401 );
}
2024-10-14 12:07:37 +02:00
$server_uuid = data_get ( $decrypted_token , 'server_uuid' );
2025-01-10 11:54:45 +01:00
if ( ! $server_uuid ) {
2026-04-28 14:50:37 +02:00
auditLogWebhookFailure ( 'sentinel' , 'invalid_token_payload' );
2025-01-10 11:54:45 +01:00
return response () -> json ([ 'message' => 'Invalid token' ], 401 );
}
2024-10-14 12:07:37 +02:00
$server = Server :: where ( 'uuid' , $server_uuid ) -> first ();
2024-10-14 13:32:36 +02:00
if ( ! $server ) {
2026-04-28 14:50:37 +02:00
auditLogWebhookFailure ( 'sentinel' , 'server_not_found' , [
'server_uuid' => $server_uuid ,
]);
2024-10-14 12:07:37 +02:00
return response () -> json ([ 'message' => 'Server not found' ], 404 );
}
2025-01-10 11:54:45 +01:00
if ( isCloud () && data_get ( $server -> team -> subscription , 'stripe_invoice_paid' , false ) === false && $server -> team -> id !== 0 ) {
2026-04-28 14:50:37 +02:00
auditLogWebhookFailure ( 'sentinel' , 'subscription_unpaid' , [
'server_uuid' => $server -> uuid ,
'team_id' => $server -> team_id ,
]);
2025-01-10 11:54:45 +01:00
return response () -> json ([ 'message' => 'Unauthorized' ], 401 );
}
if ( $server -> isFunctional () === false ) {
2026-04-28 14:50:37 +02:00
auditLogWebhookFailure ( 'sentinel' , 'server_not_functional' , [
'server_uuid' => $server -> uuid ,
'team_id' => $server -> team_id ,
]);
2025-01-10 11:54:45 +01:00
return response () -> json ([ 'message' => 'Server is not functional' ], 401 );
}
2024-10-15 13:39:19 +02:00
if ( $server -> settings -> sentinel_token !== $naked_token ) {
2026-04-28 14:50:37 +02:00
auditLogWebhookFailure ( 'sentinel' , 'token_mismatch' , [
'server_uuid' => $server -> uuid ,
'team_id' => $server -> team_id ,
]);
2024-10-15 13:39:19 +02:00
return response () -> json ([ 'message' => 'Unauthorized' ], 401 );
}
2024-10-14 12:07:37 +02:00
$data = request () -> all ();
2024-10-14 13:32:36 +02:00
2024-11-03 14:59:21 +01:00
// \App\Jobs\ServerCheckNewJob::dispatch($server, $data);
2024-10-15 13:39:19 +02:00
PushServerUpdateJob :: dispatch ( $server , $data );
2024-10-15 17:03:50 +02:00
2026-04-28 14:50:37 +02:00
auditLog ( 'sentinel.metrics_pushed' , [
'server_uuid' => $server -> uuid ,
'team_id' => $server -> team_id ,
]);
2024-10-14 12:07:37 +02:00
return response () -> json ([ 'message' => 'ok' ], 200 );
});
});
2024-06-21 16:46:13 +02:00
Route :: any ( '/{any}' , function () {
2024-07-03 13:13:38 +02:00
return response () -> json ([ 'message' => 'Not found.' , 'docs' => 'https://coolify.io/docs' ], 404 );
2024-02-16 21:56:38 +01:00
}) -> where ( 'any' , '.*' );