Compare commits

...

1 commit

Author SHA1 Message Date
Lance Pioch
95ec595606 Remove daemon transfer repo 2022-10-20 21:38:17 -04:00
3 changed files with 35 additions and 38 deletions

View file

@ -3,18 +3,21 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers; namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Carbon\CarbonImmutable; use Carbon\CarbonImmutable;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Lcobucci\JWT\Token\Plain;
use Pterodactyl\Models\Allocation; use Pterodactyl\Models\Allocation;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\ServerTransfer; use Pterodactyl\Models\ServerTransfer;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Wings\DaemonRepository;
use Pterodactyl\Services\Nodes\NodeJWTService; use Pterodactyl\Services\Nodes\NodeJWTService;
use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Repositories\Wings\DaemonServerRepository; use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Pterodactyl\Repositories\Wings\DaemonTransferRepository;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class ServerTransferController extends Controller class ServerTransferController extends Controller
@ -26,7 +29,7 @@ class ServerTransferController extends Controller
private ConnectionInterface $connection, private ConnectionInterface $connection,
private ServerRepository $repository, private ServerRepository $repository,
private DaemonServerRepository $daemonServerRepository, private DaemonServerRepository $daemonServerRepository,
private DaemonTransferRepository $daemonTransferRepository, private DaemonRepository $daemonRepository,
private NodeJWTService $jwtService private NodeJWTService $jwtService
) { ) {
} }
@ -62,15 +65,39 @@ class ServerTransferController extends Controller
// On the daemon transfer repository, make sure to set the node after the server // On the daemon transfer repository, make sure to set the node after the server
// because setServer() tells the repository to use the server's node and not the one // because setServer() tells the repository to use the server's node and not the one
// we want to specify. // we want to specify.
$this->daemonTransferRepository $repository = $this->daemonRepository
->setServer($server) ->setServer($server)
->setNode($server->transfer->newNode) ->setNode($server->transfer->newNode);
->notify($server, $token);
$this->notify($repository, $server, $token);
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return new JsonResponse([], Response::HTTP_NO_CONTENT);
} }
/**
* @throws DaemonConnectionException
*/
private function notify(DaemonRepository $repository, Server $server, Plain $token): void
{
try {
$repository->getHttpClient()->post('/api/transfer', [
'json' => [
'server_id' => $server->uuid,
'url' => $server->node->getConnectionAddress() . "/api/servers/$server->uuid/archive",
'token' => 'Bearer ' . $token->toString(),
'server' => [
'uuid' => $server->uuid,
'start_on_completion' => false,
],
],
]);
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
/** /**
* The daemon notifies us about a transfer failure. * The daemon notifies us about a transfer failure.
* *

View file

@ -3,6 +3,9 @@
namespace Pterodactyl\Repositories\Wings; namespace Pterodactyl\Repositories\Wings;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Lcobucci\JWT\Token\Plain;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
use Pterodactyl\Models\Node; use Pterodactyl\Models\Node;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;

View file

@ -1,33 +0,0 @@
<?php
namespace Pterodactyl\Repositories\Wings;
use Lcobucci\JWT\Token\Plain;
use Pterodactyl\Models\Server;
use GuzzleHttp\Exception\GuzzleException;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class DaemonTransferRepository extends DaemonRepository
{
/**
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function notify(Server $server, Plain $token): void
{
try {
$this->getHttpClient()->post('/api/transfer', [
'json' => [
'server_id' => $server->uuid,
'url' => $server->node->getConnectionAddress() . sprintf('/api/servers/%s/archive', $server->uuid),
'token' => 'Bearer ' . $token->toString(),
'server' => [
'uuid' => $server->uuid,
'start_on_completion' => false,
],
],
]);
} catch (GuzzleException $exception) {
throw new DaemonConnectionException($exception);
}
}
}