2018-01-13 14:08:19 -06:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2018-01-19 19:58:57 -06:00
|
|
|
namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
|
2018-01-13 14:08:19 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
use Illuminate\Support\Str;
|
2018-01-19 21:47:06 -06:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
|
|
|
|
use Pterodactyl\Support\JsonValueGuard;
|
|
|
|
|
use Pterodactyl\Support\ValidationRuleSubset;
|
|
|
|
|
use Pterodactyl\Validation\NodeRules;
|
2018-01-13 14:08:19 -06:00
|
|
|
|
2018-01-19 21:47:06 -06:00
|
|
|
class StoreNodeRequest extends ApplicationApiRequest
|
2018-01-13 14:08:19 -06:00
|
|
|
{
|
2022-10-14 10:59:20 -06:00
|
|
|
protected ?string $resource = AdminAcl::RESOURCE_NODES;
|
2018-01-13 14:08:19 -06:00
|
|
|
|
2022-10-14 10:59:20 -06:00
|
|
|
protected int $permission = AdminAcl::WRITE;
|
2018-01-13 14:08:19 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validation rules to apply to this request.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @param NormalizedValidationRules|null $rules
|
|
|
|
|
* @return ValidationRules
|
2018-01-13 14:08:19 -06:00
|
|
|
*/
|
2024-10-21 19:18:20 -06:00
|
|
|
public function rules(?array $rules = null): array
|
2018-01-13 14:08:19 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$selected = ValidationRuleSubset::select($rules ?? NodeRules::rules(), [
|
2018-01-13 14:08:19 -06:00
|
|
|
'public',
|
|
|
|
|
'name',
|
2025-12-24 16:43:00 -08:00
|
|
|
'description',
|
2018-01-13 14:08:19 -06:00
|
|
|
'location_id',
|
|
|
|
|
'fqdn',
|
|
|
|
|
'scheme',
|
|
|
|
|
'behind_proxy',
|
2022-11-07 00:02:30 +01:00
|
|
|
'maintenance_mode',
|
2018-01-13 14:08:19 -06:00
|
|
|
'memory',
|
|
|
|
|
'memory_overallocate',
|
|
|
|
|
'disk',
|
2019-03-02 14:48:05 -08:00
|
|
|
'disk_overallocate',
|
2018-01-13 14:08:19 -06:00
|
|
|
'upload_size',
|
|
|
|
|
'daemonListen',
|
|
|
|
|
'daemonSFTP',
|
|
|
|
|
'daemonBase',
|
2026-10-05 18:10:18 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$normalized = [];
|
|
|
|
|
foreach ($selected as $key => $value) {
|
2018-01-13 14:08:19 -06:00
|
|
|
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
|
2026-10-05 18:10:18 -04:00
|
|
|
$normalized[Str::snake($key)] = $value;
|
|
|
|
|
}
|
2018-01-13 14:08:19 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $normalized;
|
2018-01-13 14:08:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fields to rename for clarity in the API response.
|
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function attributes(): array
|
2018-01-13 14:08:19 -06:00
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'daemon_base' => 'Daemon Base Path',
|
|
|
|
|
'upload_size' => 'File Upload Size Limit',
|
|
|
|
|
'location_id' => 'Location',
|
|
|
|
|
'public' => 'Node Visibility',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Change the formatting of some data keys in the validated response data
|
|
|
|
|
* to match what the application expects in the services.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @return NodeCreationData
|
2018-01-13 14:08:19 -06:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function payload(): array
|
2018-01-13 14:08:19 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$data = parent::validated();
|
|
|
|
|
|
|
|
|
|
$daemonBase = Arr::get($data, 'daemon_base');
|
|
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
|
'name' => JsonValueGuard::string(Arr::get($data, 'name')),
|
|
|
|
|
'location_id' => JsonValueGuard::integer(Arr::get($data, 'location_id')),
|
|
|
|
|
'fqdn' => JsonValueGuard::string(Arr::get($data, 'fqdn')),
|
|
|
|
|
'scheme' => JsonValueGuard::string(Arr::get($data, 'scheme')),
|
|
|
|
|
'memory' => JsonValueGuard::integer(Arr::get($data, 'memory')),
|
|
|
|
|
'memory_overallocate' => JsonValueGuard::integer(Arr::get($data, 'memory_overallocate')),
|
|
|
|
|
'disk' => JsonValueGuard::integer(Arr::get($data, 'disk')),
|
|
|
|
|
'disk_overallocate' => JsonValueGuard::integer(Arr::get($data, 'disk_overallocate')),
|
|
|
|
|
'daemonListen' => JsonValueGuard::integer(Arr::get($data, 'daemon_listen')),
|
|
|
|
|
'daemonSFTP' => JsonValueGuard::integer(Arr::get($data, 'daemon_sftp')),
|
|
|
|
|
'daemonBase' => $daemonBase !== null && $daemonBase !== '' ? JsonValueGuard::string($daemonBase) : '/var/lib/pterodactyl/volumes',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (array_key_exists('description', $data)) {
|
|
|
|
|
$description = Arr::get($data, 'description');
|
|
|
|
|
$response['description'] = $description !== null && $description !== '' ? JsonValueGuard::string($description) : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (['public', 'behind_proxy', 'maintenance_mode'] as $boolean) {
|
|
|
|
|
if (array_key_exists($boolean, $data)) {
|
|
|
|
|
$response[$boolean] = JsonValueGuard::boolean(Arr::get($data, $boolean));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-13 14:08:19 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
$uploadSize = Arr::get($data, 'upload_size');
|
|
|
|
|
if ($uploadSize !== null && $uploadSize !== '') {
|
|
|
|
|
$response['upload_size'] = JsonValueGuard::integer($uploadSize);
|
|
|
|
|
}
|
2018-01-13 14:08:19 -06:00
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
}
|