fix: api updates

This commit is contained in:
Andras Bacsai 2024-07-03 13:13:38 +02:00
parent 4459c9f73d
commit b24a489c77
14 changed files with 216 additions and 328 deletions

View File

@ -58,10 +58,7 @@ public function applications(Request $request)
return $this->removeSensitiveData($application); return $this->removeSensitiveData($application);
}); });
return response()->json([ return response()->json($applications);
'success' => true,
'data' => $applications,
]);
} }
public function create_application(Request $request) public function create_application(Request $request)
@ -96,7 +93,6 @@ public function create_application(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -110,22 +106,22 @@ public function create_application(Request $request)
$project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first(); $project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first();
if (! $project) { if (! $project) {
return response()->json(['succes' => false, 'message' => 'Project not found.'], 404); return response()->json(['message' => 'Project not found.'], 404);
} }
$environment = $project->environments()->where('name', $request->environment_name)->first(); $environment = $project->environments()->where('name', $request->environment_name)->first();
if (! $environment) { if (! $environment) {
return response()->json(['success' => false, 'message' => 'Environment not found.'], 404); return response()->json(['message' => 'Environment not found.'], 404);
} }
$server = Server::whereTeamId($teamId)->whereUuid($serverUuid)->first(); $server = Server::whereTeamId($teamId)->whereUuid($serverUuid)->first();
if (! $server) { if (! $server) {
return response()->json(['success' => false, 'message' => 'Server not found.'], 404); return response()->json(['message' => 'Server not found.'], 404);
} }
$destinations = $server->destinations(); $destinations = $server->destinations();
if ($destinations->count() == 0) { if ($destinations->count() == 0) {
return response()->json(['success' => false, 'message' => 'Server has no destinations.'], 400); return response()->json(['message' => 'Server has no destinations.'], 400);
} }
if ($destinations->count() > 1 && ! $request->has('destination_uuid')) { if ($destinations->count() > 1 && ! $request->has('destination_uuid')) {
return response()->json(['success' => false, 'message' => 'Server has multiple destinations and you do not set destination_uuid.'], 400); return response()->json(['message' => 'Server has multiple destinations and you do not set destination_uuid.'], 400);
} }
$destination = $destinations->first(); $destination = $destinations->first();
if ($type === 'public') { if ($type === 'public') {
@ -147,7 +143,6 @@ public function create_application(Request $request)
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $validator->errors(), 'errors' => $validator->errors(),
], 422); ], 422);
@ -195,10 +190,7 @@ public function create_application(Request $request)
} }
} }
return response()->json([ return response()->json(serializeApiResponse($application);
'success' => true,
'data' => serializeApiResponse($application),
]);
} elseif ($type === 'private-gh-app') { } elseif ($type === 'private-gh-app') {
if (! $request->has('name')) { if (! $request->has('name')) {
$request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch)); $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
@ -220,7 +212,6 @@ public function create_application(Request $request)
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $validator->errors(), 'errors' => $validator->errors(),
], 422); ], 422);
@ -231,7 +222,7 @@ public function create_application(Request $request)
} }
$githubApp = GithubApp::whereTeamId($teamId)->where('uuid', $githubAppUuid)->first(); $githubApp = GithubApp::whereTeamId($teamId)->where('uuid', $githubAppUuid)->first();
if (! $githubApp) { if (! $githubApp) {
return response()->json(['success' => false, 'message' => 'Github App not found.'], 404); return response()->json(['message' => 'Github App not found.'], 404);
} }
$gitRepository = $request->git_repository; $gitRepository = $request->git_repository;
if (str($gitRepository)->startsWith('http') || str($gitRepository)->contains('github.com')) { if (str($gitRepository)->startsWith('http') || str($gitRepository)->contains('github.com')) {
@ -284,10 +275,7 @@ public function create_application(Request $request)
} }
} }
return response()->json([ return response()->json(serializeApiResponse($application));
'success' => true,
'data' => serializeApiResponse($application),
]);
} elseif ($type === 'private-deploy-key') { } elseif ($type === 'private-deploy-key') {
if (! $request->has('name')) { if (! $request->has('name')) {
$request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch)); $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
@ -320,7 +308,7 @@ public function create_application(Request $request)
} }
$privateKey = PrivateKey::whereTeamId($teamId)->where('uuid', $request->private_key_uuid)->first(); $privateKey = PrivateKey::whereTeamId($teamId)->where('uuid', $request->private_key_uuid)->first();
if (! $privateKey) { if (! $privateKey) {
return response()->json(['success' => false, 'message' => 'Private Key not found.'], 404); return response()->json(['message' => 'Private Key not found.'], 404);
} }
$application = new Application(); $application = new Application();
@ -368,10 +356,7 @@ public function create_application(Request $request)
} }
} }
return response()->json([ return response()->json(serializeApiResponse($application));
'success' => true,
'data' => serializeApiResponse($application),
]);
} elseif ($type === 'dockerfile') { } elseif ($type === 'dockerfile') {
if (! $request->has('name')) { if (! $request->has('name')) {
$request->offsetSet('name', 'dockerfile-'.new Cuid2(7)); $request->offsetSet('name', 'dockerfile-'.new Cuid2(7));
@ -382,7 +367,6 @@ public function create_application(Request $request)
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $validator->errors(), 'errors' => $validator->errors(),
], 422); ], 422);
@ -393,7 +377,6 @@ public function create_application(Request $request)
} }
if (! isBase64Encoded($request->dockerfile)) { if (! isBase64Encoded($request->dockerfile)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'dockerfile' => 'The dockerfile should be base64 encoded.', 'dockerfile' => 'The dockerfile should be base64 encoded.',
@ -403,7 +386,6 @@ public function create_application(Request $request)
$dockerFile = base64_decode($request->dockerfile); $dockerFile = base64_decode($request->dockerfile);
if (mb_detect_encoding($dockerFile, 'ASCII', true) === false) { if (mb_detect_encoding($dockerFile, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'dockerfile' => 'The dockerfile should be base64 encoded.', 'dockerfile' => 'The dockerfile should be base64 encoded.',
@ -443,10 +425,7 @@ public function create_application(Request $request)
); );
} }
return response()->json([ return response()->json(serializeApiResponse($application));
'success' => true,
'data' => serializeApiResponse($application),
]);
} elseif ($type === 'docker-image') { } elseif ($type === 'docker-image') {
if (! $request->has('name')) { if (! $request->has('name')) {
$request->offsetSet('name', 'docker-image-'.new Cuid2(7)); $request->offsetSet('name', 'docker-image-'.new Cuid2(7));
@ -459,7 +438,6 @@ public function create_application(Request $request)
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $validator->errors(), 'errors' => $validator->errors(),
], 422); ], 422);
@ -496,10 +474,7 @@ public function create_application(Request $request)
); );
} }
return response()->json([ return response()->json(serializeApiResponse($application));
'success' => true,
'data' => serializeApiResponse($application),
]);
} elseif ($type === 'dockercompose') { } elseif ($type === 'dockercompose') {
$allowedFields = ['project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'instant_deploy', 'docker_compose_raw']; $allowedFields = ['project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'instant_deploy', 'docker_compose_raw'];
@ -513,7 +488,6 @@ public function create_application(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -527,7 +501,6 @@ public function create_application(Request $request)
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $validator->errors(), 'errors' => $validator->errors(),
], 422); ], 422);
@ -538,7 +511,6 @@ public function create_application(Request $request)
} }
if (! isBase64Encoded($request->docker_compose_raw)) { if (! isBase64Encoded($request->docker_compose_raw)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'docker_compose_raw' => 'The docker_compose_raw should be base64 encoded.', 'docker_compose_raw' => 'The docker_compose_raw should be base64 encoded.',
@ -577,13 +549,10 @@ public function create_application(Request $request)
$service->parse(isNew: true); $service->parse(isNew: true);
StartService::dispatch($service); StartService::dispatch($service);
return response()->json([ return response()->json(serializeApiResponse($service));
'success' => true,
'data' => serializeApiResponse($service),
]);
} }
return response()->json(['success' => false, 'message' => 'Invalid type.'], 400); return response()->json(['message' => 'Invalid type.'], 400);
} }
@ -595,17 +564,14 @@ public function application_by_uuid(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first(); $application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first();
if (! $application) { if (! $application) {
return response()->json(['success' => false, 'message' => 'Application not found.'], 404); return response()->json(['message' => 'Application not found.'], 404);
} }
return response()->json([ return response()->json($this->removeSensitiveData($application));
'success' => true,
'data' => $this->removeSensitiveData($application),
]);
} }
public function delete_by_uuid(Request $request) public function delete_by_uuid(Request $request)
@ -618,7 +584,6 @@ public function delete_by_uuid(Request $request)
if ($request->collect()->count() == 0) { if ($request->collect()->count() == 0) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Invalid request.', 'message' => 'Invalid request.',
], 400); ], 400);
} }
@ -626,14 +591,12 @@ public function delete_by_uuid(Request $request)
if (! $application) { if (! $application) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Application not found', 'message' => 'Application not found',
], 404); ], 404);
} }
DeleteResourceJob::dispatch($application, $cleanup); DeleteResourceJob::dispatch($application, $cleanup);
return response()->json([ return response()->json([
'success' => true,
'message' => 'Application deletion request queued.', 'message' => 'Application deletion request queued.',
]); ]);
} }
@ -647,7 +610,6 @@ public function update_by_uuid(Request $request)
if ($request->collect()->count() == 0) { if ($request->collect()->count() == 0) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Invalid request.', 'message' => 'Invalid request.',
], 400); ], 400);
} }
@ -659,7 +621,6 @@ public function update_by_uuid(Request $request)
if (! $application) { if (! $application) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Application not found', 'message' => 'Application not found',
], 404); ], 404);
} }
@ -686,7 +647,6 @@ public function update_by_uuid(Request $request)
foreach ($ports as $port) { foreach ($ports as $port) {
if (! is_numeric($port)) { if (! is_numeric($port)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'ports_exposes' => 'The ports_exposes should be a comma separated list of numbers.', 'ports_exposes' => 'The ports_exposes should be a comma separated list of numbers.',
@ -709,7 +669,6 @@ public function update_by_uuid(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -750,10 +709,7 @@ public function update_by_uuid(Request $request)
$application->fill($data); $application->fill($data);
$application->save(); $application->save();
return response()->json([ return response()->json($this->removeSensitiveData($application));
'success' => true,
'data' => $this->removeSensitiveData($application),
]);
} }
public function envs_by_uuid(Request $request) public function envs_by_uuid(Request $request)
@ -766,16 +722,12 @@ public function envs_by_uuid(Request $request)
if (! $application) { if (! $application) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Application not found', 'message' => 'Application not found',
], 404); ], 404);
} }
$envs = $application->environment_variables->sortBy('id')->merge($application->environment_variables_preview->sortBy('id')); $envs = $application->environment_variables->sortBy('id')->merge($application->environment_variables_preview->sortBy('id'));
return response()->json([ return response()->json(serializeApiResponse($envs));
'success' => true,
'data' => serializeApiResponse($envs),
]);
} }
public function update_env_by_uuid(Request $request) public function update_env_by_uuid(Request $request)
@ -795,7 +747,6 @@ public function update_env_by_uuid(Request $request)
if (! $application) { if (! $application) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Application not found', 'message' => 'Application not found',
], 404); ], 404);
} }
@ -817,7 +768,6 @@ public function update_env_by_uuid(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -843,7 +793,6 @@ public function update_env_by_uuid(Request $request)
return response()->json(serializeApiResponse($env)); return response()->json(serializeApiResponse($env));
} else { } else {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Environment variable not found.', 'message' => 'Environment variable not found.',
], 404); ], 404);
} }
@ -862,14 +811,10 @@ public function update_env_by_uuid(Request $request)
} }
$env->save(); $env->save();
return response()->json([ return response()->json(serializeApiResponse($env));
'success' => true,
'data' => serializeApiResponse($env),
]);
} else { } else {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Environment variable not found.', 'message' => 'Environment variable not found.',
], 404); ], 404);
@ -877,8 +822,7 @@ public function update_env_by_uuid(Request $request)
} }
return response()->json([ return response()->json([
'success' => false, 'message' => 'Something is not okay. Are you okay?',
'message' => 'Something went wrong.',
], 500); ], 500);
} }
@ -899,7 +843,6 @@ public function create_bulk_envs(Request $request)
if (! $application) { if (! $application) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Application not found', 'message' => 'Application not found',
], 404); ], 404);
} }
@ -907,7 +850,6 @@ public function create_bulk_envs(Request $request)
$bulk_data = $request->get('data'); $bulk_data = $request->get('data');
if (! $bulk_data) { if (! $bulk_data) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Bulk data is required.', 'message' => 'Bulk data is required.',
], 400); ], 400);
} }
@ -924,7 +866,6 @@ public function create_bulk_envs(Request $request)
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $validator->errors(), 'errors' => $validator->errors(),
], 422); ], 422);
@ -975,10 +916,7 @@ public function create_bulk_envs(Request $request)
} }
} }
return response()->json([ return response()->json(serializeApiResponse($env));
'success' => true,
'data' => serializeApiResponse($env),
]);
} }
public function create_env(Request $request) public function create_env(Request $request)
@ -993,7 +931,6 @@ public function create_env(Request $request)
if (! $application) { if (! $application) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Application not found', 'message' => 'Application not found',
], 404); ], 404);
} }
@ -1015,7 +952,6 @@ public function create_env(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -1025,7 +961,6 @@ public function create_env(Request $request)
$env = $application->environment_variables_preview->where('key', $request->key)->first(); $env = $application->environment_variables_preview->where('key', $request->key)->first();
if ($env) { if ($env) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Environment variable already exists. Use PATCH request to update it.', 'message' => 'Environment variable already exists. Use PATCH request to update it.',
], 409); ], 409);
} else { } else {
@ -1037,10 +972,7 @@ public function create_env(Request $request)
'is_literal' => $request->is_literal ?? false, 'is_literal' => $request->is_literal ?? false,
]); ]);
return response()->json([ return response()->json(serializeApiResponse($env))->setStatusCode(201);
'success' => true,
'data' => serializeApiResponse($env),
])->setStatusCode(201);
} }
} else { } else {
$env = $application->environment_variables->where('key', $request->key)->first(); $env = $application->environment_variables->where('key', $request->key)->first();
@ -1057,16 +989,12 @@ public function create_env(Request $request)
'is_literal' => $request->is_literal ?? false, 'is_literal' => $request->is_literal ?? false,
]); ]);
return response()->json([ return response()->json(serializeApiResponse($env))->setStatusCode(201);
'success' => true,
'data' => serializeApiResponse($env),
])->setStatusCode(201);
} }
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Something went wrong.', 'message' => 'Something went wrong.',
], 500); ], 500);
@ -1082,21 +1010,18 @@ public function delete_env_by_uuid(Request $request)
if (! $application) { if (! $application) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Application not found.', 'message' => 'Application not found.',
], 404); ], 404);
} }
$found_env = EnvironmentVariable::where('uuid', $request->env_uuid)->where('application_id', $application->id)->first(); $found_env = EnvironmentVariable::where('uuid', $request->env_uuid)->where('application_id', $application->id)->first();
if (! $found_env) { if (! $found_env) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Environment variable not found.', 'message' => 'Environment variable not found.',
], 404); ], 404);
} }
$found_env->forceDelete(); $found_env->forceDelete();
return response()->json([ return response()->json([
'success' => true,
'message' => 'Environment variable deleted.', 'message' => 'Environment variable deleted.',
]); ]);
} }
@ -1111,11 +1036,11 @@ public function action_deploy(Request $request)
$instant_deploy = $request->query->get('instant_deploy') ?? false; $instant_deploy = $request->query->get('instant_deploy') ?? false;
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first(); $application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first();
if (! $application) { if (! $application) {
return response()->json(['success' => false, 'message' => 'Application not found.'], 404); return response()->json(['message' => 'Application not found.'], 404);
} }
$deployment_uuid = new Cuid2(7); $deployment_uuid = new Cuid2(7);
@ -1130,7 +1055,6 @@ public function action_deploy(Request $request)
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Deployment request queued.', 'message' => 'Deployment request queued.',
'data' => [ 'data' => [
'deployment_uuid' => $deployment_uuid->toString(), 'deployment_uuid' => $deployment_uuid->toString(),
@ -1149,17 +1073,16 @@ public function action_stop(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first(); $application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first();
if (! $application) { if (! $application) {
return response()->json(['success' => false, 'message' => 'Application not found.'], 404); return response()->json(['message' => 'Application not found.'], 404);
} }
StopApplication::dispatch($application); StopApplication::dispatch($application);
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Application stopping request queued.', 'message' => 'Application stopping request queued.',
], ],
); );
@ -1173,11 +1096,11 @@ public function action_restart(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first(); $application = Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first();
if (! $application) { if (! $application) {
return response()->json(['success' => false, 'message' => 'Application not found.'], 404); return response()->json(['message' => 'Application not found.'], 404);
} }
$deployment_uuid = new Cuid2(7); $deployment_uuid = new Cuid2(7);
@ -1191,7 +1114,6 @@ public function action_restart(Request $request)
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Restart request queued.', 'message' => 'Restart request queued.',
'data' => [ 'data' => [
'deployment_uuid' => $deployment_uuid->toString(), 'deployment_uuid' => $deployment_uuid->toString(),
@ -1213,7 +1135,6 @@ private function validateDataApplications(Request $request, Server $server)
$port = explode(':', $portMapping); $port = explode(':', $portMapping);
if (in_array($port[0], $ports)) { if (in_array($port[0], $ports)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'ports_mappings' => 'The first number before : should be unique between mappings.', 'ports_mappings' => 'The first number before : should be unique between mappings.',
@ -1227,7 +1148,6 @@ private function validateDataApplications(Request $request, Server $server)
if ($request->has('custom_labels')) { if ($request->has('custom_labels')) {
if (! isBase64Encoded($request->custom_labels)) { if (! isBase64Encoded($request->custom_labels)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'custom_labels' => 'The custom_labels should be base64 encoded.', 'custom_labels' => 'The custom_labels should be base64 encoded.',
@ -1237,7 +1157,6 @@ private function validateDataApplications(Request $request, Server $server)
$customLabels = base64_decode($request->custom_labels); $customLabels = base64_decode($request->custom_labels);
if (mb_detect_encoding($customLabels, 'ASCII', true) === false) { if (mb_detect_encoding($customLabels, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'custom_labels' => 'The custom_labels should be base64 encoded.', 'custom_labels' => 'The custom_labels should be base64 encoded.',
@ -1260,14 +1179,12 @@ private function validateDataApplications(Request $request, Server $server)
}); });
if (count($errors) > 0) { if (count($errors) > 0) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
} }
if (checkIfDomainIsAlreadyUsed($fqdn, $teamId)) { if (checkIfDomainIsAlreadyUsed($fqdn, $teamId)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'domains' => 'One of the domain is already used.', 'domains' => 'One of the domain is already used.',

View File

@ -52,10 +52,7 @@ public function databases(Request $request)
return $this->removeSensitiveData($database); return $this->removeSensitiveData($database);
}); });
return response()->json([ return response()->json($databases);
'success' => true,
'data' => $databases,
]);
} }
public function database_by_uuid(Request $request) public function database_by_uuid(Request $request)
@ -65,17 +62,14 @@ public function database_by_uuid(Request $request)
return invalidTokenResponse(); return invalidTokenResponse();
} }
if (! $request->uuid) { if (! $request->uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 404); return response()->json(['message' => 'UUID is required.'], 404);
} }
$database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId); $database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId);
if (! $database) { if (! $database) {
return response()->json(['success' => false, 'message' => 'Database not found.'], 404); return response()->json(['message' => 'Database not found.'], 404);
} }
return response()->json([ return response()->json($this->removeSensitiveData($database));
'success' => true,
'data' => $this->removeSensitiveData($database),
]);
} }
public function update_by_uuid(Request $request) public function update_by_uuid(Request $request)
@ -141,7 +135,6 @@ public function update_by_uuid(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -150,11 +143,11 @@ public function update_by_uuid(Request $request)
removeUnnecessaryFieldsFromRequest($request); removeUnnecessaryFieldsFromRequest($request);
$database = queryDatabaseByUuidWithinTeam($uuid, $teamId); $database = queryDatabaseByUuidWithinTeam($uuid, $teamId);
if (! $database) { if (! $database) {
return response()->json(['success' => false, 'message' => 'Database not found.'], 404); return response()->json(['message' => 'Database not found.'], 404);
} }
if ($request->is_public && $request->public_port) { if ($request->is_public && $request->public_port) {
if (isPublicPortAlreadyUsed($database->destination->server, $request->public_port, $database->id)) { if (isPublicPortAlreadyUsed($database->destination->server, $request->public_port, $database->id)) {
return response()->json(['success' => false, 'message' => 'Public port already used by another database.'], 400); return response()->json(['message' => 'Public port already used by another database.'], 400);
} }
} }
@ -175,7 +168,6 @@ public function update_by_uuid(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database updated.', 'message' => 'Database updated.',
'data' => $this->removeSensitiveData($database), 'data' => $this->removeSensitiveData($database),
]); ]);
@ -252,7 +244,6 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -264,27 +255,27 @@ public function create_database(Request $request)
} }
$project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first(); $project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first();
if (! $project) { if (! $project) {
return response()->json(['succes' => false, 'message' => 'Project not found.'], 404); return response()->json(['message' => 'Project not found.'], 404);
} }
$environment = $project->environments()->where('name', $request->environment_name)->first(); $environment = $project->environments()->where('name', $request->environment_name)->first();
if (! $environment) { if (! $environment) {
return response()->json(['success' => false, 'message' => 'Environment not found.'], 404); return response()->json(['message' => 'Environment not found.'], 404);
} }
$server = Server::whereTeamId($teamId)->whereUuid($serverUuid)->first(); $server = Server::whereTeamId($teamId)->whereUuid($serverUuid)->first();
if (! $server) { if (! $server) {
return response()->json(['success' => false, 'message' => 'Server not found.'], 404); return response()->json(['message' => 'Server not found.'], 404);
} }
$destinations = $server->destinations(); $destinations = $server->destinations();
if ($destinations->count() == 0) { if ($destinations->count() == 0) {
return response()->json(['success' => false, 'message' => 'Server has no destinations.'], 400); return response()->json(['message' => 'Server has no destinations.'], 400);
} }
if ($destinations->count() > 1 && ! $request->has('destination_uuid')) { if ($destinations->count() > 1 && ! $request->has('destination_uuid')) {
return response()->json(['success' => false, 'message' => 'Server has multiple destinations and you do not set destination_uuid.'], 400); return response()->json(['message' => 'Server has multiple destinations and you do not set destination_uuid.'], 400);
} }
$destination = $destinations->first(); $destination = $destinations->first();
if ($request->has('public_port') && $request->is_public) { if ($request->has('public_port') && $request->is_public) {
if (isPublicPortAlreadyUsed($server, $request->public_port)) { if (isPublicPortAlreadyUsed($server, $request->public_port)) {
return response()->json(['success' => false, 'message' => 'Public port already used by another database.'], 400); return response()->json(['message' => 'Public port already used by another database.'], 400);
} }
} }
if ($request->type === NewDatabaseTypes::POSTGRESQL->value) { if ($request->type === NewDatabaseTypes::POSTGRESQL->value) {
@ -292,7 +283,6 @@ public function create_database(Request $request)
if ($request->has('postgres_conf')) { if ($request->has('postgres_conf')) {
if (! isBase64Encoded($request->postgres_conf)) { if (! isBase64Encoded($request->postgres_conf)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'postgres_conf' => 'The postgres_conf should be base64 encoded.', 'postgres_conf' => 'The postgres_conf should be base64 encoded.',
@ -302,7 +292,6 @@ public function create_database(Request $request)
$postgresConf = base64_decode($request->postgres_conf); $postgresConf = base64_decode($request->postgres_conf);
if (mb_detect_encoding($postgresConf, 'ASCII', true) === false) { if (mb_detect_encoding($postgresConf, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'postgres_conf' => 'The postgres_conf should be base64 encoded.', 'postgres_conf' => 'The postgres_conf should be base64 encoded.',
@ -320,7 +309,6 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database starting queued.', 'message' => 'Database starting queued.',
'data' => serializeApiResponse($database), 'data' => serializeApiResponse($database),
]); ]);
@ -329,7 +317,6 @@ public function create_database(Request $request)
if ($request->has('mariadb_conf')) { if ($request->has('mariadb_conf')) {
if (! isBase64Encoded($request->mariadb_conf)) { if (! isBase64Encoded($request->mariadb_conf)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'mariadb_conf' => 'The mariadb_conf should be base64 encoded.', 'mariadb_conf' => 'The mariadb_conf should be base64 encoded.',
@ -339,7 +326,6 @@ public function create_database(Request $request)
$mariadbConf = base64_decode($request->mariadb_conf); $mariadbConf = base64_decode($request->mariadb_conf);
if (mb_detect_encoding($mariadbConf, 'ASCII', true) === false) { if (mb_detect_encoding($mariadbConf, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'mariadb_conf' => 'The mariadb_conf should be base64 encoded.', 'mariadb_conf' => 'The mariadb_conf should be base64 encoded.',
@ -357,7 +343,6 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database starting queued.', 'message' => 'Database starting queued.',
'data' => serializeApiResponse($database), 'data' => serializeApiResponse($database),
]); ]);
@ -366,7 +351,6 @@ public function create_database(Request $request)
if ($request->has('mysql_conf')) { if ($request->has('mysql_conf')) {
if (! isBase64Encoded($request->mysql_conf)) { if (! isBase64Encoded($request->mysql_conf)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'mysql_conf' => 'The mysql_conf should be base64 encoded.', 'mysql_conf' => 'The mysql_conf should be base64 encoded.',
@ -376,7 +360,6 @@ public function create_database(Request $request)
$mysqlConf = base64_decode($request->mysql_conf); $mysqlConf = base64_decode($request->mysql_conf);
if (mb_detect_encoding($mysqlConf, 'ASCII', true) === false) { if (mb_detect_encoding($mysqlConf, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'mysql_conf' => 'The mysql_conf should be base64 encoded.', 'mysql_conf' => 'The mysql_conf should be base64 encoded.',
@ -403,7 +386,6 @@ public function create_database(Request $request)
if ($request->has('redis_conf')) { if ($request->has('redis_conf')) {
if (! isBase64Encoded($request->redis_conf)) { if (! isBase64Encoded($request->redis_conf)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'redis_conf' => 'The redis_conf should be base64 encoded.', 'redis_conf' => 'The redis_conf should be base64 encoded.',
@ -413,7 +395,6 @@ public function create_database(Request $request)
$redisConf = base64_decode($request->redis_conf); $redisConf = base64_decode($request->redis_conf);
if (mb_detect_encoding($redisConf, 'ASCII', true) === false) { if (mb_detect_encoding($redisConf, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'redis_conf' => 'The redis_conf should be base64 encoded.', 'redis_conf' => 'The redis_conf should be base64 encoded.',
@ -431,7 +412,6 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database starting queued.', 'message' => 'Database starting queued.',
'data' => serializeApiResponse($database), 'data' => serializeApiResponse($database),
]); ]);
@ -446,7 +426,6 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database starting queued.', 'message' => 'Database starting queued.',
'data' => serializeApiResponse($database), 'data' => serializeApiResponse($database),
]); ]);
@ -455,7 +434,6 @@ public function create_database(Request $request)
if ($request->has('keydb_conf')) { if ($request->has('keydb_conf')) {
if (! isBase64Encoded($request->keydb_conf)) { if (! isBase64Encoded($request->keydb_conf)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'keydb_conf' => 'The keydb_conf should be base64 encoded.', 'keydb_conf' => 'The keydb_conf should be base64 encoded.',
@ -465,7 +443,6 @@ public function create_database(Request $request)
$keydbConf = base64_decode($request->keydb_conf); $keydbConf = base64_decode($request->keydb_conf);
if (mb_detect_encoding($keydbConf, 'ASCII', true) === false) { if (mb_detect_encoding($keydbConf, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'keydb_conf' => 'The keydb_conf should be base64 encoded.', 'keydb_conf' => 'The keydb_conf should be base64 encoded.',
@ -483,7 +460,6 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database starting queued.', 'message' => 'Database starting queued.',
'data' => serializeApiResponse($database), 'data' => serializeApiResponse($database),
]); ]);
@ -498,7 +474,6 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database starting queued.', 'message' => 'Database starting queued.',
'data' => serializeApiResponse($database), 'data' => serializeApiResponse($database),
]); ]);
@ -507,7 +482,6 @@ public function create_database(Request $request)
if ($request->has('mongo_conf')) { if ($request->has('mongo_conf')) {
if (! isBase64Encoded($request->mongo_conf)) { if (! isBase64Encoded($request->mongo_conf)) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'mongo_conf' => 'The mongo_conf should be base64 encoded.', 'mongo_conf' => 'The mongo_conf should be base64 encoded.',
@ -517,7 +491,6 @@ public function create_database(Request $request)
$mongoConf = base64_decode($request->mongo_conf); $mongoConf = base64_decode($request->mongo_conf);
if (mb_detect_encoding($mongoConf, 'ASCII', true) === false) { if (mb_detect_encoding($mongoConf, 'ASCII', true) === false) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => [ 'errors' => [
'mongo_conf' => 'The mongo_conf should be base64 encoded.', 'mongo_conf' => 'The mongo_conf should be base64 encoded.',
@ -535,13 +508,12 @@ public function create_database(Request $request)
} }
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database starting queued.', 'message' => 'Database starting queued.',
'data' => serializeApiResponse($database), 'data' => serializeApiResponse($database),
]); ]);
} }
return response()->json(['success' => false, 'message' => 'Invalid database type requested.'], 400); return response()->json(['message' => 'Invalid database type requested.'], 400);
} }
public function delete_by_uuid(Request $request) public function delete_by_uuid(Request $request)
@ -551,17 +523,16 @@ public function delete_by_uuid(Request $request)
return invalidTokenResponse(); return invalidTokenResponse();
} }
if (! $request->uuid) { if (! $request->uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 404); return response()->json(['message' => 'UUID is required.'], 404);
} }
$database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId); $database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId);
if (! $database) { if (! $database) {
return response()->json(['success' => false, 'message' => 'Database not found.'], 404); return response()->json(['message' => 'Database not found.'], 404);
} }
StopDatabase::dispatch($database); StopDatabase::dispatch($database);
$database->forceDelete(); $database->forceDelete();
return response()->json([ return response()->json([
'success' => true,
'message' => 'Database deletion request queued.', 'message' => 'Database deletion request queued.',
]); ]);
} }
@ -574,20 +545,19 @@ public function action_deploy(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId); $database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId);
if (! $database) { if (! $database) {
return response()->json(['success' => false, 'message' => 'Database not found.'], 404); return response()->json(['message' => 'Database not found.'], 404);
} }
if (str($database->status)->contains('running')) { if (str($database->status)->contains('running')) {
return response()->json(['success' => false, 'message' => 'Database is already running.'], 400); return response()->json(['message' => 'Database is already running.'], 400);
} }
StartDatabase::dispatch($database); StartDatabase::dispatch($database);
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Database starting request queued.', 'message' => 'Database starting request queued.',
], ],
200 200
@ -602,20 +572,19 @@ public function action_stop(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId); $database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId);
if (! $database) { if (! $database) {
return response()->json(['success' => false, 'message' => 'Database not found.'], 404); return response()->json(['message' => 'Database not found.'], 404);
} }
if (str($database->status)->contains('stopped') || str($database->status)->contains('exited')) { if (str($database->status)->contains('stopped') || str($database->status)->contains('exited')) {
return response()->json(['success' => false, 'message' => 'Database is already stopped.'], 400); return response()->json(['message' => 'Database is already stopped.'], 400);
} }
StopDatabase::dispatch($database); StopDatabase::dispatch($database);
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Database stopping request queued.', 'message' => 'Database stopping request queued.',
], ],
200 200
@ -630,17 +599,16 @@ public function action_restart(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId); $database = queryDatabaseByUuidWithinTeam($request->uuid, $teamId);
if (! $database) { if (! $database) {
return response()->json(['success' => false, 'message' => 'Database not found.'], 404); return response()->json(['message' => 'Database not found.'], 404);
} }
RestartDatabase::dispatch($database); RestartDatabase::dispatch($database);
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Database restarting request queued.', 'message' => 'Database restarting request queued.',
], ],
200 200

View File

@ -45,10 +45,7 @@ public function deployments(Request $request)
'status', 'status',
])->sortBy('id')->toArray(); ])->sortBy('id')->toArray();
return response()->json([ return response()->json(serializeApiResponse($deployments_per_server));
'success' => true,
'data' => serializeApiResponse($deployments_per_server),
]);
} }
public function deployment_by_uuid(Request $request) public function deployment_by_uuid(Request $request)
@ -59,17 +56,14 @@ public function deployment_by_uuid(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$deployment = ApplicationDeploymentQueue::where('deployment_uuid', $uuid)->first(); $deployment = ApplicationDeploymentQueue::where('deployment_uuid', $uuid)->first();
if (! $deployment) { if (! $deployment) {
return response()->json(['success' => false, 'message' => 'Deployment not found.'], 404); return response()->json(['message' => 'Deployment not found.'], 404);
} }
return response()->json([ return response()->json($this->removeSensitiveData($deployment));
'success' => true,
'data' => $this->removeSensitiveData($deployment),
]);
} }
public function deploy(Request $request) public function deploy(Request $request)
@ -80,7 +74,7 @@ public function deploy(Request $request)
$force = $request->query->get('force') ?? false; $force = $request->query->get('force') ?? false;
if ($uuids && $tags) { if ($uuids && $tags) {
return response()->json(['success' => false, 'message' => 'You can only use uuid or tag, not both.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400); return response()->json(['message' => 'You can only use uuid or tag, not both.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400);
} }
if (is_null($teamId)) { if (is_null($teamId)) {
return invalidTokenResponse(); return invalidTokenResponse();
@ -91,7 +85,7 @@ public function deploy(Request $request)
return $this->by_uuids($uuids, $teamId, $force); return $this->by_uuids($uuids, $teamId, $force);
} }
return response()->json(['success' => false, 'message' => 'You must provide uuid or tag.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400); return response()->json(['message' => 'You must provide uuid or tag.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400);
} }
private function by_uuids(string $uuid, int $teamId, bool $force = false) private function by_uuids(string $uuid, int $teamId, bool $force = false)
@ -100,7 +94,7 @@ private function by_uuids(string $uuid, int $teamId, bool $force = false)
$uuids = collect(array_filter($uuids)); $uuids = collect(array_filter($uuids));
if (count($uuids) === 0) { if (count($uuids) === 0) {
return response()->json(['success' => false, 'message' => 'No UUIDs provided.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400); return response()->json(['message' => 'No UUIDs provided.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400);
} }
$deployments = collect(); $deployments = collect();
$payload = collect(); $payload = collect();
@ -109,22 +103,19 @@ private function by_uuids(string $uuid, int $teamId, bool $force = false)
if ($resource) { if ($resource) {
['message' => $return_message, 'deployment_uuid' => $deployment_uuid] = $this->deploy_resource($resource, $force); ['message' => $return_message, 'deployment_uuid' => $deployment_uuid] = $this->deploy_resource($resource, $force);
if ($deployment_uuid) { if ($deployment_uuid) {
$deployments->push(['success' => true, 'message' => $return_message, 'resource_uuid' => $uuid, 'deployment_uuid' => $deployment_uuid->toString()]); $deployments->push(['message' => $return_message, 'resource_uuid' => $uuid, 'deployment_uuid' => $deployment_uuid->toString()]);
} else { } else {
$deployments->push(['success' => true, 'message' => $return_message, 'resource_uuid' => $uuid]); $deployments->push(['message' => $return_message, 'resource_uuid' => $uuid]);
} }
} }
} }
if ($deployments->count() > 0) { if ($deployments->count() > 0) {
$payload->put('deployments', $deployments->toArray()); $payload->put('deployments', $deployments->toArray());
return response()->json([ return response()->json(serializeApiResponse($payload->toArray()));
'success' => true,
'data' => serializeApiResponse($payload->toArray()),
]);
} }
return response()->json(['success' => false, 'message' => 'No resources found.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 404); return response()->json(['message' => 'No resources found.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 404);
} }
public function by_tags(string $tags, int $team_id, bool $force = false) public function by_tags(string $tags, int $team_id, bool $force = false)
@ -133,7 +124,7 @@ public function by_tags(string $tags, int $team_id, bool $force = false)
$tags = collect(array_filter($tags)); $tags = collect(array_filter($tags));
if (count($tags) === 0) { if (count($tags) === 0) {
return response()->json(['success' => false, 'message' => 'No TAGs provided.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400); return response()->json(['message' => 'No TAGs provided.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 400);
} }
$message = collect([]); $message = collect([]);
$deployments = collect(); $deployments = collect();
@ -169,13 +160,10 @@ public function by_tags(string $tags, int $team_id, bool $force = false)
$payload->put('details', $deployments->toArray()); $payload->put('details', $deployments->toArray());
} }
return response()->json([ return response()->json(serializeApiResponse($payload->toArray()));
'success' => true,
'data' => serializeApiResponse($payload->toArray()),
]);
} }
return response()->json(['success' => false, 'message' => 'No resources found with this tag.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 404); return response()->json(['message' => 'No resources found with this tag.', 'docs' => 'https://coolify.io/docs/api-reference/deploy-webhook'], 404);
} }
public function deploy_resource($resource, bool $force = false): array public function deploy_resource($resource, bool $force = false): array
@ -183,7 +171,7 @@ public function deploy_resource($resource, bool $force = false): array
$message = null; $message = null;
$deployment_uuid = null; $deployment_uuid = null;
if (gettype($resource) !== 'object') { if (gettype($resource) !== 'object') {
return ['success' => false, 'message' => "Resource ($resource) not found.", 'deployment_uuid' => $deployment_uuid]; return ['message' => "Resource ($resource) not found.", 'deployment_uuid' => $deployment_uuid];
} }
switch ($resource?->getMorphClass()) { switch ($resource?->getMorphClass()) {
case 'App\Models\Application': case 'App\Models\Application':
@ -209,6 +197,6 @@ public function deploy_resource($resource, bool $force = false): array
break; break;
} }
return ['success' => true, 'message' => $message, 'deployment_uuid' => $deployment_uuid]; return ['message' => $message, 'deployment_uuid' => $deployment_uuid];
} }
} }

