Add nests & eggs
Cleanup middleware handling and parameters on controllers...
This commit is contained in:
parent
de07b3cc7f
commit
8afced3410
26 changed files with 737 additions and 446 deletions
150
app/Transformers/Api/Application/EggTransformer.php
Normal file
150
app/Transformers/Api/Application/EggTransformer.php
Normal file
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class EggTransformer extends BaseTransformer
|
||||
{
|
||||
/**
|
||||
* Relationships that can be loaded onto this transformation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'nest', 'servers', 'config', 'script',
|
||||
];
|
||||
|
||||
/**
|
||||
* Return the resource name for the JSONAPI output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceName(): string
|
||||
{
|
||||
return Egg::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an Egg model into a representation that can be consumed by
|
||||
* the application api.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Egg $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'uuid' => $model->uuid,
|
||||
'nest' => $model->nest_id,
|
||||
'author' => $model->author,
|
||||
'description' => $model->description,
|
||||
'docker_image' => $model->docker_image,
|
||||
'config' => [
|
||||
'files' => json_decode($model->config_files),
|
||||
'startup' => json_decode($model->config_startup),
|
||||
'stop' => $model->config_stop,
|
||||
'logs' => json_decode($model->config_logs),
|
||||
'extends' => $model->config_from,
|
||||
],
|
||||
'startup' => $model->startup,
|
||||
'script' => [
|
||||
'privileged' => $model->script_is_privileged,
|
||||
'install' => $model->script_install,
|
||||
'entry' => $model->script_entry,
|
||||
'container' => $model->script_container,
|
||||
'extends' => $model->copy_script_from,
|
||||
],
|
||||
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
||||
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the Nest relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeNest(Egg $model)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_NESTS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('nest');
|
||||
|
||||
return $this->item($model->getRelation('nest'), $this->makeTransformer(NestTransformer::class), Nest::RESOURCE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the Servers relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeServers(Egg $model)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('servers');
|
||||
|
||||
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Include more detailed information about the configuration if this Egg is
|
||||
* extending another.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeConfig(Egg $model)
|
||||
{
|
||||
if (is_null($model->config_from)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('configFrom');
|
||||
|
||||
return $this->item($model, function (Egg $model) {
|
||||
return [
|
||||
'files' => json_decode($model->inherit_config_files),
|
||||
'startup' => json_decode($model->inherit_config_startup),
|
||||
'stop' => $model->inherit_config_stop,
|
||||
'logs' => json_decode($model->inherit_config_logs),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Include more detailed information about the script configuration if the
|
||||
* Egg is extending another.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeScript(Egg $model)
|
||||
{
|
||||
if (is_null($model->copy_script_from)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('scriptFrom');
|
||||
|
||||
return $this->item($model, function (Egg $model) {
|
||||
return [
|
||||
'privileged' => $model->script_is_privileged,
|
||||
'install' => $model->copy_script_install,
|
||||
'entry' => $model->copy_script_entry,
|
||||
'container' => $model->copy_script_container,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
63
app/Transformers/Api/Application/NestTransformer.php
Normal file
63
app/Transformers/Api/Application/NestTransformer.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class NestTransformer extends BaseTransformer
|
||||
{
|
||||
/**
|
||||
* Relationships that can be loaded onto this transformation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'eggs', 'servers',
|
||||
];
|
||||
|
||||
/**
|
||||
* Return the resource name for the JSONAPI output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceName(): string
|
||||
{
|
||||
return Nest::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Nest model into a representation that can be consumed by the
|
||||
* application API.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Nest $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Nest $model)
|
||||
{
|
||||
$response = $model->toArray();
|
||||
|
||||
$response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at);
|
||||
$response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the Eggs relationship on the given Nest model transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Nest $model
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeEggs(Nest $model)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('eggs');
|
||||
|
||||
return $this->collection($model->getRelation('eggs'), $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Transformers\Admin;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Illuminate\Http\Request;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class OptionTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* List of resources that can be included.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'service',
|
||||
'packs',
|
||||
'servers',
|
||||
'variables',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Illuminate Request object if provided.
|
||||
*
|
||||
* @var \Illuminate\Http\Request|bool
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Setup request object for transformer.
|
||||
*
|
||||
* @param \Illuminate\Http\Request|bool $request
|
||||
*/
|
||||
public function __construct($request = false)
|
||||
{
|
||||
if (! $request instanceof Request && $request !== false) {
|
||||
throw new DisplayException('Request passed to constructor must be of type Request or false.');
|
||||
}
|
||||
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a generic transformed service option array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Egg $option)
|
||||
{
|
||||
return $option->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parent service for this service option.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeService(Egg $option)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('service-view')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->item($option->service, new ServiceTransformer($this->request), 'service');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the packs associated with this service option.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includePacks(Egg $option)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('pack-list')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->collection($option->packs, new PackTransformer($this->request), 'pack');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the servers associated with this service option.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeServers(Egg $option)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('server-list')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->collection($option->servers, new ServerTransformer($this->request), 'server');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the variables for this service option.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeVariables(Egg $option)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('option-view')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->collection($option->variables, new ServiceVariableTransformer($this->request), 'variable');
|
||||
}
|
||||
}
|
|
@ -75,7 +75,6 @@ class ServerDatabaseTransformer extends BaseTransformer
|
|||
{
|
||||
return $this->item($model, function (Database $model) {
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'password' => $this->encrypter->decrypt($model->password),
|
||||
];
|
||||
}, 'database_password');
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Transformers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class ServiceTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* List of resources that can be included.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'options',
|
||||
'servers',
|
||||
'packs',
|
||||
];
|
||||
|
||||
/**
|
||||
* The Illuminate Request object if provided.
|
||||
*
|
||||
* @var \Illuminate\Http\Request|bool
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Setup request object for transformer.
|
||||
*
|
||||
* @param \Illuminate\Http\Request|bool $request
|
||||
*/
|
||||
public function __construct($request = false)
|
||||
{
|
||||
if (! $request instanceof Request && $request !== false) {
|
||||
throw new DisplayException('Request passed to constructor must be of type Request or false.');
|
||||
}
|
||||
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a generic transformed service array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Nest $service)
|
||||
{
|
||||
return $service->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the the service options.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeOptions(Nest $service)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('option-list')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->collection($service->options, new OptionTransformer($this->request), 'option');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the servers associated with this service.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeServers(Nest $service)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('server-list')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->collection($service->servers, new ServerTransformer($this->request), 'server');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the packs associated with this service.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includePacks(Nest $service)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('pack-list')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->collection($service->packs, new PackTransformer($this->request), 'pack');
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Transformers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class ServiceVariableTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* List of resources that can be included.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['variables'];
|
||||
|
||||
/**
|
||||
* The Illuminate Request object if provided.
|
||||
*
|
||||
* @var \Illuminate\Http\Request|bool
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Setup request object for transformer.
|
||||
*
|
||||
* @param \Illuminate\Http\Request|bool $request
|
||||
*/
|
||||
public function __construct($request = false)
|
||||
{
|
||||
if (! $request instanceof Request && $request !== false) {
|
||||
throw new DisplayException('Request passed to constructor must be of type Request or false.');
|
||||
}
|
||||
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a generic transformed server variable array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(EggVariable $variable)
|
||||
{
|
||||
return $variable->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the server variables associated with this variable.
|
||||
*
|
||||
* @return \Leauge\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeVariables(EggVariable $variable)
|
||||
{
|
||||
if ($this->request && ! $this->request->apiKeyHasPermission('server-view')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->collection($variable->serverVariable, new ServerVariableTransformer($this->request), 'server_variable');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue