2018-01-28 23:14:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Api\Application\Servers;
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2018-01-28 23:14:14 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
|
|
|
|
|
|
|
class StoreServerRequest extends ApplicationApiRequest
|
|
|
|
{
|
|
|
|
public function rules(): array
|
|
|
|
{
|
2019-09-05 05:26:28 +00:00
|
|
|
$rules = Server::getRules();
|
2018-01-28 23:14:14 +00:00
|
|
|
|
|
|
|
return [
|
2018-02-24 17:57:12 +00:00
|
|
|
'external_id' => $rules['external_id'],
|
2018-01-28 23:14:14 +00:00
|
|
|
'name' => $rules['name'],
|
|
|
|
'description' => array_merge(['nullable'], $rules['description']),
|
2022-12-15 00:05:46 +00:00
|
|
|
'owner_id' => $rules['owner_id'],
|
|
|
|
'node_id' => $rules['node_id'],
|
2018-01-28 23:14:14 +00:00
|
|
|
|
|
|
|
'limits' => 'required|array',
|
|
|
|
'limits.memory' => $rules['memory'],
|
|
|
|
'limits.swap' => $rules['swap'],
|
|
|
|
'limits.disk' => $rules['disk'],
|
|
|
|
'limits.io' => $rules['io'],
|
2020-03-29 18:41:55 +00:00
|
|
|
'limits.threads' => $rules['threads'],
|
2018-01-28 23:14:14 +00:00
|
|
|
'limits.cpu' => $rules['cpu'],
|
2022-12-15 00:05:46 +00:00
|
|
|
'limits.oom_killer' => 'required|boolean',
|
2018-01-28 23:14:14 +00:00
|
|
|
|
2018-03-03 05:11:30 +00:00
|
|
|
'feature_limits' => 'required|array',
|
|
|
|
'feature_limits.allocations' => $rules['allocation_limit'],
|
2020-10-17 21:23:00 +00:00
|
|
|
'feature_limits.backups' => $rules['backup_limit'],
|
2022-12-15 00:05:46 +00:00
|
|
|
'feature_limits.databases' => $rules['database_limit'],
|
2018-03-03 05:11:30 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
'allocation.default' => 'required|bail|integer|exists:allocations,id',
|
|
|
|
'allocation.additional.*' => 'integer|exists:allocations,id',
|
2018-01-28 23:14:14 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
'startup' => $rules['startup'],
|
|
|
|
'environment' => 'present|array',
|
|
|
|
'egg_id' => $rules['egg_id'],
|
|
|
|
'image' => $rules['image'],
|
|
|
|
'skip_scripts' => 'present|boolean',
|
2018-01-28 23:14:14 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-15 00:05:46 +00:00
|
|
|
* @param string|null $key
|
|
|
|
* @param string|array|null $default
|
|
|
|
*
|
|
|
|
* @return array
|
2018-01-28 23:14:14 +00:00
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
public function validated($key = null, $default = null)
|
2018-01-28 23:14:14 +00:00
|
|
|
{
|
|
|
|
$data = parent::validated();
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
$response = [
|
2018-02-25 20:43:40 +00:00
|
|
|
'external_id' => array_get($data, 'external_id'),
|
2018-01-28 23:14:14 +00:00
|
|
|
'name' => array_get($data, 'name'),
|
|
|
|
'description' => array_get($data, 'description'),
|
2022-12-15 00:05:46 +00:00
|
|
|
'owner_id' => array_get($data, 'owner_id'),
|
|
|
|
'node_id' => array_get($data, 'node_id'),
|
|
|
|
|
2018-01-28 23:14:14 +00:00
|
|
|
'memory' => array_get($data, 'limits.memory'),
|
|
|
|
'swap' => array_get($data, 'limits.swap'),
|
|
|
|
'disk' => array_get($data, 'limits.disk'),
|
|
|
|
'io' => array_get($data, 'limits.io'),
|
2020-03-29 18:41:55 +00:00
|
|
|
'threads' => array_get($data, 'limits.threads'),
|
2022-12-15 00:05:46 +00:00
|
|
|
'cpu' => array_get($data, 'limits.cpu'),
|
|
|
|
'oom_disabled' => !array_get($data, 'limits.oom_killer'),
|
|
|
|
|
2018-03-03 05:11:30 +00:00
|
|
|
'allocation_limit' => array_get($data, 'feature_limits.allocations'),
|
2020-10-17 21:23:00 +00:00
|
|
|
'backup_limit' => array_get($data, 'feature_limits.backups'),
|
2022-12-15 00:05:46 +00:00
|
|
|
'database_limit' => array_get($data, 'feature_limits.databases'),
|
2018-01-28 23:14:14 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
'allocation_id' => array_get($data, 'allocation.default'),
|
|
|
|
'allocation_additional' => array_get($data, 'allocation.additional'),
|
2018-01-28 23:14:14 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
'startup' => array_get($data, 'startup'),
|
|
|
|
'environment' => array_get($data, 'environment'),
|
|
|
|
'egg_id' => array_get($data, 'egg_id'),
|
|
|
|
'image' => array_get($data, 'image'),
|
|
|
|
'skip_scripts' => array_get($data, 'skip_scripts'),
|
|
|
|
'start_on_completion' => array_get($data, 'start_on_completion', false),
|
|
|
|
];
|
2018-01-28 23:14:14 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
return is_null($key) ? $response : Arr::get($response, $key, $default);
|
2018-01-28 23:14:14 +00:00
|
|
|
}
|
|
|
|
}
|