View File

@ -17,21 +17,18 @@ public function delete_env_by_uuid(Request $request)
$env = EnvironmentVariable::where('uuid', $request->env_uuid)->first(); $env = EnvironmentVariable::where('uuid', $request->env_uuid)->first();
if (! $env) { if (! $env) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Environment variable not found.', 'message' => 'Environment variable not found.',
], 404); ], 404);
} }
$found_app = $env->resource()->whereRelation('environment.project.team', 'id', $teamId)->first(); $found_app = $env->resource()->whereRelation('environment.project.team', 'id', $teamId)->first();
if (! $found_app) { if (! $found_app) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Environment variable not found.', 'message' => 'Environment variable not found.',
], 404); ], 404);
} }
$env->delete(); $env->delete();
return response()->json([ return response()->json([
'success' => true,
'message' => 'Environment variable deleted.', 'message' => 'Environment variable deleted.',
]); ]);
} }

View File

@ -16,10 +16,8 @@ public function projects(Request $request)
} }
$projects = Project::whereTeamId($teamId)->select('id', 'name', 'uuid')->get(); $projects = Project::whereTeamId($teamId)->select('id', 'name', 'uuid')->get();
return response()->json([ return response()->json(serializeApiResponse($projects),
'success' => true, );
'data' => serializeApiResponse($projects),
]);
} }
public function project_by_uuid(Request $request) public function project_by_uuid(Request $request)
@ -30,13 +28,12 @@ public function project_by_uuid(Request $request)
} }
$project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first()->load(['environments']); $project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first()->load(['environments']);
if (! $project) { if (! $project) {
return response()->json(['success' => false, 'message' => 'Project not found.'], 404); return response()->json(['message' => 'Project not found.'], 404);
} }
return response()->json([ return response()->json(
'success' => true, serializeApiResponse($project),
'data' => serializeApiResponse($project), );
]);
} }
public function environment_details(Request $request) public function environment_details(Request $request)
@ -48,13 +45,10 @@ public function environment_details(Request $request)
$project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first(); $project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first();
$environment = $project->environments()->whereName(request()->environment_name)->first(); $environment = $project->environments()->whereName(request()->environment_name)->first();
if (! $environment) { if (! $environment) {
return response()->json(['success' => false, 'message' => 'Environment not found.'], 404); return response()->json(['message' => 'Environment not found.'], 404);
} }
$environment = $environment->load(['applications', 'postgresqls', 'redis', 'mongodbs', 'mysqls', 'mariadbs', 'services']); $environment = $environment->load(['applications', 'postgresqls', 'redis', 'mongodbs', 'mysqls', 'mariadbs', 'services']);
return response()->json([ return response()->json(serializeApiResponse($environment));
'success' => true,
'data' => serializeApiResponse($environment),
]);
} }
} }

