2017-08-05 22:20:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Nodes;
|
|
|
|
|
2020-04-17 00:47:53 +00:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2020-04-10 22:15:38 +00:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Pterodactyl\Models\Node;
|
|
|
|
use Illuminate\Encryption\Encrypter;
|
2017-08-05 22:20:07 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class NodeCreationService
|
2017-08-05 22:20:07 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
2020-04-10 22:15:38 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Encryption\Encrypter
|
|
|
|
*/
|
|
|
|
private $encrypter;
|
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
/**
|
|
|
|
* CreationService constructor.
|
|
|
|
*
|
2020-04-10 22:15:38 +00:00
|
|
|
* @param \Illuminate\Encryption\Encrypter $encrypter
|
2017-08-05 22:20:07 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
|
|
|
|
*/
|
2020-04-10 22:15:38 +00:00
|
|
|
public function __construct(Encrypter $encrypter, NodeRepositoryInterface $repository)
|
2017-08-05 22:20:07 +00:00
|
|
|
{
|
|
|
|
$this->repository = $repository;
|
2020-04-10 22:15:38 +00:00
|
|
|
$this->encrypter = $encrypter;
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new node on the panel.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param array $data
|
2017-08-05 22:20:07 +00:00
|
|
|
* @return \Pterodactyl\Models\Node
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
*/
|
|
|
|
public function handle(array $data)
|
|
|
|
{
|
2020-04-17 00:47:53 +00:00
|
|
|
$data['uuid'] = Uuid::uuid4()->toString();
|
2020-04-12 02:49:56 +00: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 22:20:07 +00:00
|
|
|
|
2020-04-10 22:15:38 +00:00
|
|
|
return $this->repository->create($data, true, true);
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
}
|