2021-01-23 12:09:16 -08:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2021-01-23 12:09:16 -08:00
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
|
use Illuminate\Support\Facades\Date;
|
2021-01-23 12:09:16 -08:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Pterodactyl\Models\ApiKey;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\User;
|
2021-01-23 12:09:16 -08:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @extends Factory<ApiKey>
|
|
|
|
|
*/
|
2021-01-23 12:09:16 -08:00
|
|
|
class ApiKeyFactory extends Factory
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $model = ApiKey::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Define the model's default state.
|
|
|
|
|
*/
|
|
|
|
|
public function definition(): array
|
|
|
|
|
{
|
|
|
|
|
static $token;
|
|
|
|
|
|
|
|
|
|
return [
|
2026-10-05 18:10:18 -04:00
|
|
|
'user_id' => User::factory(),
|
2021-01-23 12:09:16 -08:00
|
|
|
'key_type' => ApiKey::TYPE_APPLICATION,
|
2022-05-22 19:03:51 -04:00
|
|
|
'identifier' => ApiKey::generateTokenIdentifier(ApiKey::TYPE_APPLICATION),
|
2021-07-11 11:27:15 -06:00
|
|
|
'token' => $token ?: $token = encrypt(Str::random(ApiKey::KEY_LENGTH)),
|
2021-01-23 12:09:16 -08:00
|
|
|
'allowed_ips' => null,
|
|
|
|
|
'memo' => 'Test Function Key',
|
2026-10-05 18:10:18 -04:00
|
|
|
'created_at' => Date::now(),
|
|
|
|
|
'updated_at' => Date::now(),
|
2021-01-23 12:09:16 -08:00
|
|
|
];
|
|
|
|
|
}
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Restrict the key to an example IP range for documentation purposes.
|
|
|
|
|
*/
|
|
|
|
|
public function withAllowedIps(): self
|
|
|
|
|
{
|
|
|
|
|
return $this->state([
|
|
|
|
|
'allowed_ips' => ['127.0.0.1'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
2021-01-23 12:09:16 -08:00
|
|
|
}
|