View File

@ -34,9 +34,6 @@ public function resources(Request $request)
return $payload; return $payload;
}); });
return response()->json([ return response()->json(serializeApiResponse($resources));
'success' => true,
'data' => serializeApiResponse($resources),
]);
} }
} }

View File

@ -16,10 +16,7 @@ public function keys(Request $request)
} }
$keys = PrivateKey::where('team_id', $teamId)->get(); $keys = PrivateKey::where('team_id', $teamId)->get();
return response()->json([ return response()->json(serializeApiResponse($keys));
'success' => true,
'data' => serializeApiResponse($keys),
]);
} }
public function key_by_uuid(Request $request) public function key_by_uuid(Request $request)
@ -33,15 +30,11 @@ public function key_by_uuid(Request $request)
if (is_null($key)) { if (is_null($key)) {
return response()->json([ return response()->json([
'success' => false, 'message' => 'Private Key not found.',
'message' => 'Key not found.',
], 404); ], 404);
} }
return response()->json([ return response()->json(serializeApiResponse($key));
'success' => true,
'data' => serializeApiResponse($key),
]);
} }
public function create_key(Request $request) public function create_key(Request $request)
@ -64,7 +57,6 @@ public function create_key(Request $request)
$errors = $validator->errors(); $errors = $validator->errors();
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -82,10 +74,9 @@ public function create_key(Request $request)
'private_key' => $request->private_key, 'private_key' => $request->private_key,
]); ]);
return response()->json([ return response()->json(serializeApiResponse([
'success' => true, 'uuid' => $key->uuid,
'data' => serializeApiResponse($key), ]))->setStatusCode(201);
]);
} }
public function update_key(Request $request) public function update_key(Request $request)
@ -116,7 +107,6 @@ public function update_key(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -124,16 +114,14 @@ public function update_key(Request $request)
$foundKey = PrivateKey::where('team_id', $teamId)->where('uuid', $request->uuid)->first(); $foundKey = PrivateKey::where('team_id', $teamId)->where('uuid', $request->uuid)->first();
if (is_null($foundKey)) { if (is_null($foundKey)) {
return response()->json([ return response()->json([
'success' => false, 'message' => 'Private Key not found.',
'message' => 'Key not found.',
], 404); ], 404);
} }
$foundKey->update($request->all()); $foundKey->update($request->all());
return response()->json([ return response()->json(serializeApiResponse([
'success' => true, 'uuid' => $foundKey->uuid,
'data' => serializeApiResponse($foundKey), ]))->setStatusCode(201);
])->setStatusCode(201);
} }
public function delete_key(Request $request) public function delete_key(Request $request)
@ -143,18 +131,17 @@ public function delete_key(Request $request)
return invalidTokenResponse(); return invalidTokenResponse();
} }
if (! $request->uuid) { if (! $request->uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 422); return response()->json(['message' => 'UUID is required.'], 422);
} }
$key = PrivateKey::where('team_id', $teamId)->where('uuid', $request->uuid)->first(); $key = PrivateKey::where('team_id', $teamId)->where('uuid', $request->uuid)->first();
if (is_null($key)) { if (is_null($key)) {
return response()->json(['success' => false, 'message' => 'Key not found.'], 404); return response()->json(['message' => 'Private Key not found.'], 404);
} }
$key->forceDelete(); $key->forceDelete();
return response()->json([ return response()->json([
'success' => true, 'message' => 'Private Key deleted.',
'message' => 'Key deleted.',
]); ]);
} }
} }

