2024-02-16 21:56:38 +01:00
|
|
|
<?php
|
|
|
|
|
2024-06-28 15:05:37 +02:00
|
|
|
use App\Enums\BuildPackTypes;
|
|
|
|
use App\Enums\RedirectTypes;
|
2024-06-21 16:46:13 +02:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2024-07-01 16:26:50 +02:00
|
|
|
use Illuminate\Http\Request;
|
2024-06-28 15:05:37 +02:00
|
|
|
use Illuminate\Validation\Rule;
|
2024-06-21 16:46:13 +02:00
|
|
|
|
2024-07-01 16:26:50 +02:00
|
|
|
function getTeamIdFromToken()
|
2024-02-16 21:56:38 +01:00
|
|
|
{
|
|
|
|
$token = auth()->user()->currentAccessToken();
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-16 21:56:38 +01:00
|
|
|
return data_get($token, 'team_id');
|
|
|
|
}
|
2024-07-01 16:26:50 +02:00
|
|
|
function invalidTokenResponse()
|
2024-03-07 12:27:23 +01:00
|
|
|
{
|
2024-07-01 16:26:50 +02:00
|
|
|
return response()->json(['success' => false, 'message' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api-reference/authorization'], 400);
|
2024-03-07 12:27:23 +01:00
|
|
|
}
|
2024-06-21 16:46:13 +02:00
|
|
|
|
2024-07-01 16:26:50 +02:00
|
|
|
function serializeApiResponse($data)
|
2024-06-21 16:46:13 +02:00
|
|
|
{
|
|
|
|
if (! $data instanceof Collection) {
|
|
|
|
$data = collect($data);
|
|
|
|
}
|
|
|
|
$data = $data->sortKeys();
|
2024-07-01 16:26:50 +02:00
|
|
|
|
2024-06-21 16:46:13 +02:00
|
|
|
$created_at = data_get($data, 'created_at');
|
|
|
|
$updated_at = data_get($data, 'updated_at');
|
|
|
|
if ($created_at) {
|
|
|
|
unset($data['created_at']);
|
|
|
|
$data['created_at'] = $created_at;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($updated_at) {
|
|
|
|
unset($data['updated_at']);
|
|
|
|
$data['updated_at'] = $updated_at;
|
|
|
|
}
|
2024-07-01 16:26:50 +02:00
|
|
|
if (data_get($data, 'name')) {
|
|
|
|
$data = $data->prepend($data['name'], 'name');
|
|
|
|
}
|
|
|
|
if (data_get($data, 'description')) {
|
|
|
|
$data = $data->prepend($data['description'], 'description');
|
|
|
|
}
|
|
|
|
if (data_get($data, 'uuid')) {
|
|
|
|
$data = $data->prepend($data['uuid'], 'uuid');
|
|
|
|
}
|
|
|
|
|
2024-06-21 16:46:13 +02:00
|
|
|
if (data_get($data, 'id')) {
|
|
|
|
$data = $data->prepend($data['id'], 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2024-06-28 15:05:37 +02:00
|
|
|
|
|
|
|
function sharedDataApplications()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'git_repository' => 'string',
|
|
|
|
'git_branch' => 'string',
|
|
|
|
'build_pack' => Rule::enum(BuildPackTypes::class),
|
|
|
|
'is_static' => 'boolean',
|
|
|
|
'domains' => 'string',
|
|
|
|
'redirect' => Rule::enum(RedirectTypes::class),
|
|
|
|
'git_commit_sha' => 'string',
|
|
|
|
'docker_registry_image_name' => 'string|nullable',
|
|
|
|
'docker_registry_image_tag' => 'string|nullable',
|
|
|
|
'install_command' => 'string|nullable',
|
|
|
|
'build_command' => 'string|nullable',
|
|
|
|
'start_command' => 'string|nullable',
|
|
|
|
'ports_exposes' => 'string|regex:/^(\d+)(,\d+)*$/',
|
|
|
|
'ports_mappings' => 'string|regex:/^(\d+:\d+)(,\d+:\d+)*$/|nullable',
|
|
|
|
'base_directory' => 'string|nullable',
|
|
|
|
'publish_directory' => 'string|nullable',
|
|
|
|
'health_check_enabled' => 'boolean',
|
|
|
|
'health_check_path' => 'string',
|
|
|
|
'health_check_port' => 'string|nullable',
|
|
|
|
'health_check_host' => 'string',
|
|
|
|
'health_check_method' => 'string',
|
|
|
|
'health_check_return_code' => 'numeric',
|
|
|
|
'health_check_scheme' => 'string',
|
|
|
|
'health_check_response_text' => 'string|nullable',
|
|
|
|
'health_check_interval' => 'numeric',
|
|
|
|
'health_check_timeout' => 'numeric',
|
|
|
|
'health_check_retries' => 'numeric',
|
|
|
|
'health_check_start_period' => 'numeric',
|
|
|
|
'limits_memory' => 'string',
|
|
|
|
'limits_memory_swap' => 'string',
|
|
|
|
'limits_memory_swappiness' => 'numeric',
|
|
|
|
'limits_memory_reservation' => 'string',
|
|
|
|
'limits_cpus' => 'string',
|
|
|
|
'limits_cpuset' => 'string|nullable',
|
|
|
|
'limits_cpu_shares' => 'numeric',
|
|
|
|
'custom_labels' => 'string|nullable',
|
|
|
|
'custom_docker_run_options' => 'string|nullable',
|
|
|
|
'post_deployment_command' => 'string|nullable',
|
|
|
|
'post_deployment_command_container' => 'string',
|
|
|
|
'pre_deployment_command' => 'string|nullable',
|
|
|
|
'pre_deployment_command_container' => 'string',
|
|
|
|
'manual_webhook_secret_github' => 'string|nullable',
|
|
|
|
'manual_webhook_secret_gitlab' => 'string|nullable',
|
|
|
|
'manual_webhook_secret_bitbucket' => 'string|nullable',
|
|
|
|
'manual_webhook_secret_gitea' => 'string|nullable',
|
|
|
|
];
|
|
|
|
}
|
2024-07-01 16:26:50 +02:00
|
|
|
|
|
|
|
function validateIncomingRequest(Request $request)
|
|
|
|
{
|
|
|
|
// check if request is json
|
|
|
|
if (! $request->isJson()) {
|
|
|
|
return response()->json([
|
|
|
|
'success' => false,
|
|
|
|
'message' => 'Invalid request.',
|
|
|
|
'error' => 'Content-Type must be application/json.',
|
|
|
|
], 400);
|
|
|
|
}
|
|
|
|
// check if request is valid json
|
|
|
|
if (! json_decode($request->getContent())) {
|
|
|
|
return response()->json([
|
|
|
|
'success' => false,
|
|
|
|
'message' => 'Invalid request.',
|
|
|
|
'error' => 'Invalid JSON.',
|
|
|
|
], 400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeUnnecessaryFieldsFromRequest(Request $request)
|
|
|
|
{
|
|
|
|
$request->offsetUnset('project_uuid');
|
|
|
|
$request->offsetUnset('environment_name');
|
|
|
|
$request->offsetUnset('destination_uuid');
|
|
|
|
$request->offsetUnset('server_uuid');
|
|
|
|
$request->offsetUnset('type');
|
|
|
|
$request->offsetUnset('domains');
|
|
|
|
$request->offsetUnset('instant_deploy');
|
|
|
|
$request->offsetUnset('github_app_uuid');
|
|
|
|
$request->offsetUnset('private_key_uuid');
|
|
|
|
}
|