fix: api updates
This commit is contained in:
parent
4459c9f73d
commit
b24a489c77
@ -58,10 +58,7 @@ public function applications(Request $request)
|
||||
return $this->removeSensitiveData($application);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $applications,
|
||||
]);
|
||||
return response()->json($applications);
|
||||
}
|
||||
|
||||
public function create_application(Request $request)
|
||||
@ -96,7 +93,6 @@ public function create_application(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -110,22 +106,22 @@ public function create_application(Request $request)
|
||||
|
||||
$project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first();
|
||||
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();
|
||||
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();
|
||||
if (! $server) {
|
||||
return response()->json(['success' => false, 'message' => 'Server not found.'], 404);
|
||||
return response()->json(['message' => 'Server not found.'], 404);
|
||||
}
|
||||
$destinations = $server->destinations();
|
||||
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')) {
|
||||
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();
|
||||
if ($type === 'public') {
|
||||
@ -147,7 +143,6 @@ public function create_application(Request $request)
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
@ -195,10 +190,7 @@ public function create_application(Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($application),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($application);
|
||||
} elseif ($type === 'private-gh-app') {
|
||||
if (! $request->has('name')) {
|
||||
$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()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
@ -231,7 +222,7 @@ public function create_application(Request $request)
|
||||
}
|
||||
$githubApp = GithubApp::whereTeamId($teamId)->where('uuid', $githubAppUuid)->first();
|
||||
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;
|
||||
if (str($gitRepository)->startsWith('http') || str($gitRepository)->contains('github.com')) {
|
||||
@ -284,10 +275,7 @@ public function create_application(Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($application),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($application));
|
||||
} elseif ($type === 'private-deploy-key') {
|
||||
if (! $request->has('name')) {
|
||||
$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();
|
||||
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();
|
||||
@ -368,10 +356,7 @@ public function create_application(Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($application),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($application));
|
||||
} elseif ($type === 'dockerfile') {
|
||||
if (! $request->has('name')) {
|
||||
$request->offsetSet('name', 'dockerfile-'.new Cuid2(7));
|
||||
@ -382,7 +367,6 @@ public function create_application(Request $request)
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
@ -393,7 +377,6 @@ public function create_application(Request $request)
|
||||
}
|
||||
if (! isBase64Encoded($request->dockerfile)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'dockerfile' => 'The dockerfile should be base64 encoded.',
|
||||
@ -403,7 +386,6 @@ public function create_application(Request $request)
|
||||
$dockerFile = base64_decode($request->dockerfile);
|
||||
if (mb_detect_encoding($dockerFile, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'dockerfile' => 'The dockerfile should be base64 encoded.',
|
||||
@ -443,10 +425,7 @@ public function create_application(Request $request)
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($application),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($application));
|
||||
} elseif ($type === 'docker-image') {
|
||||
if (! $request->has('name')) {
|
||||
$request->offsetSet('name', 'docker-image-'.new Cuid2(7));
|
||||
@ -459,7 +438,6 @@ public function create_application(Request $request)
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
@ -496,10 +474,7 @@ public function create_application(Request $request)
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($application),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($application));
|
||||
} elseif ($type === 'dockercompose') {
|
||||
$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([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -527,7 +501,6 @@ public function create_application(Request $request)
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
@ -538,7 +511,6 @@ public function create_application(Request $request)
|
||||
}
|
||||
if (! isBase64Encoded($request->docker_compose_raw)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
StartService::dispatch($service);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($service),
|
||||
]);
|
||||
return response()->json(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');
|
||||
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();
|
||||
if (! $application) {
|
||||
return response()->json(['success' => false, 'message' => 'Application not found.'], 404);
|
||||
return response()->json(['message' => 'Application not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->removeSensitiveData($application),
|
||||
]);
|
||||
return response()->json($this->removeSensitiveData($application));
|
||||
}
|
||||
|
||||
public function delete_by_uuid(Request $request)
|
||||
@ -618,7 +584,6 @@ public function delete_by_uuid(Request $request)
|
||||
|
||||
if ($request->collect()->count() == 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid request.',
|
||||
], 400);
|
||||
}
|
||||
@ -626,14 +591,12 @@ public function delete_by_uuid(Request $request)
|
||||
|
||||
if (! $application) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Application not found',
|
||||
], 404);
|
||||
}
|
||||
DeleteResourceJob::dispatch($application, $cleanup);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Application deletion request queued.',
|
||||
]);
|
||||
}
|
||||
@ -647,7 +610,6 @@ public function update_by_uuid(Request $request)
|
||||
|
||||
if ($request->collect()->count() == 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid request.',
|
||||
], 400);
|
||||
}
|
||||
@ -659,7 +621,6 @@ public function update_by_uuid(Request $request)
|
||||
|
||||
if (! $application) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Application not found',
|
||||
], 404);
|
||||
}
|
||||
@ -686,7 +647,6 @@ public function update_by_uuid(Request $request)
|
||||
foreach ($ports as $port) {
|
||||
if (! is_numeric($port)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -750,10 +709,7 @@ public function update_by_uuid(Request $request)
|
||||
$application->fill($data);
|
||||
$application->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->removeSensitiveData($application),
|
||||
]);
|
||||
return response()->json($this->removeSensitiveData($application));
|
||||
}
|
||||
|
||||
public function envs_by_uuid(Request $request)
|
||||
@ -766,16 +722,12 @@ public function envs_by_uuid(Request $request)
|
||||
|
||||
if (! $application) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Application not found',
|
||||
], 404);
|
||||
}
|
||||
$envs = $application->environment_variables->sortBy('id')->merge($application->environment_variables_preview->sortBy('id'));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($envs),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($envs));
|
||||
}
|
||||
|
||||
public function update_env_by_uuid(Request $request)
|
||||
@ -795,7 +747,6 @@ public function update_env_by_uuid(Request $request)
|
||||
|
||||
if (! $application) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Application not found',
|
||||
], 404);
|
||||
}
|
||||
@ -817,7 +768,6 @@ public function update_env_by_uuid(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -843,7 +793,6 @@ public function update_env_by_uuid(Request $request)
|
||||
return response()->json(serializeApiResponse($env));
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Environment variable not found.',
|
||||
], 404);
|
||||
}
|
||||
@ -862,14 +811,10 @@ public function update_env_by_uuid(Request $request)
|
||||
}
|
||||
$env->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($env),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($env));
|
||||
} else {
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Environment variable not found.',
|
||||
], 404);
|
||||
|
||||
@ -877,8 +822,7 @@ public function update_env_by_uuid(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
'message' => 'Something is not okay. Are you okay?',
|
||||
], 500);
|
||||
|
||||
}
|
||||
@ -899,7 +843,6 @@ public function create_bulk_envs(Request $request)
|
||||
|
||||
if (! $application) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Application not found',
|
||||
], 404);
|
||||
}
|
||||
@ -907,7 +850,6 @@ public function create_bulk_envs(Request $request)
|
||||
$bulk_data = $request->get('data');
|
||||
if (! $bulk_data) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Bulk data is required.',
|
||||
], 400);
|
||||
}
|
||||
@ -924,7 +866,6 @@ public function create_bulk_envs(Request $request)
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
@ -975,10 +916,7 @@ public function create_bulk_envs(Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($env),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($env));
|
||||
}
|
||||
|
||||
public function create_env(Request $request)
|
||||
@ -993,7 +931,6 @@ public function create_env(Request $request)
|
||||
|
||||
if (! $application) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Application not found',
|
||||
], 404);
|
||||
}
|
||||
@ -1015,7 +952,6 @@ public function create_env(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -1025,7 +961,6 @@ public function create_env(Request $request)
|
||||
$env = $application->environment_variables_preview->where('key', $request->key)->first();
|
||||
if ($env) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Environment variable already exists. Use PATCH request to update it.',
|
||||
], 409);
|
||||
} else {
|
||||
@ -1037,10 +972,7 @@ public function create_env(Request $request)
|
||||
'is_literal' => $request->is_literal ?? false,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($env),
|
||||
])->setStatusCode(201);
|
||||
return response()->json(serializeApiResponse($env))->setStatusCode(201);
|
||||
}
|
||||
} else {
|
||||
$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,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($env),
|
||||
])->setStatusCode(201);
|
||||
return response()->json(serializeApiResponse($env))->setStatusCode(201);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
], 500);
|
||||
|
||||
@ -1082,21 +1010,18 @@ public function delete_env_by_uuid(Request $request)
|
||||
|
||||
if (! $application) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Application not found.',
|
||||
], 404);
|
||||
}
|
||||
$found_env = EnvironmentVariable::where('uuid', $request->env_uuid)->where('application_id', $application->id)->first();
|
||||
if (! $found_env) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Environment variable not found.',
|
||||
], 404);
|
||||
}
|
||||
$found_env->forceDelete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Environment variable deleted.',
|
||||
]);
|
||||
}
|
||||
@ -1111,11 +1036,11 @@ public function action_deploy(Request $request)
|
||||
$instant_deploy = $request->query->get('instant_deploy') ?? false;
|
||||
$uuid = $request->route('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();
|
||||
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);
|
||||
@ -1130,7 +1055,6 @@ public function action_deploy(Request $request)
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Deployment request queued.',
|
||||
'data' => [
|
||||
'deployment_uuid' => $deployment_uuid->toString(),
|
||||
@ -1149,17 +1073,16 @@ public function action_stop(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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();
|
||||
if (! $application) {
|
||||
return response()->json(['success' => false, 'message' => 'Application not found.'], 404);
|
||||
return response()->json(['message' => 'Application not found.'], 404);
|
||||
}
|
||||
StopApplication::dispatch($application);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Application stopping request queued.',
|
||||
],
|
||||
);
|
||||
@ -1173,11 +1096,11 @@ public function action_restart(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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();
|
||||
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);
|
||||
@ -1191,7 +1114,6 @@ public function action_restart(Request $request)
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Restart request queued.',
|
||||
'data' => [
|
||||
'deployment_uuid' => $deployment_uuid->toString(),
|
||||
@ -1213,7 +1135,6 @@ private function validateDataApplications(Request $request, Server $server)
|
||||
$port = explode(':', $portMapping);
|
||||
if (in_array($port[0], $ports)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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 (! isBase64Encoded($request->custom_labels)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
if (mb_detect_encoding($customLabels, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'custom_labels' => 'The custom_labels should be base64 encoded.',
|
||||
@ -1260,14 +1179,12 @@ private function validateDataApplications(Request $request, Server $server)
|
||||
});
|
||||
if (count($errors) > 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
}
|
||||
if (checkIfDomainIsAlreadyUsed($fqdn, $teamId)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'domains' => 'One of the domain is already used.',
|
||||
|
@ -52,10 +52,7 @@ public function databases(Request $request)
|
||||
return $this->removeSensitiveData($database);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $databases,
|
||||
]);
|
||||
return response()->json($databases);
|
||||
}
|
||||
|
||||
public function database_by_uuid(Request $request)
|
||||
@ -65,17 +62,14 @@ public function database_by_uuid(Request $request)
|
||||
return invalidTokenResponse();
|
||||
}
|
||||
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);
|
||||
if (! $database) {
|
||||
return response()->json(['success' => false, 'message' => 'Database not found.'], 404);
|
||||
return response()->json(['message' => 'Database not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->removeSensitiveData($database),
|
||||
]);
|
||||
return response()->json($this->removeSensitiveData($database));
|
||||
}
|
||||
|
||||
public function update_by_uuid(Request $request)
|
||||
@ -141,7 +135,6 @@ public function update_by_uuid(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -150,11 +143,11 @@ public function update_by_uuid(Request $request)
|
||||
removeUnnecessaryFieldsFromRequest($request);
|
||||
$database = queryDatabaseByUuidWithinTeam($uuid, $teamId);
|
||||
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 (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([
|
||||
'success' => true,
|
||||
'message' => 'Database updated.',
|
||||
'data' => $this->removeSensitiveData($database),
|
||||
]);
|
||||
@ -252,7 +244,6 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -264,27 +255,27 @@ public function create_database(Request $request)
|
||||
}
|
||||
$project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first();
|
||||
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();
|
||||
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();
|
||||
if (! $server) {
|
||||
return response()->json(['success' => false, 'message' => 'Server not found.'], 404);
|
||||
return response()->json(['message' => 'Server not found.'], 404);
|
||||
}
|
||||
$destinations = $server->destinations();
|
||||
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')) {
|
||||
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();
|
||||
if ($request->has('public_port') && $request->is_public) {
|
||||
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) {
|
||||
@ -292,7 +283,6 @@ public function create_database(Request $request)
|
||||
if ($request->has('postgres_conf')) {
|
||||
if (! isBase64Encoded($request->postgres_conf)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
if (mb_detect_encoding($postgresConf, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'postgres_conf' => 'The postgres_conf should be base64 encoded.',
|
||||
@ -320,7 +309,6 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database starting queued.',
|
||||
'data' => serializeApiResponse($database),
|
||||
]);
|
||||
@ -329,7 +317,6 @@ public function create_database(Request $request)
|
||||
if ($request->has('mariadb_conf')) {
|
||||
if (! isBase64Encoded($request->mariadb_conf)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
if (mb_detect_encoding($mariadbConf, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'mariadb_conf' => 'The mariadb_conf should be base64 encoded.',
|
||||
@ -357,7 +343,6 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database starting queued.',
|
||||
'data' => serializeApiResponse($database),
|
||||
]);
|
||||
@ -366,7 +351,6 @@ public function create_database(Request $request)
|
||||
if ($request->has('mysql_conf')) {
|
||||
if (! isBase64Encoded($request->mysql_conf)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
if (mb_detect_encoding($mysqlConf, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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 (! isBase64Encoded($request->redis_conf)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
if (mb_detect_encoding($redisConf, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'redis_conf' => 'The redis_conf should be base64 encoded.',
|
||||
@ -431,7 +412,6 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database starting queued.',
|
||||
'data' => serializeApiResponse($database),
|
||||
]);
|
||||
@ -446,7 +426,6 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database starting queued.',
|
||||
'data' => serializeApiResponse($database),
|
||||
]);
|
||||
@ -455,7 +434,6 @@ public function create_database(Request $request)
|
||||
if ($request->has('keydb_conf')) {
|
||||
if (! isBase64Encoded($request->keydb_conf)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
if (mb_detect_encoding($keydbConf, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'keydb_conf' => 'The keydb_conf should be base64 encoded.',
|
||||
@ -483,7 +460,6 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database starting queued.',
|
||||
'data' => serializeApiResponse($database),
|
||||
]);
|
||||
@ -498,7 +474,6 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database starting queued.',
|
||||
'data' => serializeApiResponse($database),
|
||||
]);
|
||||
@ -507,7 +482,6 @@ public function create_database(Request $request)
|
||||
if ($request->has('mongo_conf')) {
|
||||
if (! isBase64Encoded($request->mongo_conf)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'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);
|
||||
if (mb_detect_encoding($mongoConf, 'ASCII', true) === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => [
|
||||
'mongo_conf' => 'The mongo_conf should be base64 encoded.',
|
||||
@ -535,13 +508,12 @@ public function create_database(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database starting queued.',
|
||||
'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)
|
||||
@ -551,17 +523,16 @@ public function delete_by_uuid(Request $request)
|
||||
return invalidTokenResponse();
|
||||
}
|
||||
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);
|
||||
if (! $database) {
|
||||
return response()->json(['success' => false, 'message' => 'Database not found.'], 404);
|
||||
return response()->json(['message' => 'Database not found.'], 404);
|
||||
}
|
||||
StopDatabase::dispatch($database);
|
||||
$database->forceDelete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Database deletion request queued.',
|
||||
]);
|
||||
}
|
||||
@ -574,20 +545,19 @@ public function action_deploy(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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);
|
||||
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')) {
|
||||
return response()->json(['success' => false, 'message' => 'Database is already running.'], 400);
|
||||
return response()->json(['message' => 'Database is already running.'], 400);
|
||||
}
|
||||
StartDatabase::dispatch($database);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Database starting request queued.',
|
||||
],
|
||||
200
|
||||
@ -602,20 +572,19 @@ public function action_stop(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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);
|
||||
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')) {
|
||||
return response()->json(['success' => false, 'message' => 'Database is already stopped.'], 400);
|
||||
return response()->json(['message' => 'Database is already stopped.'], 400);
|
||||
}
|
||||
StopDatabase::dispatch($database);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Database stopping request queued.',
|
||||
],
|
||||
200
|
||||
@ -630,17 +599,16 @@ public function action_restart(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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);
|
||||
if (! $database) {
|
||||
return response()->json(['success' => false, 'message' => 'Database not found.'], 404);
|
||||
return response()->json(['message' => 'Database not found.'], 404);
|
||||
}
|
||||
RestartDatabase::dispatch($database);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Database restarting request queued.',
|
||||
],
|
||||
200
|
||||
|
@ -45,10 +45,7 @@ public function deployments(Request $request)
|
||||
'status',
|
||||
])->sortBy('id')->toArray();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($deployments_per_server),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($deployments_per_server));
|
||||
}
|
||||
|
||||
public function deployment_by_uuid(Request $request)
|
||||
@ -59,17 +56,14 @@ public function deployment_by_uuid(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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();
|
||||
if (! $deployment) {
|
||||
return response()->json(['success' => false, 'message' => 'Deployment not found.'], 404);
|
||||
return response()->json(['message' => 'Deployment not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->removeSensitiveData($deployment),
|
||||
]);
|
||||
return response()->json($this->removeSensitiveData($deployment));
|
||||
}
|
||||
|
||||
public function deploy(Request $request)
|
||||
@ -80,7 +74,7 @@ public function deploy(Request $request)
|
||||
$force = $request->query->get('force') ?? false;
|
||||
|
||||
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)) {
|
||||
return invalidTokenResponse();
|
||||
@ -91,7 +85,7 @@ public function deploy(Request $request)
|
||||
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)
|
||||
@ -100,7 +94,7 @@ private function by_uuids(string $uuid, int $teamId, bool $force = false)
|
||||
$uuids = collect(array_filter($uuids));
|
||||
|
||||
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();
|
||||
$payload = collect();
|
||||
@ -109,22 +103,19 @@ private function by_uuids(string $uuid, int $teamId, bool $force = false)
|
||||
if ($resource) {
|
||||
['message' => $return_message, 'deployment_uuid' => $deployment_uuid] = $this->deploy_resource($resource, $force);
|
||||
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 {
|
||||
$deployments->push(['success' => true, 'message' => $return_message, 'resource_uuid' => $uuid]);
|
||||
$deployments->push(['message' => $return_message, 'resource_uuid' => $uuid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($deployments->count() > 0) {
|
||||
$payload->put('deployments', $deployments->toArray());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($payload->toArray()),
|
||||
]);
|
||||
return response()->json(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)
|
||||
@ -133,7 +124,7 @@ public function by_tags(string $tags, int $team_id, bool $force = false)
|
||||
$tags = collect(array_filter($tags));
|
||||
|
||||
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([]);
|
||||
$deployments = collect();
|
||||
@ -169,13 +160,10 @@ public function by_tags(string $tags, int $team_id, bool $force = false)
|
||||
$payload->put('details', $deployments->toArray());
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($payload->toArray()),
|
||||
]);
|
||||
return response()->json(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
|
||||
@ -183,7 +171,7 @@ public function deploy_resource($resource, bool $force = false): array
|
||||
$message = null;
|
||||
$deployment_uuid = null;
|
||||
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()) {
|
||||
case 'App\Models\Application':
|
||||
@ -209,6 +197,6 @@ public function deploy_resource($resource, bool $force = false): array
|
||||
break;
|
||||
}
|
||||
|
||||
return ['success' => true, 'message' => $message, 'deployment_uuid' => $deployment_uuid];
|
||||
return ['message' => $message, 'deployment_uuid' => $deployment_uuid];
|
||||
}
|
||||
}
|
||||
|
@ -17,21 +17,18 @@ public function delete_env_by_uuid(Request $request)
|
||||
$env = EnvironmentVariable::where('uuid', $request->env_uuid)->first();
|
||||
if (! $env) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Environment variable not found.',
|
||||
], 404);
|
||||
}
|
||||
$found_app = $env->resource()->whereRelation('environment.project.team', 'id', $teamId)->first();
|
||||
if (! $found_app) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Environment variable not found.',
|
||||
], 404);
|
||||
}
|
||||
$env->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Environment variable deleted.',
|
||||
]);
|
||||
}
|
||||
|
@ -16,10 +16,8 @@ public function projects(Request $request)
|
||||
}
|
||||
$projects = Project::whereTeamId($teamId)->select('id', 'name', 'uuid')->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($projects),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($projects),
|
||||
);
|
||||
}
|
||||
|
||||
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']);
|
||||
if (! $project) {
|
||||
return response()->json(['success' => false, 'message' => 'Project not found.'], 404);
|
||||
return response()->json(['message' => 'Project not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($project),
|
||||
]);
|
||||
return response()->json(
|
||||
serializeApiResponse($project),
|
||||
);
|
||||
}
|
||||
|
||||
public function environment_details(Request $request)
|
||||
@ -48,13 +45,10 @@ public function environment_details(Request $request)
|
||||
$project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first();
|
||||
$environment = $project->environments()->whereName(request()->environment_name)->first();
|
||||
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']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($environment),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($environment));
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,6 @@ public function resources(Request $request)
|
||||
return $payload;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($resources),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($resources));
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,7 @@ public function keys(Request $request)
|
||||
}
|
||||
$keys = PrivateKey::where('team_id', $teamId)->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($keys),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($keys));
|
||||
}
|
||||
|
||||
public function key_by_uuid(Request $request)
|
||||
@ -33,15 +30,11 @@ public function key_by_uuid(Request $request)
|
||||
|
||||
if (is_null($key)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Key not found.',
|
||||
'message' => 'Private Key not found.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($key),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($key));
|
||||
}
|
||||
|
||||
public function create_key(Request $request)
|
||||
@ -64,7 +57,6 @@ public function create_key(Request $request)
|
||||
$errors = $validator->errors();
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -82,10 +74,9 @@ public function create_key(Request $request)
|
||||
'private_key' => $request->private_key,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($key),
|
||||
]);
|
||||
return response()->json(serializeApiResponse([
|
||||
'uuid' => $key->uuid,
|
||||
]))->setStatusCode(201);
|
||||
}
|
||||
|
||||
public function update_key(Request $request)
|
||||
@ -116,7 +107,6 @@ public function update_key(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -124,16 +114,14 @@ public function update_key(Request $request)
|
||||
$foundKey = PrivateKey::where('team_id', $teamId)->where('uuid', $request->uuid)->first();
|
||||
if (is_null($foundKey)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Key not found.',
|
||||
'message' => 'Private Key not found.',
|
||||
], 404);
|
||||
}
|
||||
$foundKey->update($request->all());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($foundKey),
|
||||
])->setStatusCode(201);
|
||||
return response()->json(serializeApiResponse([
|
||||
'uuid' => $foundKey->uuid,
|
||||
]))->setStatusCode(201);
|
||||
}
|
||||
|
||||
public function delete_key(Request $request)
|
||||
@ -143,18 +131,17 @@ public function delete_key(Request $request)
|
||||
return invalidTokenResponse();
|
||||
}
|
||||
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();
|
||||
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();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Key deleted.',
|
||||
'message' => 'Private Key deleted.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,29 @@
|
||||
|
||||
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)
|
||||
{
|
||||
$teamId = getTeamIdFromToken();
|
||||
@ -25,13 +48,14 @@ public function servers(Request $request)
|
||||
return $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([
|
||||
'success' => true,
|
||||
'data' => $servers,
|
||||
]);
|
||||
return response()->json($servers);
|
||||
}
|
||||
|
||||
public function server_by_uuid(Request $request)
|
||||
@ -67,13 +91,47 @@ public function server_by_uuid(Request $request)
|
||||
$server->load(['settings']);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($server),
|
||||
]);
|
||||
$settings = $this->removeSensitiveDataFromSettings($server->settings);
|
||||
$server = $this->removeSensitiveData($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();
|
||||
if (is_null($teamId)) {
|
||||
@ -83,10 +141,7 @@ public function get_domains_by_server(Request $request)
|
||||
if ($uuid) {
|
||||
$domains = Application::getDomainsByUuid($uuid);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($domains),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($domains));
|
||||
}
|
||||
$projects = Project::where('team_id', $teamId)->get();
|
||||
$domains = collect();
|
||||
@ -181,9 +236,6 @@ public function get_domains_by_server(Request $request)
|
||||
];
|
||||
})->values();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($domains),
|
||||
]);
|
||||
return response()->json(serializeApiResponse($domains));
|
||||
}
|
||||
}
|
||||
|
@ -45,10 +45,7 @@ public function services(Request $request)
|
||||
$service = $this->removeSensitiveData($service);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $services,
|
||||
]);
|
||||
return response()->json($services);
|
||||
}
|
||||
|
||||
public function create_service(Request $request)
|
||||
@ -85,7 +82,6 @@ public function create_service(Request $request)
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $errors,
|
||||
], 422);
|
||||
@ -97,22 +93,22 @@ public function create_service(Request $request)
|
||||
}
|
||||
$project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first();
|
||||
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();
|
||||
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();
|
||||
if (! $server) {
|
||||
return response()->json(['success' => false, 'message' => 'Server not found.'], 404);
|
||||
return response()->json(['message' => 'Server not found.'], 404);
|
||||
}
|
||||
$destinations = $server->destinations();
|
||||
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')) {
|
||||
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();
|
||||
$services = get_service_templates();
|
||||
@ -170,7 +166,6 @@ public function create_service(Request $request)
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Service created.',
|
||||
'data' => $this->removeSensitiveData([
|
||||
'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 {
|
||||
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)
|
||||
@ -196,17 +191,14 @@ public function service_by_uuid(Request $request)
|
||||
return invalidTokenResponse();
|
||||
}
|
||||
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();
|
||||
if (! $service) {
|
||||
return response()->json(['success' => false, 'message' => 'Service not found.'], 404);
|
||||
return response()->json(['message' => 'Service not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->removeSensitiveData($service),
|
||||
]);
|
||||
return response()->json($this->removeSensitiveData($service));
|
||||
}
|
||||
|
||||
public function delete_by_uuid(Request $request)
|
||||
@ -216,16 +208,15 @@ public function delete_by_uuid(Request $request)
|
||||
return invalidTokenResponse();
|
||||
}
|
||||
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();
|
||||
if (! $service) {
|
||||
return response()->json(['success' => false, 'message' => 'Service not found.'], 404);
|
||||
return response()->json(['message' => 'Service not found.'], 404);
|
||||
}
|
||||
DeleteResourceJob::dispatch($service);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Service deletion request queued.',
|
||||
]);
|
||||
}
|
||||
@ -238,20 +229,19 @@ public function action_deploy(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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();
|
||||
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')) {
|
||||
return response()->json(['success' => false, 'message' => 'Service is already running.'], 400);
|
||||
return response()->json(['message' => 'Service is already running.'], 400);
|
||||
}
|
||||
StartService::dispatch($service);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Service starting request queued.',
|
||||
],
|
||||
200
|
||||
@ -266,20 +256,19 @@ public function action_stop(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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();
|
||||
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')) {
|
||||
return response()->json(['success' => false, 'message' => 'Service is already stopped.'], 400);
|
||||
return response()->json(['message' => 'Service is already stopped.'], 400);
|
||||
}
|
||||
StopService::dispatch($service);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Service stopping request queued.',
|
||||
],
|
||||
200
|
||||
@ -294,17 +283,16 @@ public function action_restart(Request $request)
|
||||
}
|
||||
$uuid = $request->route('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();
|
||||
if (! $service) {
|
||||
return response()->json(['success' => false, 'message' => 'Service not found.'], 404);
|
||||
return response()->json(['message' => 'Service not found.'], 404);
|
||||
}
|
||||
RestartService::dispatch($service);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'success' => true,
|
||||
'message' => 'Service restarting request queued.',
|
||||
],
|
||||
200
|
||||
|
@ -10,6 +10,10 @@ class TeamController extends Controller
|
||||
private function removeSensitiveData($team)
|
||||
{
|
||||
$token = auth()->user()->currentAccessToken();
|
||||
$team->makeHidden([
|
||||
'custom_server_limit',
|
||||
'pivot',
|
||||
]);
|
||||
if ($token->can('view:sensitive')) {
|
||||
return serializeApiResponse($team);
|
||||
}
|
||||
@ -34,10 +38,9 @@ public function teams(Request $request)
|
||||
return $this->removeSensitiveData($team);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $teams,
|
||||
]);
|
||||
return response()->json(
|
||||
$teams,
|
||||
);
|
||||
}
|
||||
|
||||
public function team_by_id(Request $request)
|
||||
@ -50,14 +53,13 @@ public function team_by_id(Request $request)
|
||||
$teams = auth()->user()->teams;
|
||||
$team = $teams->where('id', $id)->first();
|
||||
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);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($team),
|
||||
]);
|
||||
return response()->json(
|
||||
serializeApiResponse($team),
|
||||
);
|
||||
}
|
||||
|
||||
public function members_by_id(Request $request)
|
||||
@ -70,14 +72,16 @@ public function members_by_id(Request $request)
|
||||
$teams = auth()->user()->teams;
|
||||
$team = $teams->where('id', $id)->first();
|
||||
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;
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($members),
|
||||
$members->makeHidden([
|
||||
'pivot',
|
||||
]);
|
||||
|
||||
return response()->json(
|
||||
serializeApiResponse($members),
|
||||
);
|
||||
}
|
||||
|
||||
public function current_team(Request $request)
|
||||
@ -88,10 +92,9 @@ public function current_team(Request $request)
|
||||
}
|
||||
$team = auth()->user()->currentTeam();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($team),
|
||||
]);
|
||||
return response()->json(
|
||||
serializeApiResponse($team),
|
||||
);
|
||||
}
|
||||
|
||||
public function current_team_members(Request $request)
|
||||
@ -102,9 +105,8 @@ public function current_team_members(Request $request)
|
||||
}
|
||||
$team = auth()->user()->currentTeam();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => serializeApiResponse($team->members),
|
||||
]);
|
||||
return response()->json(
|
||||
serializeApiResponse($team->members),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public function handle(Request $request, Closure $next): Response
|
||||
return $next($request);
|
||||
}
|
||||
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);
|
||||
|
@ -20,6 +20,6 @@ public function handle(Request $request, Closure $next): Response
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ function getTeamIdFromToken()
|
||||
}
|
||||
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)
|
||||
@ -138,7 +138,6 @@ 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);
|
||||
@ -146,7 +145,6 @@ function validateIncomingRequest(Request $request)
|
||||
// check if request is valid json
|
||||
if (! json_decode($request->getContent())) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid request.',
|
||||
'error' => 'Invalid JSON.',
|
||||
], 400);
|
||||
@ -154,7 +152,6 @@ function validateIncomingRequest(Request $request)
|
||||
// check if valid json is empty
|
||||
if (empty($request->json()->all())) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid request.',
|
||||
'error' => 'Empty JSON.',
|
||||
], 400);
|
||||
|
@ -43,7 +43,7 @@
|
||||
return invalidTokenResponse();
|
||||
}
|
||||
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->update(['is_api_enabled' => true]);
|
||||
@ -56,7 +56,7 @@
|
||||
return invalidTokenResponse();
|
||||
}
|
||||
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->update(['is_api_enabled' => false]);
|
||||
@ -97,7 +97,8 @@
|
||||
|
||||
Route::get('/servers', [ServersController::class, 'servers']);
|
||||
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']);
|
||||
|
||||
@ -148,7 +149,7 @@
|
||||
});
|
||||
|
||||
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', '.*');
|
||||
|
||||
// Route::middleware(['throttle:5'])->group(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user