mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Api\Client\Account;
|
|
|
|
use IPTools\Range;
|
|
use App\Models\ApiKey;
|
|
use Illuminate\Validation\Validator;
|
|
use App\Http\Requests\Api\Client\ClientApiRequest;
|
|
|
|
class StoreApiKeyRequest extends ClientApiRequest
|
|
{
|
|
/** @return array<array-key, string|string[]> */
|
|
public function rules(): array
|
|
{
|
|
$rules = ApiKey::getRules();
|
|
|
|
return [
|
|
'description' => $rules['memo'],
|
|
'allowed_ips' => [...$rules['allowed_ips'], 'max:50'],
|
|
'allowed_ips.*' => 'string',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Check that each of the values entered is actually valid.
|
|
*/
|
|
public function withValidator(Validator $validator): void
|
|
{
|
|
$validator->after(function (Validator $validator) {
|
|
if (!is_array($ips = $this->input('allowed_ips'))) {
|
|
return;
|
|
}
|
|
|
|
foreach ($ips as $index => $ip) {
|
|
$valid = false;
|
|
try {
|
|
$valid = Range::parse($ip)->valid();
|
|
} catch (\Exception $exception) {
|
|
if ($exception->getMessage() !== 'Invalid IP address format') {
|
|
throw $exception;
|
|
}
|
|
} finally {
|
|
$validator->errors()->addIf(!$valid, "allowed_ips.{$index}", '"' . $ip . '" is not a valid IP address or CIDR range.');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|