View File

@ -12,6 +12,29 @@
class ServersController extends Controller class ServersController extends Controller
{ {
private function removeSensitiveDataFromSettings($settings)
{
$token = auth()->user()->currentAccessToken();
if ($token->can('view:sensitive')) {
return serializeApiResponse($settings);
}
$settings = $settings->makeHidden([
'metrics_token',
]);
return serializeApiResponse($settings);
}
private function removeSensitiveData($server)
{
$token = auth()->user()->currentAccessToken();
if ($token->can('view:sensitive')) {
return serializeApiResponse($server);
}
return serializeApiResponse($server);
}
public function servers(Request $request) public function servers(Request $request)
{ {
$teamId = getTeamIdFromToken(); $teamId = getTeamIdFromToken();
@ -25,13 +48,14 @@ public function servers(Request $request)
return $server; return $server;
}); });
$servers = $servers->map(function ($server) { $servers = $servers->map(function ($server) {
return serializeApiResponse($server); $settings = $this->removeSensitiveDataFromSettings($server->settings);
$server = $this->removeSensitiveData($server);
data_set($server, 'settings', $settings);
return $server;
}); });
return response()->json([ return response()->json($servers);
'success' => true,
'data' => $servers,
]);
} }
public function server_by_uuid(Request $request) public function server_by_uuid(Request $request)
@ -67,13 +91,47 @@ public function server_by_uuid(Request $request)
$server->load(['settings']); $server->load(['settings']);
} }
return response()->json([ $settings = $this->removeSensitiveDataFromSettings($server->settings);
'success' => true, $server = $this->removeSensitiveData($server);
'data' => serializeApiResponse($server), data_set($server, 'settings', $settings);
]);
return response()->json(serializeApiResponse($server));
} }
public function get_domains_by_server(Request $request) public function resources_by_server(Request $request)
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
$server = ModelsServer::whereTeamId($teamId)->whereUuid(request()->uuid)->first();
if (is_null($server)) {
return response()->json(['message' => 'Server not found.'], 404);
}
$server['resources'] = $server->definedResources()->map(function ($resource) {
$payload = [
'id' => $resource->id,
'uuid' => $resource->uuid,
'name' => $resource->name,
'type' => $resource->type(),
'created_at' => $resource->created_at,
'updated_at' => $resource->updated_at,
];
if ($resource->type() === 'service') {
$payload['status'] = $resource->status();
} else {
$payload['status'] = $resource->status;
}
return $payload;
});
$server = $this->removeSensitiveData($server);
ray($server);
return response()->json(serializeApiResponse(data_get($server, 'resources')));
}
public function domains_by_server(Request $request)
{ {
$teamId = getTeamIdFromToken(); $teamId = getTeamIdFromToken();
if (is_null($teamId)) { if (is_null($teamId)) {
@ -83,10 +141,7 @@ public function get_domains_by_server(Request $request)
if ($uuid) { if ($uuid) {
$domains = Application::getDomainsByUuid($uuid); $domains = Application::getDomainsByUuid($uuid);
return response()->json([ return response()->json(serializeApiResponse($domains));
'success' => true,
'data' => serializeApiResponse($domains),
]);
} }
$projects = Project::where('team_id', $teamId)->get(); $projects = Project::where('team_id', $teamId)->get();
$domains = collect(); $domains = collect();
@ -181,9 +236,6 @@ public function get_domains_by_server(Request $request)
]; ];
})->values(); })->values();
return response()->json([ return response()->json(serializeApiResponse($domains));
'success' => true,
'data' => serializeApiResponse($domains),
]);
} }
} }

View File

@ -45,10 +45,7 @@ public function services(Request $request)
$service = $this->removeSensitiveData($service); $service = $this->removeSensitiveData($service);
} }
return response()->json([ return response()->json($services);
'success' => true,
'data' => $services,
]);
} }
public function create_service(Request $request) public function create_service(Request $request)
@ -85,7 +82,6 @@ public function create_service(Request $request)
} }
return response()->json([ return response()->json([
'success' => false,
'message' => 'Validation failed.', 'message' => 'Validation failed.',
'errors' => $errors, 'errors' => $errors,
], 422); ], 422);
@ -97,22 +93,22 @@ public function create_service(Request $request)
} }
$project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first(); $project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first();
if (! $project) { if (! $project) {
return response()->json(['succes' => false, 'message' => 'Project not found.'], 404); return response()->json(['message' => 'Project not found.'], 404);
} }
$environment = $project->environments()->where('name', $request->environment_name)->first(); $environment = $project->environments()->where('name', $request->environment_name)->first();
if (! $environment) { if (! $environment) {
return response()->json(['success' => false, 'message' => 'Environment not found.'], 404); return response()->json(['message' => 'Environment not found.'], 404);
} }
$server = Server::whereTeamId($teamId)->whereUuid($serverUuid)->first(); $server = Server::whereTeamId($teamId)->whereUuid($serverUuid)->first();
if (! $server) { if (! $server) {
return response()->json(['success' => false, 'message' => 'Server not found.'], 404); return response()->json(['message' => 'Server not found.'], 404);
} }
$destinations = $server->destinations(); $destinations = $server->destinations();
if ($destinations->count() == 0) { if ($destinations->count() == 0) {
return response()->json(['success' => false, 'message' => 'Server has no destinations.'], 400); return response()->json(['message' => 'Server has no destinations.'], 400);
} }
if ($destinations->count() > 1 && ! $request->has('destination_uuid')) { if ($destinations->count() > 1 && ! $request->has('destination_uuid')) {
return response()->json(['success' => false, 'message' => 'Server has multiple destinations and you do not set destination_uuid.'], 400); return response()->json(['message' => 'Server has multiple destinations and you do not set destination_uuid.'], 400);
} }
$destination = $destinations->first(); $destination = $destinations->first();
$services = get_service_templates(); $services = get_service_templates();
@ -170,7 +166,6 @@ public function create_service(Request $request)
}); });
return response()->json([ return response()->json([
'success' => true,
'message' => 'Service created.', 'message' => 'Service created.',
'data' => $this->removeSensitiveData([ 'data' => $this->removeSensitiveData([
'id' => $service->id, 'id' => $service->id,
@ -181,12 +176,12 @@ public function create_service(Request $request)
]); ]);
} }
return response()->json(['success' => false, 'message' => 'Service not found.'], 404); return response()->json(['message' => 'Service not found.'], 404);
} else { } else {
return response()->json(['success' => false, 'message' => 'Invalid service type.', 'valid_service_types' => $serviceKeys], 400); return response()->json(['message' => 'Invalid service type.', 'valid_service_types' => $serviceKeys], 400);
} }
return response()->json(['success' => false, 'message' => 'Invalid service type.'], 400); return response()->json(['message' => 'Invalid service type.'], 400);
} }
public function service_by_uuid(Request $request) public function service_by_uuid(Request $request)
@ -196,17 +191,14 @@ public function service_by_uuid(Request $request)
return invalidTokenResponse(); return invalidTokenResponse();
} }
if (! $request->uuid) { if (! $request->uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 404); return response()->json(['message' => 'UUID is required.'], 404);
} }
$service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first(); $service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first();
if (! $service) { if (! $service) {
return response()->json(['success' => false, 'message' => 'Service not found.'], 404); return response()->json(['message' => 'Service not found.'], 404);
} }
return response()->json([ return response()->json($this->removeSensitiveData($service));
'success' => true,
'data' => $this->removeSensitiveData($service),
]);
} }
public function delete_by_uuid(Request $request) public function delete_by_uuid(Request $request)
@ -216,16 +208,15 @@ public function delete_by_uuid(Request $request)
return invalidTokenResponse(); return invalidTokenResponse();
} }
if (! $request->uuid) { if (! $request->uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 404); return response()->json(['message' => 'UUID is required.'], 404);
} }
$service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first(); $service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first();
if (! $service) { if (! $service) {
return response()->json(['success' => false, 'message' => 'Service not found.'], 404); return response()->json(['message' => 'Service not found.'], 404);
} }
DeleteResourceJob::dispatch($service); DeleteResourceJob::dispatch($service);
return response()->json([ return response()->json([
'success' => true,
'message' => 'Service deletion request queued.', 'message' => 'Service deletion request queued.',
]); ]);
} }
@ -238,20 +229,19 @@ public function action_deploy(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first(); $service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first();
if (! $service) { if (! $service) {
return response()->json(['success' => false, 'message' => 'Service not found.'], 404); return response()->json(['message' => 'Service not found.'], 404);
} }
if (str($service->status())->contains('running')) { if (str($service->status())->contains('running')) {
return response()->json(['success' => false, 'message' => 'Service is already running.'], 400); return response()->json(['message' => 'Service is already running.'], 400);
} }
StartService::dispatch($service); StartService::dispatch($service);
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Service starting request queued.', 'message' => 'Service starting request queued.',
], ],
200 200
@ -266,20 +256,19 @@ public function action_stop(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first(); $service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first();
if (! $service) { if (! $service) {
return response()->json(['success' => false, 'message' => 'Service not found.'], 404); return response()->json(['message' => 'Service not found.'], 404);
} }
if (str($service->status())->contains('stopped') || str($service->status())->contains('exited')) { if (str($service->status())->contains('stopped') || str($service->status())->contains('exited')) {
return response()->json(['success' => false, 'message' => 'Service is already stopped.'], 400); return response()->json(['message' => 'Service is already stopped.'], 400);
} }
StopService::dispatch($service); StopService::dispatch($service);
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Service stopping request queued.', 'message' => 'Service stopping request queued.',
], ],
200 200
@ -294,17 +283,16 @@ public function action_restart(Request $request)
} }
$uuid = $request->route('uuid'); $uuid = $request->route('uuid');
if (! $uuid) { if (! $uuid) {
return response()->json(['success' => false, 'message' => 'UUID is required.'], 400); return response()->json(['message' => 'UUID is required.'], 400);
} }
$service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first(); $service = Service::whereRelation('environment.project.team', 'id', $teamId)->whereUuid($request->uuid)->first();
if (! $service) { if (! $service) {
return response()->json(['success' => false, 'message' => 'Service not found.'], 404); return response()->json(['message' => 'Service not found.'], 404);
} }
RestartService::dispatch($service); RestartService::dispatch($service);
return response()->json( return response()->json(
[ [
'success' => true,
'message' => 'Service restarting request queued.', 'message' => 'Service restarting request queued.',
], ],
200 200

View File

@ -10,6 +10,10 @@ class TeamController extends Controller
private function removeSensitiveData($team) private function removeSensitiveData($team)
{ {
$token = auth()->user()->currentAccessToken(); $token = auth()->user()->currentAccessToken();
$team->makeHidden([
'custom_server_limit',
'pivot',
]);
if ($token->can('view:sensitive')) { if ($token->can('view:sensitive')) {
return serializeApiResponse($team); return serializeApiResponse($team);
} }
@ -34,10 +38,9 @@ public function teams(Request $request)
return $this->removeSensitiveData($team); return $this->removeSensitiveData($team);
}); });
return response()->json([ return response()->json(
'success' => true, $teams,
'data' => $teams, );
]);
} }
public function team_by_id(Request $request) public function team_by_id(Request $request)
@ -50,14 +53,13 @@ public function team_by_id(Request $request)
$teams = auth()->user()->teams; $teams = auth()->user()->teams;
$team = $teams->where('id', $id)->first(); $team = $teams->where('id', $id)->first();
if (is_null($team)) { if (is_null($team)) {
return response()->json(['success' => false, 'message' => 'Team not found.', 'docs' => 'https://coolify.io/docs/api-reference/get-team-by-teamid'], 404); return response()->json(['message' => 'Team not found.', 'docs' => 'https://coolify.io/docs/api-reference/get-team-by-teamid'], 404);
} }
$team = $this->removeSensitiveData($team); $team = $this->removeSensitiveData($team);
return response()->json([ return response()->json(
'success' => true, serializeApiResponse($team),
'data' => serializeApiResponse($team), );
]);
} }
public function members_by_id(Request $request) public function members_by_id(Request $request)
@ -70,14 +72,16 @@ public function members_by_id(Request $request)
$teams = auth()->user()->teams; $teams = auth()->user()->teams;
$team = $teams->where('id', $id)->first(); $team = $teams->where('id', $id)->first();
if (is_null($team)) { if (is_null($team)) {
return response()->json(['success' => false, 'message' => 'Team not found.', 'docs' => 'https://coolify.io/docs/api-reference/get-team-by-teamid-members'], 404); return response()->json(['message' => 'Team not found.', 'docs' => 'https://coolify.io/docs/api-reference/get-team-by-teamid-members'], 404);
} }
$members = $team->members; $members = $team->members;
$members->makeHidden([
return response()->json([ 'pivot',
'success' => true,
'data' => serializeApiResponse($members),
]); ]);
return response()->json(
serializeApiResponse($members),
);
} }
public function current_team(Request $request) public function current_team(Request $request)
@ -88,10 +92,9 @@ public function current_team(Request $request)
} }
$team = auth()->user()->currentTeam(); $team = auth()->user()->currentTeam();
return response()->json([ return response()->json(
'success' => true, serializeApiResponse($team),
'data' => serializeApiResponse($team), );
]);
} }
public function current_team_members(Request $request) public function current_team_members(Request $request)
@ -102,9 +105,8 @@ public function current_team_members(Request $request)
} }
$team = auth()->user()->currentTeam(); $team = auth()->user()->currentTeam();
return response()->json([ return response()->json(
'success' => true, serializeApiResponse($team->members),
'data' => serializeApiResponse($team->members), );
]);
} }
} }

