Nest & Egg management working through the ACP now.

This commit is contained in:
Dane Everitt 2017-10-07 16:16:51 -05:00
parent df87ea0867
commit 6b8464ea3a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
32 changed files with 616 additions and 566 deletions

View file

@ -7,17 +7,20 @@
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Services\Options;
namespace Pterodactyl\Services\Eggs;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
class OptionConfigurationFileService
class EggConfigurationService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* OptionConfigurationFileService constructor.
* EggConfigurationService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
@ -27,7 +30,7 @@ class OptionConfigurationFileService
}
/**
* Return a service configuration file to be used by the daemon.
* Return an Egg file to be used by the Daemon.
*
* @param int|\Pterodactyl\Models\Egg $option
* @return array

View file

@ -7,15 +7,16 @@
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Services\Options;
namespace Pterodactyl\Services\Eggs;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
class OptionCreationService
// When a mommy and a daddy pterodactyl really like eachother...
class EggCreationService
{
/**
* @var \Illuminate\Contracts\Config\Repository
@ -28,7 +29,7 @@ class OptionCreationService
protected $repository;
/**
* CreationService constructor.
* EggCreationService constructor.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
@ -46,31 +47,25 @@ class OptionCreationService
* @return \Pterodactyl\Models\Egg
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
*/
public function handle(array $data): Egg
{
if (! is_null(array_get($data, 'config_from'))) {
$data['config_from'] = array_get($data, 'config_from');
if (! is_null($data['config_from'])) {
$results = $this->repository->findCountWhere([
['service_id', '=', array_get($data, 'service_id')],
['nest_id', '=', array_get($data, 'nest_id')],
['id', '=', array_get($data, 'config_from')],
]);
if ($results !== 1) {
throw new NoParentConfigurationFoundException(trans('exceptions.service.options.must_be_child'));
}
} else {
$data['config_from'] = null;
}
if (count($parts = explode(':', array_get($data, 'tag'))) > 1) {
$data['tag'] = $this->config->get('pterodactyl.service.author') . ':' . trim(array_pop($parts));
} else {
$data['tag'] = $this->config->get('pterodactyl.service.author') . ':' . trim(array_get($data, 'tag'));
}
return $this->repository->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
'author' => $this->config->get('pterodactyl.service.author'),
]), true, true);
}
}

View file

@ -7,14 +7,14 @@
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Services\Options;
namespace Pterodactyl\Services\Eggs;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\HasChildrenException;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Exceptions\Service\ServiceOption\HasChildrenException;
class OptionDeletionService
class EggDeletionService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
@ -27,7 +27,7 @@ class OptionDeletionService
protected $serverRepository;
/**
* OptionDeletionService constructor.
* EggDeletionService constructor.
*
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
@ -41,26 +41,26 @@ class OptionDeletionService
}
/**
* Delete an option from the database if it has no active servers attached to it.
* Delete an Egg from the database if it has no active servers attached to it.
*
* @param int $option
* @param int $egg
* @return int
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\HasChildrenException
* @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException
*/
public function handle(int $option): int
public function handle(int $egg): int
{
$servers = $this->serverRepository->findCountWhere([['option_id', '=', $option]]);
$servers = $this->serverRepository->findCountWhere([['egg_id', '=', $egg]]);
if ($servers > 0) {
throw new HasActiveServersException(trans('exceptions.service.options.delete_has_servers'));
throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));
}
$children = $this->repository->findCountWhere([['config_from', '=', $option]]);
$children = $this->repository->findCountWhere([['config_from', '=', $egg]]);
if ($children > 0) {
throw new HasChildrenException(trans('exceptions.service.options.has_children'));
throw new HasChildrenException(trans('exceptions.nest.egg.has_children'));
}
return $this->repository->delete($option);
return $this->repository->delete($egg);
}
}

View file

@ -7,13 +7,13 @@
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Services\Options;
namespace Pterodactyl\Services\Eggs;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
class OptionUpdateService
class EggUpdateService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
@ -21,7 +21,7 @@ class OptionUpdateService
protected $repository;
/**
* OptionUpdateService constructor.
* EggUpdateService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
@ -33,30 +33,30 @@ class OptionUpdateService
/**
* Update a service option.
*
* @param int|\Pterodactyl\Models\Egg $option
* @param int|\Pterodactyl\Models\Egg $egg
* @param array $data
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
*/
public function handle($option, array $data)
public function handle($egg, array $data)
{
if (! $option instanceof Egg) {
$option = $this->repository->find($option);
if (! $egg instanceof Egg) {
$egg = $this->repository->find($egg);
}
if (! is_null(array_get($data, 'config_from'))) {
$results = $this->repository->findCountWhere([
['service_id', '=', $option->service_id],
['nest_id', '=', $egg->nest_id],
['id', '=', array_get($data, 'config_from')],
]);
if ($results !== 1) {
throw new NoParentConfigurationFoundException(trans('exceptions.service.options.must_be_child'));
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
}
}
$this->repository->withoutFresh()->update($option->id, $data);
$this->repository->withoutFresh()->update($egg->id, $data);
}
}

