Integrate Coolify API client and module for managing Coolify services, enhancing automation and deployment processes.
This commit is contained in:
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
|
||||
namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use classes\release_manager;
|
||||
use Throwable;
|
||||
use traits\route_t;
|
||||
|
||||
class releaseManagerRoute
|
||||
{
|
||||
use route_t;
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$this->get('/release/bootstrap', function () {
|
||||
global $response;
|
||||
$response->success((new release_manager())->bootstrap());
|
||||
});
|
||||
|
||||
$this->get('/release/runtime', function () {
|
||||
global $response;
|
||||
$response->success((new release_manager())->runtimeForCurrentPrincipal());
|
||||
});
|
||||
|
||||
$this->post('/release/timeline/events', function () {
|
||||
global $response;
|
||||
$payload = $this->requestPayload();
|
||||
$events = is_array($payload['events'] ?? null) ? $payload['events'] : ($payload['event'] ?? $payload);
|
||||
$context = is_array($payload['context'] ?? null) ? $payload['context'] : [];
|
||||
$response->success((new release_manager())->ingestTimelineEvents(
|
||||
is_array($events) ? $events : [],
|
||||
$context
|
||||
), 202);
|
||||
});
|
||||
|
||||
$this->post('/release/github/webhook', function () {
|
||||
global $response;
|
||||
try {
|
||||
$headers = function_exists('getallheaders') ? getallheaders() : [];
|
||||
$rawBody = file_get_contents('php://input') ?: '';
|
||||
$response->success((new release_manager())->handleGithubWebhook($headers, $rawBody), 202);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 401);
|
||||
}
|
||||
});
|
||||
|
||||
$this->get('/superuser/releases', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
$response->success((new release_manager())->summary());
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'View release manager channels, deployments, and health',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/config', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
$response->success((new release_manager())->releaseConfig());
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'View Release Manager source configuration',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/config', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_manage');
|
||||
try {
|
||||
$response->success((new release_manager())->updateReleaseConfig($this->requestPayload(), $this->actorUserId()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_manage' => 'Update Release Manager source configuration',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/github/repositories', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
try {
|
||||
$response->success((new release_manager())->listGithubRepositories($this->getParametersAsArray()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'List private GitHub repositories available to Release Manager',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/github/branches', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->listGithubBranches($this->getParametersAsArray()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'List GitHub branches for a Release Manager repository',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/github/commits', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->listGithubCommits($this->getParametersAsArray()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'List or resolve GitHub commits for a Release Manager repository',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/github/test', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
$response->success((new release_manager())->testGithubRepositoryAccess($this->requestPayload()));
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Test Release Manager access to a GitHub repository, branch, and commit',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/channels', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
$response->success((new release_manager())->listChannels());
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'View release channels',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/channels', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_manage');
|
||||
try {
|
||||
$response->success((new release_manager())->createChannel($this->requestPayload(), $this->actorUserId()), 201);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_manage' => 'Create release channels',
|
||||
]);
|
||||
|
||||
$this->patch('/superuser/releases/channels/{id}', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_manage');
|
||||
try {
|
||||
$response->success((new release_manager())->updateChannel($this->routeId(), $this->requestPayload(), $this->actorUserId()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_manage' => 'Update release channels',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/channels/{id}/rollback', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_rollback');
|
||||
try {
|
||||
$response->success((new release_manager())->rollbackChannel($this->routeId(), $this->actorUserId()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 409);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_rollback' => 'Rollback an active release channel',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/assignments', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
$response->success((new release_manager())->listAssignments());
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'View release channel assignments',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/assignments', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_manage');
|
||||
try {
|
||||
$response->success((new release_manager())->createAssignment($this->requestPayload(), $this->actorUserId()), 201);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_manage' => 'Assign users, subusers, or customers to release channels',
|
||||
]);
|
||||
|
||||
$this->delete('/superuser/releases/assignments/{id}', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_manage');
|
||||
try {
|
||||
$response->success((new release_manager())->deleteAssignment($this->routeId(), $this->actorUserId()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 404);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_manage' => 'Remove release channel assignments',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/targets', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
$response->success((new release_manager())->listDeploymentTargets());
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'View release deployment targets',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/targets', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->upsertDeploymentTarget($this->requestPayload(), $this->actorUserId()), 201);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Create or update GitHub to Coolify release deployment targets',
|
||||
]);
|
||||
|
||||
$this->delete('/superuser/releases/targets/{id}', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->deleteDeploymentTarget($this->routeId(), $this->actorUserId()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 404);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Delete release deployment targets',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/service-sets', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
$response->success((new release_manager())->listServiceSets());
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'View reusable Release Manager service sets',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/service-sets', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->createServiceSet($this->requestPayload(), $this->actorUserId()), 201);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Create reusable Release Manager service sets',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/bundles', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
$limit = (int)($this->getParameter('limit') ?? 50);
|
||||
$response->success((new release_manager())->listBundles($limit));
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'View Release Manager bundles',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/bundles', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->createBundle($this->requestPayload(), $this->actorUserId()), 201);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Create Release Manager full-stack bundles',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/bundles/{id}/deploy', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->deployBundle($this->routeId(), $this->actorUserId()), 202);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 409);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Deploy Release Manager full-stack bundles',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/bundles/{id}/promote', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->promoteBundle($this->routeId(), $this->actorUserId()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 409);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Promote Release Manager bundles without data failover',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/deployments', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_view');
|
||||
$limit = (int)($this->getParameter('limit') ?? 50);
|
||||
$response->success((new release_manager())->listDeployments($limit));
|
||||
}, [
|
||||
'superuser_release_manager_view' => 'View release deployments',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/deployments', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->startDeployment($this->requestPayload(), $this->actorUserId()), 202);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 409);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Trigger release deployments from GitHub/Coolify targets',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/deployments/{id}/promote', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_deploy');
|
||||
try {
|
||||
$response->success((new release_manager())->promoteDeployment($this->routeId(), $this->actorUserId()));
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 409);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_deploy' => 'Promote a deployment to its release channel',
|
||||
]);
|
||||
|
||||
$this->post('/superuser/releases/replay-targets', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_replay');
|
||||
try {
|
||||
$response->success((new release_manager())->setReplayTarget($this->requestPayload(), $this->actorUserId()), 201);
|
||||
} catch (Throwable $throwable) {
|
||||
$response->error(['message' => $throwable->getMessage()], 400);
|
||||
}
|
||||
}, [
|
||||
'superuser_release_manager_replay' => 'Enable release timeline replay capture for a user, customer, subuser, or channel',
|
||||
]);
|
||||
|
||||
$this->get('/superuser/releases/timeline', function () {
|
||||
global $response;
|
||||
$this->requirePermission('superuser_release_manager_replay');
|
||||
$response->success((new release_manager())->searchTimeline($this->getParametersAsArray()));
|
||||
}, [
|
||||
'superuser_release_manager_replay' => 'Replay release failure timelines',
|
||||
]);
|
||||
}
|
||||
|
||||
private function routeId(): int
|
||||
{
|
||||
$id = (int)$this->fromRoute('id');
|
||||
$this->requireParameterIntPositive($id, 'id');
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function actorUserId(): ?int
|
||||
{
|
||||
try {
|
||||
$user = (new authentication())->get_user();
|
||||
return $user !== false && isset($user->id) ? (int)$user->id : null;
|
||||
} catch (Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function requestPayload(): array
|
||||
{
|
||||
$payload = json_decode(file_get_contents('php://input'), true);
|
||||
if (!is_array($payload)) {
|
||||
$payload = [];
|
||||
}
|
||||
|
||||
if ($_GET !== []) {
|
||||
$payload = array_replace($payload, $_GET);
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user