View File

@ -20,7 +20,7 @@ public function handle(Request $request, Closure $next): Response
return $next($request); return $next($request);
} }
if ($token->can('read-only')) { if ($token->can('read-only')) {
return response()->json(['success' => false, 'message' => 'You are not allowed to perform this action.'], 403); return response()->json(['message' => 'You are not allowed to perform this action.'], 403);
} }
return $next($request); return $next($request);

View File

@ -20,6 +20,6 @@ public function handle(Request $request, Closure $next): Response
return $next($request); return $next($request);
} }
return response()->json(['success' => false, 'message' => 'You are not allowed to perform this action.'], 403); return response()->json(['message' => 'You are not allowed to perform this action.'], 403);
} }
} }

View File

@ -14,7 +14,7 @@ function getTeamIdFromToken()
} }
function invalidTokenResponse() function invalidTokenResponse()
{ {
return response()->json(['success' => false, 'message' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api-reference/authorization'], 400); return response()->json(['message' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api-reference/authorization'], 400);
} }
function serializeApiResponse($data) function serializeApiResponse($data)
@ -138,7 +138,6 @@ function validateIncomingRequest(Request $request)
// check if request is json // check if request is json
if (! $request->isJson()) { if (! $request->isJson()) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Invalid request.', 'message' => 'Invalid request.',
'error' => 'Content-Type must be application/json.', 'error' => 'Content-Type must be application/json.',
], 400); ], 400);
@ -146,7 +145,6 @@ function validateIncomingRequest(Request $request)
// check if request is valid json // check if request is valid json
if (! json_decode($request->getContent())) { if (! json_decode($request->getContent())) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Invalid request.', 'message' => 'Invalid request.',
'error' => 'Invalid JSON.', 'error' => 'Invalid JSON.',
], 400); ], 400);
@ -154,7 +152,6 @@ function validateIncomingRequest(Request $request)
// check if valid json is empty // check if valid json is empty
if (empty($request->json()->all())) { if (empty($request->json()->all())) {
return response()->json([ return response()->json([
'success' => false,
'message' => 'Invalid request.', 'message' => 'Invalid request.',
'error' => 'Empty JSON.', 'error' => 'Empty JSON.',
], 400); ], 400);

View File

@ -43,7 +43,7 @@
return invalidTokenResponse(); return invalidTokenResponse();
} }
if ($teamId !== '0') { if ($teamId !== '0') {
return response()->json(['success' => false, 'message' => 'You are not allowed to enable the API.'], 403); return response()->json(['message' => 'You are not allowed to enable the API.'], 403);
} }
$settings = InstanceSettings::get(); $settings = InstanceSettings::get();
$settings->update(['is_api_enabled' => true]); $settings->update(['is_api_enabled' => true]);
@ -56,7 +56,7 @@
return invalidTokenResponse(); return invalidTokenResponse();
} }
if ($teamId !== '0') { if ($teamId !== '0') {
return response()->json(['success' => false, 'message' => 'You are not allowed to disable the API.'], 403); return response()->json(['message' => 'You are not allowed to disable the API.'], 403);
} }
$settings = InstanceSettings::get(); $settings = InstanceSettings::get();
$settings->update(['is_api_enabled' => false]); $settings->update(['is_api_enabled' => false]);
@ -97,7 +97,8 @@
Route::get('/servers', [ServersController::class, 'servers']); Route::get('/servers', [ServersController::class, 'servers']);
Route::get('/servers/{uuid}', [ServersController::class, 'server_by_uuid']); Route::get('/servers/{uuid}', [ServersController::class, 'server_by_uuid']);
Route::get('/servers/{uuid}/domains', [ServersController::class, 'get_domains_by_server']); Route::get('/servers/{uuid}/domains', [ServersController::class, 'domains_by_server']);
Route::get('/servers/{uuid}/resources', [ServersController::class, 'resources_by_server']);
Route::get('/resources', [ResourcesController::class, 'resources']); Route::get('/resources', [ResourcesController::class, 'resources']);
@ -148,7 +149,7 @@
}); });
Route::any('/{any}', function () { Route::any('/{any}', function () {
return response()->json(['success' => false, 'message' => 'Not found.', 'docs' => 'https://coolify.io/docs'], 404); return response()->json(['message' => 'Not found.', 'docs' => 'https://coolify.io/docs'], 404);
})->where('any', '.*'); })->where('any', '.*');
// Route::middleware(['throttle:5'])->group(function () { // Route::middleware(['throttle:5'])->group(function () {