2020-03-22 18:15:38 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-03-22 18:15:38 -07:00
|
|
|
namespace Pterodactyl\Http\Requests\Api\Client\Account;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Closure;
|
2022-06-18 14:21:20 -04:00
|
|
|
use Illuminate\Validation\Validator;
|
2026-10-11 07:53:18 -04:00
|
|
|
use Pterodactyl\Actions\Api\CreateAccountApiKey;
|
2020-03-22 18:15:38 -07:00
|
|
|
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
2026-10-11 10:00:29 -04:00
|
|
|
use Pterodactyl\Validation\Concerns\ValidatesAllowedIps;
|
2020-03-22 18:15:38 -07:00
|
|
|
|
|
|
|
|
class StoreApiKeyRequest extends ClientApiRequest
|
|
|
|
|
{
|
2026-10-11 07:53:18 -04:00
|
|
|
use ValidatesAllowedIps;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return ValidationRules
|
|
|
|
|
*/
|
2020-03-22 18:15:38 -07:00
|
|
|
public function rules(): array
|
|
|
|
|
{
|
2026-10-11 07:53:18 -04:00
|
|
|
return CreateAccountApiKey::rules();
|
2020-03-22 18:15:38 -07:00
|
|
|
}
|
2020-08-17 19:48:51 -07:00
|
|
|
|
|
|
|
|
/**
|
2022-06-18 14:21:20 -04:00
|
|
|
* Check that each of the values entered is actually valid.
|
2026-10-11 07:53:18 -04:00
|
|
|
*
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return list<Closure(Validator): void>
|
|
|
|
|
*/
|
|
|
|
|
public function after(): array
|
2020-08-17 19:48:51 -07:00
|
|
|
{
|
2026-10-11 07:53:18 -04:00
|
|
|
return [self::validateAllowedIps(...)];
|
|
|
|
|
}
|
2026-10-05 18:10:18 -04:00
|
|
|
|
2026-10-11 07:53:18 -04:00
|
|
|
/**
|
|
|
|
|
* The validated IP addresses and CIDR ranges the key may be used from, or null when
|
|
|
|
|
* none were sent.
|
|
|
|
|
*
|
|
|
|
|
* @return list<string>|null
|
|
|
|
|
*/
|
|
|
|
|
public function allowedIps(): ?array
|
|
|
|
|
{
|
|
|
|
|
$validated = $this->safe();
|
|
|
|
|
if (! $validated->filled('allowed_ips')) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-10-07 22:24:12 +05:45
|
|
|
|
2026-10-11 07:53:18 -04:00
|
|
|
return array_map(fn (int|string $key): string => $validated->string('allowed_ips.'.$key)->toString(), array_keys($validated->array('allowed_ips')));
|
2020-08-17 19:48:51 -07:00
|
|
|
}
|
2020-03-22 18:15:38 -07:00
|
|
|
}
|