Files

51 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Http\Requests\Api\Client\Account;
2026-10-05 18:10:18 -04:00
use Closure;
use Illuminate\Validation\Validator;
2026-10-11 07:53:18 -04:00
use Pterodactyl\Actions\Api\CreateAccountApiKey;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
2026-10-11 10:00:29 -04:00
use Pterodactyl\Validation\Concerns\ValidatesAllowedIps;
class StoreApiKeyRequest extends ClientApiRequest
{
2026-10-11 07:53:18 -04:00
use ValidatesAllowedIps;
2026-10-05 18:10:18 -04:00
/**
* @return ValidationRules
*/
public function rules(): array
{
2026-10-11 07:53:18 -04:00
return CreateAccountApiKey::rules();
}
/**
* 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
{
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-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')));
}
}