From 764811c927bb7cd4c32e49ac92d5411eaf3e19d2 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 27 Feb 2022 10:50:25 -0500 Subject: [PATCH] Fix incompatible signatures after update --- .../Allocations/StoreAllocationRequest.php | 12 ++++++++++-- .../Api/Application/Nodes/StoreNodeRequest.php | 13 ++++++++++--- .../Databases/StoreServerDatabaseRequest.php | 12 ++++++++++-- .../Api/Application/Servers/StoreServerRequest.php | 12 ++++++++++-- .../UpdateServerBuildConfigurationRequest.php | 11 +++++++++-- .../Servers/UpdateServerDetailsRequest.php | 10 ++++++++-- .../Api/Application/Servers/UpdateServerRequest.php | 13 ++++++++++--- app/Models/Node.php | 7 ++++++- 8 files changed, 73 insertions(+), 17 deletions(-) diff --git a/app/Http/Requests/Api/Application/Allocations/StoreAllocationRequest.php b/app/Http/Requests/Api/Application/Allocations/StoreAllocationRequest.php index dd97e1332..b0472b1fc 100644 --- a/app/Http/Requests/Api/Application/Allocations/StoreAllocationRequest.php +++ b/app/Http/Requests/Api/Application/Allocations/StoreAllocationRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Allocations; +use Illuminate\Support\Arr; use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; class StoreAllocationRequest extends ApplicationApiRequest @@ -16,14 +17,21 @@ class StoreAllocationRequest extends ApplicationApiRequest ]; } - public function validated(): array + /** + * @param string|null $key + * @param string|array|null $default + * @return mixed + */ + public function validated($key = null, $default = null) { $data = parent::validated(); - return [ + $response = [ 'allocation_ip' => $data['ip'], 'allocation_ports' => $data['ports'], 'allocation_alias' => $data['alias'] ?? null, ]; + + return is_null($key) ? $response : Arr::get($response, $key, $default); } } diff --git a/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php b/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php index cef2169c7..65459091d 100644 --- a/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php +++ b/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Nodes; +use Illuminate\Support\Arr; use Pterodactyl\Models\Node; use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; @@ -58,12 +59,18 @@ class StoreNodeRequest extends ApplicationApiRequest * Change the formatting of some data keys in the validated response data * to match what the application expects in the services. * - * @return array + * @param string|null $key + * @param string|array|null $default + * @return mixed */ - public function validated() + public function validated($key = null, $default = null) { $response = parent::validated(); - $response['daemon_base'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemon_base'); + $response['daemon_base'] = $response['daemon_base'] ?? Node::DEFAULT_DAEMON_BASE; + + if (!is_null($key)) { + return Arr::get($response, $key, $default); + } return $response; } diff --git a/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php b/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php index f8549075a..4954176b8 100644 --- a/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php +++ b/app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Servers\Databases; +use Illuminate\Support\Arr; use Webmozart\Assert\Assert; use Pterodactyl\Models\Server; use Illuminate\Validation\Rule; @@ -30,13 +31,20 @@ class StoreServerDatabaseRequest extends ApplicationApiRequest ]; } - public function validated(): array + /** + * @param string|null $key + * @param string|array|null $default + * @return mixed + */ + public function validated($key = null, $default = null) { - return [ + $data = [ 'database' => $this->input('database'), 'remote' => $this->input('remote'), 'database_host_id' => $this->input('host'), ]; + + return is_null($key) ? $data : Arr::get($data, $key, $default); } public function attributes(): array diff --git a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php index 452909abe..984895761 100644 --- a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php +++ b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Servers; +use Illuminate\Support\Arr; use Pterodactyl\Models\Server; use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; @@ -43,11 +44,16 @@ class StoreServerRequest extends ApplicationApiRequest ]; } - public function validated(): array + /** + * @param string|null $key + * @param string|array|null $default + * @return array + */ + public function validated($key = null, $default = null) { $data = parent::validated(); - return [ + $response = [ 'external_id' => array_get($data, 'external_id'), 'name' => array_get($data, 'name'), 'description' => array_get($data, 'description'), @@ -76,5 +82,7 @@ class StoreServerRequest extends ApplicationApiRequest 'skip_scripts' => array_get($data, 'skip_scripts'), 'start_on_completion' => array_get($data, 'start_on_completion', false), ]; + + return is_null($key) ? $response : Arr::get($response, $key, $default); } } diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php index 7045c1e08..28d2e3e39 100644 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php +++ b/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Servers; +use Illuminate\Support\Arr; use Pterodactyl\Models\Server; use Illuminate\Support\Collection; @@ -52,9 +53,11 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest /** * Convert the allocation field into the expected format for the service handler. * - * @return array + * @param string|null $key + * @param string|array|null $default + * @return mixed */ - public function validated() + public function validated($key = null, $default = null) { $data = parent::validated(); @@ -73,6 +76,10 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest unset($data['limits']); } + if (!is_null($key)) { + return Arr::get($data, $key, $default); + } + return $data; } diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php index 226f69d18..a4551edcd 100644 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php +++ b/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Servers; +use Illuminate\Support\Arr; use Pterodactyl\Models\Server; class UpdateServerDetailsRequest extends ServerWriteRequest @@ -24,15 +25,20 @@ class UpdateServerDetailsRequest extends ServerWriteRequest /** * Convert the posted data into the correct format that is expected * by the application. + * + * @param string|null $key + * @param string|array|null $default */ - public function validated(): array + public function validated($key = null, $default = null) { - return [ + $data = [ 'external_id' => $this->input('external_id'), 'name' => $this->input('name'), 'owner_id' => $this->input('user'), 'description' => $this->input('description'), ]; + + return is_null($key) ? $data : Arr::get($data, $key, $default); } /** diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php index 9b254d047..d07cffd03 100644 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php +++ b/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Application\Servers; +use Illuminate\Support\Arr; use Pterodactyl\Models\Server; use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; @@ -39,11 +40,15 @@ class UpdateServerRequest extends ApplicationApiRequest ]; } - public function validated(): array + /** + * @param string|null $key + * @param string|array|null $default + * @return mixed + */ + public function validated($key = null, $default = null) { $data = parent::validated(); - - return [ + $response = [ 'external_id' => array_get($data, 'external_id'), 'name' => array_get($data, 'name'), 'description' => array_get($data, 'description'), @@ -65,5 +70,7 @@ class UpdateServerRequest extends ApplicationApiRequest 'add_allocations' => array_get($data, 'add_allocations'), 'remove_allocations' => array_get($data, 'remove_allocations'), ]; + + return is_null($key) ? $response : Arr::get($response, $key, $default); } } diff --git a/app/Models/Node.php b/app/Models/Node.php index 51af2697c..740140898 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -18,6 +18,11 @@ class Node extends Model */ public const RESOURCE_NAME = 'node'; + /** + * The default location of server files on the Wings instance. + */ + final public const DEFAULT_DAEMON_BASE = '/var/lib/pterodactyl/volumes'; + public const DAEMON_TOKEN_ID_LENGTH = 16; public const DAEMON_TOKEN_LENGTH = 64; @@ -104,7 +109,7 @@ class Node extends Model 'behind_proxy' => false, 'memory_overallocate' => 0, 'disk_overallocate' => 0, - 'daemon_base' => '/var/lib/pterodactyl/volumes', + 'daemon_base' => self::DEFAULT_DAEMON_BASE, 'maintenance_mode' => false, ];