View file

@ -7,13 +7,13 @@
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Services\Options;
namespace Pterodactyl\Services\Eggs\Scripts;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException;
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
class InstallScriptUpdateService
class InstallScriptService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
@ -21,7 +21,7 @@ class InstallScriptUpdateService
protected $repository;
/**
* InstallScriptUpdateService constructor.
* InstallScriptService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
@ -31,30 +31,30 @@ class InstallScriptUpdateService
}
/**
* Modify the option install script for a given service option.
* Modify the install script for a given Egg.
*
* @param int|\Pterodactyl\Models\Egg $option
* @param int|\Pterodactyl\Models\Egg $egg
* @param array $data
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
*/
public function handle($option, array $data)
public function handle($egg, array $data)
{
if (! $option instanceof Egg) {
$option = $this->repository->find($option);
if (! $egg instanceof Egg) {
$egg = $this->repository->find($egg);
}
if (! is_null(array_get($data, 'copy_script_from'))) {
if (! $this->repository->isCopiableScript(array_get($data, 'copy_script_from'), $option->service_id)) {
throw new InvalidCopyFromException(trans('exceptions.service.options.invalid_copy_id'));
if (! $this->repository->isCopiableScript(array_get($data, 'copy_script_from'), $egg->service_id)) {
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
}
}
$this->repository->withoutFresh()->update($option->id, [
$this->repository->withoutFresh()->update($egg->id, [
'script_install' => array_get($data, 'script_install'),
'script_is_privileged' => array_get($data, 'script_is_privileged'),
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
'script_entry' => array_get($data, 'script_entry'),
'script_container' => array_get($data, 'script_container'),
'copy_script_from' => array_get($data, 'copy_script_from'),

View file

@ -7,50 +7,51 @@
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Services\Variables;
namespace Pterodactyl\Services\Eggs\Variables;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
class VariableCreationService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $serviceOptionRepository;
protected $eggRepository;
/**
* @var \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
*/
protected $serviceVariableRepository;
protected $variableRepository;
/**
* VariableCreationService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $variableRepository
*/
public function __construct(
EggRepositoryInterface $serviceOptionRepository,
ServiceVariableRepositoryInterface $serviceVariableRepository
EggRepositoryInterface $eggRepository,
EggVariableRepositoryInterface $variableRepository
) {
$this->serviceOptionRepository = $serviceOptionRepository;
$this->serviceVariableRepository = $serviceVariableRepository;
$this->eggRepository = $eggRepository;
$this->variableRepository = $variableRepository;
}
/**
* Create a new variable for a given service option.
* Create a new variable for a given Egg.
*
* @param int|\Pterodactyl\Models\Egg $option
* @param array $data
* @param int $egg
* @param array $data
* @return \Pterodactyl\Models\EggVariable
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
*/
public function handle($option, array $data)
public function handle(int $egg, array $data): EggVariable
{
if ($option instanceof Egg) {
$option = $option->id;
}
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) {
throw new ReservedVariableNameException(sprintf(
'Cannot use the protected name %s for this environment variable.',
@ -60,8 +61,8 @@ class VariableCreationService
$options = array_get($data, 'options', []);
return $this->serviceVariableRepository->create(array_merge([
'option_id' => $option,
return $this->variableRepository->create(array_merge([
'egg_id' => $egg,
'user_viewable' => in_array('user_viewable', $options),
'user_editable' => in_array('user_editable', $options),
], $data));

View file

@ -7,32 +7,32 @@
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Services\Variables;
namespace Pterodactyl\Services\Eggs\Variables;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
class VariableUpdateService
{
/**
* @var \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
*/
protected $repository;
/**
* VariableUpdateService constructor.
*
* @param \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface $repository
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $repository
*/
public function __construct(ServiceVariableRepositoryInterface $repository)
public function __construct(EggVariableRepositoryInterface $repository)
{
$this->repository = $repository;
}
/**
* Update a specific service variable.
* Update a specific egg variable.
*
* @param int|\Pterodactyl\Models\EggVariable $variable
* @param array $data
@ -41,7 +41,7 @@ class VariableUpdateService
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
*/
public function handle($variable, array $data)
{
@ -58,7 +58,7 @@ class VariableUpdateService
$search = $this->repository->withColumns('id')->findCountWhere([
['env_variable', '=', array_get($data, 'env_variable')],
['option_id', '=', $variable->option_id],
['egg_id', '=', $variable->egg_id],
['id', '!=', $variable->id],
]);
@ -71,9 +71,9 @@ class VariableUpdateService
$options = array_get($data, 'options', []);
return $this->repository->withoutFresh()->update($variable->id, array_merge([
return $this->repository->withoutFresh()->update($variable->id, array_merge($data, [
'user_viewable' => in_array('user_viewable', $options),
'user_editable' => in_array('user_editable', $options),
], $data));
]));
}
}