Update panel to send correct service option configuration to the daemon.
This commit is contained in:
parent
1a5a1f82e7
commit
38075c6b9f
12 changed files with 282 additions and 83 deletions
|
@ -10,61 +10,29 @@
|
|||
namespace Pterodactyl\Repositories\Daemon;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Services\Servers\EnvironmentService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface as DatabaseServerRepositoryInterface;
|
||||
|
||||
class ServerRepository extends BaseRepository implements ServerRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Create a new server on the daemon for the panel.
|
||||
*
|
||||
* @param array $structure
|
||||
* @param array $overrides
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*
|
||||
* @throws \GuzzleHttp\Exception\RequestException
|
||||
*/
|
||||
public function create($id, array $overrides = [], $start = false)
|
||||
public function create(array $structure, array $overrides = []): ResponseInterface
|
||||
{
|
||||
Assert::numeric($id, 'First argument passed to create must be numeric, received %s.');
|
||||
Assert::boolean($start, 'Third argument passed to create must be boolean, received %s.');
|
||||
|
||||
$repository = $this->app->make(DatabaseServerRepositoryInterface::class);
|
||||
$environment = $this->app->make(EnvironmentService::class);
|
||||
|
||||
$server = $repository->getDataForCreation($id);
|
||||
|
||||
$data = [
|
||||
'uuid' => (string) $server->uuid,
|
||||
'user' => $server->username,
|
||||
'build' => [
|
||||
'default' => [
|
||||
'ip' => $server->allocation->ip,
|
||||
'port' => $server->allocation->port,
|
||||
],
|
||||
'ports' => $server->allocations->groupBy('ip')->map(function ($item) {
|
||||
return $item->pluck('port');
|
||||
})->toArray(),
|
||||
'env' => $environment->process($server),
|
||||
'memory' => (int) $server->memory,
|
||||
'swap' => (int) $server->swap,
|
||||
'io' => (int) $server->io,
|
||||
'cpu' => (int) $server->cpu,
|
||||
'disk' => (int) $server->disk,
|
||||
'image' => $server->image,
|
||||
],
|
||||
'service' => [
|
||||
'type' => $server->option->service->folder,
|
||||
'option' => $server->option->tag,
|
||||
'pack' => object_get($server, 'pack.uuid'),
|
||||
'skip_scripts' => $server->skip_scripts,
|
||||
],
|
||||
'rebuild' => false,
|
||||
'start_on_completion' => $start,
|
||||
];
|
||||
|
||||
// Loop through overrides.
|
||||
foreach ($overrides as $key => $value) {
|
||||
array_set($data, $key, $value);
|
||||
array_set($structure, $key, $value);
|
||||
}
|
||||
|
||||
return $this->getHttpClient()->request('POST', 'servers', [
|
||||
'json' => $data,
|
||||
'json' => $structure,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
Assert::nullOrIntegerish($server, 'First argument passed to getDataForRebuild must be null or integer, received %s.');
|
||||
Assert::nullOrIntegerish($node, 'Second argument passed to getDataForRebuild must be null or integer, received %s.');
|
||||
|
||||
$instance = $this->getBuilder()->with('node', 'option.service', 'pack');
|
||||
$instance = $this->getBuilder()->with('allocation', 'allocations', 'pack', 'option', 'node');
|
||||
|
||||
if (! is_null($server) && is_null($node)) {
|
||||
$instance = $instance->where('id', '=', $server);
|
||||
|
@ -111,9 +111,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
*/
|
||||
public function getDataForCreation($id)
|
||||
{
|
||||
$instance = $this->getBuilder()->with('allocation', 'allocations', 'pack', 'option.service')
|
||||
->find($id, $this->getColumns());
|
||||
|
||||
$instance = $this->getBuilder()->with(['allocation', 'allocations', 'pack', 'option'])->find($id, $this->getColumns());
|
||||
if (! $instance) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
|
||||
|
@ -42,18 +44,31 @@ class ServiceOptionRepository extends EloquentRepository implements ServiceOptio
|
|||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the service options and their relations to be used in the daemon API.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getAllWithCopyAttributes(): Collection
|
||||
{
|
||||
return $this->getBuilder()->with('scriptFrom', 'configFrom')->get($this->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a service option with the scriptFrom and configFrom relations loaded onto the model.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int|string $value
|
||||
* @param string $column
|
||||
* @return \Pterodactyl\Models\ServiceOption
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithCopyAttributes(int $id): ServiceOption
|
||||
public function getWithCopyAttributes($value, string $column = 'id'): ServiceOption
|
||||
{
|
||||
Assert::true((is_digit($value) || is_string($value)), 'First argument passed to getWithCopyAttributes must be an integer or string, received %s.');
|
||||
|
||||
/** @var \Pterodactyl\Models\ServiceOption $instance */
|
||||
$instance = $this->getBuilder()->with('scriptFrom', 'configFrom')->find($id, $this->getColumns());
|
||||
$instance = $this->getBuilder()->with('scriptFrom', 'configFrom')->where($column, '=', $value)->first($this->getColumns());
|
||||
if (! $instance) {
|
||||
throw new RecordNotFoundException;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue