Deprecate old way of using repositories for daemon things
This commit is contained in:
parent
a9976c723e
commit
161e0f6165
17 changed files with 178 additions and 65 deletions
|
@ -12,7 +12,7 @@ namespace Pterodactyl\Console\Commands\Server;
|
||||||
use Webmozart\Assert\Assert;
|
use Webmozart\Assert\Assert;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use Pterodactyl\Repositories\Wings\WingsServerRepository;
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||||
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class BulkReinstallActionCommand extends Command
|
||||||
protected $description = 'Reinstall a single server, all servers on a node, or all servers on the panel.';
|
protected $description = 'Reinstall a single server, all servers on a node, or all servers on the panel.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Repositories\Wings\WingsServerRepository
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
|
@ -48,12 +48,12 @@ class BulkReinstallActionCommand extends Command
|
||||||
/**
|
/**
|
||||||
* BulkReinstallActionCommand constructor.
|
* BulkReinstallActionCommand constructor.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Repositories\Wings\WingsServerRepository $daemonRepository
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonRepository
|
||||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
WingsServerRepository $daemonRepository,
|
DaemonServerRepository $daemonRepository,
|
||||||
ServerConfigurationStructureService $configurationStructureService,
|
ServerConfigurationStructureService $configurationStructureService,
|
||||||
ServerRepositoryInterface $repository
|
ServerRepositoryInterface $repository
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Pterodactyl\Console\Commands\Server;
|
||||||
use Webmozart\Assert\Assert;
|
use Webmozart\Assert\Assert;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use Pterodactyl\Repositories\Wings\WingsServerRepository;
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||||
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class RebuildServerCommand extends Command
|
||||||
protected $configurationStructureService;
|
protected $configurationStructureService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Repositories\Wings\WingsServerRepository
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||||
*/
|
*/
|
||||||
protected $daemonRepository;
|
protected $daemonRepository;
|
||||||
|
|
||||||
|
@ -48,12 +48,12 @@ class RebuildServerCommand extends Command
|
||||||
/**
|
/**
|
||||||
* RebuildServerCommand constructor.
|
* RebuildServerCommand constructor.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Repositories\Wings\WingsServerRepository $daemonRepository
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonRepository
|
||||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
WingsServerRepository $daemonRepository,
|
DaemonServerRepository $daemonRepository,
|
||||||
ServerConfigurationStructureService $configurationStructureService,
|
ServerConfigurationStructureService $configurationStructureService,
|
||||||
ServerRepositoryInterface $repository
|
ServerRepositoryInterface $repository
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -6,6 +6,9 @@ use GuzzleHttp\Client;
|
||||||
use Pterodactyl\Models\Node;
|
use Pterodactyl\Models\Node;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
interface BaseRepositoryInterface
|
interface BaseRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,9 @@ namespace Pterodactyl\Contracts\Repository\Daemon;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
interface CommandRepositoryInterface extends BaseRepositoryInterface
|
interface CommandRepositoryInterface extends BaseRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,9 @@ namespace Pterodactyl\Contracts\Repository\Daemon;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
interface ConfigurationRepositoryInterface extends BaseRepositoryInterface
|
interface ConfigurationRepositoryInterface extends BaseRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,9 @@ namespace Pterodactyl\Contracts\Repository\Daemon;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
interface FileRepositoryInterface extends BaseRepositoryInterface
|
interface FileRepositoryInterface extends BaseRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,9 @@ namespace Pterodactyl\Contracts\Repository\Daemon;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
interface PowerRepositoryInterface extends BaseRepositoryInterface
|
interface PowerRepositoryInterface extends BaseRepositoryInterface
|
||||||
{
|
{
|
||||||
const SIGNAL_START = 'start';
|
const SIGNAL_START = 'start';
|
||||||
|
|
|
@ -4,6 +4,9 @@ namespace Pterodactyl\Contracts\Repository\Daemon;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
interface ServerRepositoryInterface extends BaseRepositoryInterface
|
interface ServerRepositoryInterface extends BaseRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,24 +3,24 @@
|
||||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||||
|
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Pterodactyl\Repositories\Wings\WingsServerRepository;
|
|
||||||
use Pterodactyl\Transformers\Api\Client\StatsTransformer;
|
use Pterodactyl\Transformers\Api\Client\StatsTransformer;
|
||||||
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||||
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
||||||
|
|
||||||
class ResourceUtilizationController extends ClientApiController
|
class ResourceUtilizationController extends ClientApiController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Repositories\Wings\WingsServerRepository
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||||
*/
|
*/
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ResourceUtilizationController constructor.
|
* ResourceUtilizationController constructor.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Repositories\Wings\WingsServerRepository $repository
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $repository
|
||||||
*/
|
*/
|
||||||
public function __construct(WingsServerRepository $repository)
|
public function __construct(DaemonServerRepository $repository)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
|
|
@ -3,28 +3,27 @@
|
||||||
namespace Pterodactyl\Providers;
|
namespace Pterodactyl\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Pterodactyl\Repositories\Wings\FileRepository;
|
|
||||||
use Pterodactyl\Repositories\Daemon\PowerRepository;
|
|
||||||
use Pterodactyl\Repositories\Eloquent\EggRepository;
|
use Pterodactyl\Repositories\Eloquent\EggRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\NestRepository;
|
use Pterodactyl\Repositories\Eloquent\NestRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\PackRepository;
|
use Pterodactyl\Repositories\Eloquent\PackRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\TaskRepository;
|
use Pterodactyl\Repositories\Eloquent\TaskRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\UserRepository;
|
use Pterodactyl\Repositories\Eloquent\UserRepository;
|
||||||
use Pterodactyl\Repositories\Daemon\CommandRepository;
|
|
||||||
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
|
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\SessionRepository;
|
use Pterodactyl\Repositories\Eloquent\SessionRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
||||||
|
use Pterodactyl\Repositories\Wings\DaemonFileRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
|
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
|
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
|
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
|
||||||
|
use Pterodactyl\Repositories\Wings\DaemonPowerRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\DaemonKeyRepository;
|
use Pterodactyl\Repositories\Eloquent\DaemonKeyRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\PermissionRepository;
|
use Pterodactyl\Repositories\Eloquent\PermissionRepository;
|
||||||
|
use Pterodactyl\Repositories\Wings\DaemonCommandRepository;
|
||||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||||
use Pterodactyl\Repositories\Daemon\ConfigurationRepository;
|
|
||||||
use Pterodactyl\Repositories\Eloquent\EggVariableRepository;
|
use Pterodactyl\Repositories\Eloquent\EggVariableRepository;
|
||||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||||
|
@ -41,6 +40,7 @@ use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
||||||
|
use Pterodactyl\Repositories\Wings\DaemonConfigurationRepository;
|
||||||
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\PermissionRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\PermissionRepositoryInterface;
|
||||||
|
@ -51,7 +51,7 @@ use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
|
||||||
use Pterodactyl\Repositories\Wings\WingsServerRepository as DaemonServerRepository;
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository as DaemonServerRepository;
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||||
|
|
||||||
class RepositoryServiceProvider extends ServiceProvider
|
class RepositoryServiceProvider extends ServiceProvider
|
||||||
|
@ -84,10 +84,10 @@ class RepositoryServiceProvider extends ServiceProvider
|
||||||
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
|
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
|
||||||
|
|
||||||
// Daemon Repositories
|
// Daemon Repositories
|
||||||
$this->app->bind(ConfigurationRepositoryInterface::class, ConfigurationRepository::class);
|
$this->app->bind(ConfigurationRepositoryInterface::class, DaemonConfigurationRepository::class);
|
||||||
$this->app->bind(CommandRepositoryInterface::class, CommandRepository::class);
|
$this->app->bind(CommandRepositoryInterface::class, DaemonCommandRepository::class);
|
||||||
$this->app->bind(DaemonServerRepositoryInterface::class, DaemonServerRepository::class);
|
$this->app->bind(DaemonServerRepositoryInterface::class, DaemonServerRepository::class);
|
||||||
$this->app->bind(FileRepositoryInterface::class, FileRepository::class);
|
$this->app->bind(FileRepositoryInterface::class, DaemonFileRepository::class);
|
||||||
$this->app->bind(PowerRepositoryInterface::class, PowerRepository::class);
|
$this->app->bind(PowerRepositoryInterface::class, DaemonPowerRepository::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Repositories\Wings;
|
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
|
||||||
use Pterodactyl\Repositories\Daemon\BaseRepository;
|
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\BaseRepositoryInterface;
|
|
||||||
|
|
||||||
abstract class BaseWingsRepository extends BaseRepository implements BaseRepositoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return an instance of the Guzzle HTTP Client to be used for requests.
|
|
||||||
*
|
|
||||||
* @param array $headers
|
|
||||||
* @return \GuzzleHttp\Client
|
|
||||||
*/
|
|
||||||
public function getHttpClient(array $headers = []): Client
|
|
||||||
{
|
|
||||||
// We're just going to extend the parent client here since that logic is already quite
|
|
||||||
// sound and does everything we need it to aside from provide the correct base URL
|
|
||||||
// and authentication headers.
|
|
||||||
$client = parent::getHttpClient($headers);
|
|
||||||
|
|
||||||
return new Client(array_merge($client->getConfig(), [
|
|
||||||
'base_uri' => $this->getNode()->getConnectionAddress(),
|
|
||||||
'headers' => [
|
|
||||||
'Authorization' => 'Bearer ' . ($this->getToken() ?? $this->getNode()->daemonSecret),
|
|
||||||
'Accept' => 'application/json',
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
],
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
|
7
app/Repositories/Wings/DaemonCommandRepository.php
Normal file
7
app/Repositories/Wings/DaemonCommandRepository.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Repositories\Wings;
|
||||||
|
|
||||||
|
class DaemonCommandRepository extends DaemonRepository
|
||||||
|
{
|
||||||
|
}
|
7
app/Repositories/Wings/DaemonConfigurationRepository.php
Normal file
7
app/Repositories/Wings/DaemonConfigurationRepository.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Repositories\Wings;
|
||||||
|
|
||||||
|
class DaemonConfigurationRepository extends DaemonRepository
|
||||||
|
{
|
||||||
|
}
|
|
@ -4,11 +4,12 @@ namespace Pterodactyl\Repositories\Wings;
|
||||||
|
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
use Pterodactyl\Models\Server;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException;
|
use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException;
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
|
|
||||||
|
|
||||||
class FileRepository extends BaseWingsRepository implements FileRepositoryInterface
|
class DaemonFileRepository extends DaemonRepository
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Return stat information for a given file.
|
* Return stat information for a given file.
|
||||||
|
@ -36,8 +37,10 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function getContent(string $path, int $notLargerThan = null): string
|
public function getContent(string $path, int $notLargerThan = null): string
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
$response = $this->getHttpClient()->get(
|
$response = $this->getHttpClient()->get(
|
||||||
sprintf('/api/servers/%s/files/contents', $this->getServer()->uuid),
|
sprintf('/api/servers/%s/files/contents', $this->server->uuid),
|
||||||
[
|
[
|
||||||
'query' => ['file' => $path],
|
'query' => ['file' => $path],
|
||||||
]
|
]
|
||||||
|
@ -66,8 +69,10 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function putContent(string $path, string $content): ResponseInterface
|
public function putContent(string $path, string $content): ResponseInterface
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
return $this->getHttpClient()->post(
|
return $this->getHttpClient()->post(
|
||||||
sprintf('/api/servers/%s/files/write', $this->getServer()->uuid),
|
sprintf('/api/servers/%s/files/write', $this->server->uuid),
|
||||||
[
|
[
|
||||||
'query' => ['file' => $path],
|
'query' => ['file' => $path],
|
||||||
'body' => $content,
|
'body' => $content,
|
||||||
|
@ -85,8 +90,10 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function getDirectory(string $path): array
|
public function getDirectory(string $path): array
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
$response = $this->getHttpClient()->get(
|
$response = $this->getHttpClient()->get(
|
||||||
sprintf('/api/servers/%s/files/list-directory', $this->getServer()->uuid),
|
sprintf('/api/servers/%s/files/list-directory', $this->server->uuid),
|
||||||
[
|
[
|
||||||
'query' => ['directory' => $path],
|
'query' => ['directory' => $path],
|
||||||
]
|
]
|
||||||
|
@ -104,8 +111,10 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function createDirectory(string $name, string $path): ResponseInterface
|
public function createDirectory(string $name, string $path): ResponseInterface
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
return $this->getHttpClient()->post(
|
return $this->getHttpClient()->post(
|
||||||
sprintf('/api/servers/%s/files/create-directory', $this->getServer()->uuid),
|
sprintf('/api/servers/%s/files/create-directory', $this->server->uuid),
|
||||||
[
|
[
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
@ -124,8 +133,10 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function renameFile(string $from, string $to): ResponseInterface
|
public function renameFile(string $from, string $to): ResponseInterface
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
return $this->getHttpClient()->put(
|
return $this->getHttpClient()->put(
|
||||||
sprintf('/api/servers/%s/files/rename', $this->getServer()->uuid),
|
sprintf('/api/servers/%s/files/rename', $this->server->uuid),
|
||||||
[
|
[
|
||||||
'json' => [
|
'json' => [
|
||||||
'rename_from' => $from,
|
'rename_from' => $from,
|
||||||
|
@ -143,8 +154,10 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function copyFile(string $location): ResponseInterface
|
public function copyFile(string $location): ResponseInterface
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
return $this->getHttpClient()->post(
|
return $this->getHttpClient()->post(
|
||||||
sprintf('/api/servers/%s/files/copy', $this->getServer()->uuid),
|
sprintf('/api/servers/%s/files/copy', $this->server->uuid),
|
||||||
[
|
[
|
||||||
'json' => [
|
'json' => [
|
||||||
'location' => $location,
|
'location' => $location,
|
||||||
|
@ -161,8 +174,10 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function deleteFile(string $location): ResponseInterface
|
public function deleteFile(string $location): ResponseInterface
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
return $this->getHttpClient()->post(
|
return $this->getHttpClient()->post(
|
||||||
sprintf('/api/servers/%s/files/delete', $this->getServer()->uuid),
|
sprintf('/api/servers/%s/files/delete', $this->server->uuid),
|
||||||
[
|
[
|
||||||
'json' => [
|
'json' => [
|
||||||
'location' => $location,
|
'location' => $location,
|
7
app/Repositories/Wings/DaemonPowerRepository.php
Normal file
7
app/Repositories/Wings/DaemonPowerRepository.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Repositories\Wings;
|
||||||
|
|
||||||
|
class DaemonPowerRepository extends DaemonRepository
|
||||||
|
{
|
||||||
|
}
|
88
app/Repositories/Wings/DaemonRepository.php
Normal file
88
app/Repositories/Wings/DaemonRepository.php
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Repositories\Wings;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use Pterodactyl\Models\Node;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
use Pterodactyl\Models\Server;
|
||||||
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
|
|
||||||
|
abstract class DaemonRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Contracts\Foundation\Application
|
||||||
|
*/
|
||||||
|
protected $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Models\Server|null
|
||||||
|
*/
|
||||||
|
protected $server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Models\Node|null
|
||||||
|
*/
|
||||||
|
protected $node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BaseWingsRepository constructor.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Contracts\Foundation\Application $application
|
||||||
|
*/
|
||||||
|
public function __construct(Application $application)
|
||||||
|
{
|
||||||
|
$this->app = $application;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the server model this request is stemming from.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Models\Server $server
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setServer(Server $server)
|
||||||
|
{
|
||||||
|
$this->server = $server;
|
||||||
|
|
||||||
|
$this->setNode($this->server->node);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the node model this request is stemming from.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Models\Node $node
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setNode(Node $node)
|
||||||
|
{
|
||||||
|
$this->node = $node;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance of the Guzzle HTTP Client to be used for requests.
|
||||||
|
*
|
||||||
|
* @param array $headers
|
||||||
|
* @return \GuzzleHttp\Client
|
||||||
|
*/
|
||||||
|
public function getHttpClient(array $headers = []): Client
|
||||||
|
{
|
||||||
|
Assert::isInstanceOf(Node::class, $this->node);
|
||||||
|
|
||||||
|
return new Client([
|
||||||
|
'verify' => $this->app->environment('production'),
|
||||||
|
'base_uri' => $this->node->getConnectionAddress(),
|
||||||
|
'timeout' => config('pterodactyl.guzzle.timeout'),
|
||||||
|
'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
|
||||||
|
'headers' => array_merge($headers, [
|
||||||
|
'Authorization' => 'Bearer ' . $this->node->daemonSecret,
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Repositories\Wings;
|
namespace Pterodactyl\Repositories\Wings;
|
||||||
|
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
use Pterodactyl\Models\Server;
|
||||||
use GuzzleHttp\Exception\TransferException;
|
use GuzzleHttp\Exception\TransferException;
|
||||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
|
|
||||||
class WingsServerRepository extends BaseWingsRepository
|
class DaemonServerRepository extends DaemonRepository
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns details about a server from the Daemon instance.
|
* Returns details about a server from the Daemon instance.
|
||||||
|
@ -15,9 +17,11 @@ class WingsServerRepository extends BaseWingsRepository
|
||||||
*/
|
*/
|
||||||
public function getDetails(): array
|
public function getDetails(): array
|
||||||
{
|
{
|
||||||
|
Assert::isInstanceOf(Server::class, $this->server);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->getHttpClient()->get(
|
$response = $this->getHttpClient()->get(
|
||||||
sprintf('/api/servers/%s', $this->getServer()->uuid)
|
sprintf('/api/servers/%s', $this->server->uuid)
|
||||||
);
|
);
|
||||||
} catch (TransferException $exception) {
|
} catch (TransferException $exception) {
|
||||||
throw new DaemonConnectionException($exception);
|
throw new DaemonConnectionException($exception);
|
Loading…
Reference in a new issue