2017-08-05 23:20:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Nodes;
|
|
|
|
|
2020-04-17 01:47:53 +01:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2020-04-10 23:15:38 +01:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Pterodactyl\Models\Node;
|
2020-06-25 05:54:56 +01:00
|
|
|
use Illuminate\Contracts\Encryption\Encrypter;
|
2017-08-05 23:20:07 +01:00
|
|
|
|
2017-08-27 21:10:51 +01:00
|
|
|
class NodeCreationService
|
2017-08-05 23:20:07 +01:00
|
|
|
{
|
|
|
|
/**
|
2022-10-14 17:59:20 +01:00
|
|
|
* NodeCreationService constructor.
|
2017-08-05 23:20:07 +01:00
|
|
|
*/
|
2022-10-24 03:17:24 +01:00
|
|
|
public function __construct(private Encrypter $encrypter)
|
2017-08-05 23:20:07 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new node on the panel.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-14 17:59:20 +01:00
|
|
|
public function handle(array $data): Node
|
2017-08-05 23:20:07 +01:00
|
|
|
{
|
2020-04-17 01:47:53 +01:00
|
|
|
$data['uuid'] = Uuid::uuid4()->toString();
|
2020-04-12 03:49:56 +01:00
|
|
|
$data['daemon_token'] = $this->encrypter->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
|
|
|
|
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
|
2017-08-05 23:20:07 +01:00
|
|
|
|
2022-10-24 03:17:24 +01:00
|
|
|
/** @var Node $node */
|
|
|
|
$node = Node::query()->create($data);
|
|
|
|
|
|
|
|
return $node;
|
2017-08-05 23:20:07 +01:00
|
|
|
}
|
|
|
|
}
|