Update demon routes to use /v1/

This commit is contained in:
Dane Everitt 2017-09-30 21:00:24 -05:00
parent 15d38ce823
commit b1834307d5
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
25 changed files with 55 additions and 67 deletions

View file

@ -30,6 +30,8 @@ use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Testing\HttpException;
use League\Fractal\Serializer\JsonApiSerializer;
use Pterodactyl\Transformers\Daemon\ApiKeyTransformer;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
class ValidateKeyController extends Controller
@ -81,7 +83,11 @@ class ValidateKeyController extends Controller
throw new HttpException(501);
}
$key = $this->daemonKeyRepository->getKeyWithServer($token);
try {
$key = $this->daemonKeyRepository->getKeyWithServer($token);
} catch (RecordNotFoundException $exception) {
throw new NotFoundHttpException;
}
return $this->fractal->item($key, $this->app->make(ApiKeyTransformer::class), 'server')
->serializeWith(JsonApiSerializer::class)

View file

@ -194,7 +194,6 @@ class OptionController extends Controller
$this->optionUpdateService->handle($option, $request->all());
$this->alert->success(trans('admin/services.options.notices.option_updated'))->flash();
} catch (NoParentConfigurationFoundException $exception) {
dd('hodor');
$this->alert->danger($exception->getMessage())->flash();
}

View file

@ -55,7 +55,7 @@ class DownloadController extends Controller
$this->cache->tags(['Server:Downloads'])->put($token, ['server' => $server->uuid, 'path' => $file], 5);
return redirect(sprintf(
'%s://%s:%s/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, $token
'%s://%s:%s/v1/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, $token
));
}
}

View file

@ -9,7 +9,6 @@
namespace Pterodactyl\Models;
use GuzzleHttp\Client;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Validable;
use Illuminate\Database\Eloquent\Model;
@ -126,22 +125,6 @@ class Node extends Model implements CleansAttributes, ValidableContract
'daemonListen' => 8080,
];
/**
* Return an instance of the Guzzle client for this specific node.
*
* @param array $headers
* @return \GuzzleHttp\Client
*/
public function guzzleClient($headers = [])
{
return new Client([
'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen),
'timeout' => config('pterodactyl.guzzle.timeout'),
'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
'headers' => $headers,
]);
}
/**
* Returns the configuration in JSON format.
*

View file

@ -141,7 +141,7 @@ class BaseRepository implements BaseRepositoryInterface
}
return new Client([
'base_uri' => sprintf('%s://%s:%s/', $this->getNode()->scheme, $this->getNode()->fqdn, $this->getNode()->daemonListen),
'base_uri' => sprintf('%s://%s:%s/v1/', $this->getNode()->scheme, $this->getNode()->fqdn, $this->getNode()->daemonListen),
'timeout' => $this->config->get('pterodactyl.guzzle.timeout'),
'connect_timeout' => $this->config->get('pterodactyl.guzzle.connect_timeout'),
'headers' => $headers,

View file

@ -21,7 +21,7 @@ class CommandRepository extends BaseRepository implements CommandRepositoryInter
{
Assert::stringNotEmpty($command, 'First argument passed to send must be a non-empty string, received %s.');
return $this->getHttpClient()->request('POST', '/server/command', [
return $this->getHttpClient()->request('POST', 'server/command', [
'json' => [
'command' => $command,
],

View file

@ -41,7 +41,7 @@ class ConfigurationRepository extends BaseRepository implements ConfigurationRep
],
];
return $this->getHttpClient()->request('PATCH', '/config', [
return $this->getHttpClient()->request('PATCH', 'config', [
'json' => array_merge($structure, $overrides),
]);
}

View file

@ -22,7 +22,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/file/stat/%s',
'server/file/stat/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -40,7 +40,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/file/f/%s',
'server/file/f/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -58,7 +58,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
return $this->getHttpClient()->request('POST', '/server/file/save', [
return $this->getHttpClient()->request('POST', 'server/file/save', [
'json' => [
'path' => rawurlencode($file['dirname'] . $file['basename']),
'content' => $content,
@ -74,7 +74,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
Assert::string($path, 'First argument passed to getDirectory must be a string, received %s.');
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/directory/%s',
'server/directory/%s',
rawurlencode($path)
));

View file

@ -27,7 +27,7 @@ class PowerRepository extends BaseRepository implements PowerRepositoryInterface
case self::SIGNAL_STOP:
case self::SIGNAL_RESTART:
case self::SIGNAL_KILL:
return $this->getHttpClient()->request('PUT', '/server/power', [
return $this->getHttpClient()->request('PUT', 'server/power', [
'json' => [
'action' => $signal,
],

View file

@ -63,7 +63,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
array_set($data, $key, $value);
}
return $this->getHttpClient()->request('POST', '/servers', [
return $this->getHttpClient()->request('POST', 'servers', [
'json' => $data,
]);
}
@ -73,7 +73,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function update(array $data)
{
return $this->getHttpClient()->request('PATCH', '/server', [
return $this->getHttpClient()->request('PATCH', 'server', [
'json' => $data,
]);
}
@ -86,10 +86,10 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
Assert::nullOrIsArray($data, 'First argument passed to reinstall must be null or an array, received %s.');
if (is_null($data)) {
return $this->getHttpClient()->request('POST', '/server/reinstall');
return $this->getHttpClient()->request('POST', 'server/reinstall');
}
return $this->getHttpClient()->request('POST', '/server/reinstall', [
return $this->getHttpClient()->request('POST', 'server/reinstall', [
'json' => $data,
]);
}
@ -99,7 +99,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function rebuild()
{
return $this->getHttpClient()->request('POST', '/server/rebuild');
return $this->getHttpClient()->request('POST', 'server/rebuild');
}
/**
@ -107,7 +107,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function suspend()
{
return $this->getHttpClient()->request('POST', '/server/suspend');
return $this->getHttpClient()->request('POST', 'server/suspend');
}
/**
@ -115,7 +115,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function unsuspend()
{
return $this->getHttpClient()->request('POST', '/server/unsuspend');
return $this->getHttpClient()->request('POST', 'server/unsuspend');
}
/**
@ -123,7 +123,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function delete()
{
return $this->getHttpClient()->request('DELETE', '/servers');
return $this->getHttpClient()->request('DELETE', 'servers');
}
/**
@ -131,7 +131,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function details()
{
return $this->getHttpClient()->request('GET', '/server');
return $this->getHttpClient()->request('GET', 'server');
}
/**
@ -141,6 +141,6 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
{
Assert::stringNotEmpty($key, 'First argument passed to revokeAccessKey must be a non-empty string, received %s.');
return $this->getHttpClient()->request('DELETE', '/keys/' . $key);
return $this->getHttpClient()->request('DELETE', 'keys/' . $key);
}
}

View file

@ -21,7 +21,7 @@ class CommandRepository extends BaseRepository implements CommandRepositoryInter
{
Assert::stringNotEmpty($command, 'First argument passed to send must be a non-empty string, received %s.');
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/command', [
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/command', [
'json' => [
'command' => $command,
],

View file

@ -25,7 +25,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/' . $this->getAccessServer() . '/file/stat/%s',
'server/' . $this->getAccessServer() . '/file/stat/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -43,7 +43,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/' . $this->getAccessServer() . '/file/f/%s',
'server/' . $this->getAccessServer() . '/file/f/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -61,7 +61,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/file/save', [
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/file/save', [
'json' => [
'path' => rawurlencode($file['dirname'] . $file['basename']),
'content' => $content,
@ -77,7 +77,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
Assert::string($path, 'First argument passed to getDirectory must be a string, received %s.');
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/' . $this->getAccessServer() . '/directory/%s',
'server/' . $this->getAccessServer() . '/directory/%s',
rawurlencode($path)
));

View file

@ -27,7 +27,7 @@ class PowerRepository extends BaseRepository implements PowerRepositoryInterface
case self::SIGNAL_STOP:
case self::SIGNAL_RESTART:
case self::SIGNAL_KILL:
return $this->getHttpClient()->request('PUT', '/server/' . $this->getAccessServer() . '/power', [
return $this->getHttpClient()->request('PUT', 'server/' . $this->getAccessServer() . '/power', [
'json' => [
'action' => $signal,
],

View file

@ -43,7 +43,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function rebuild()
{
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/rebuild');
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/rebuild');
}
/**
@ -51,7 +51,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function suspend()
{
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/suspend');
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/suspend');
}
/**
@ -59,7 +59,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function unsuspend()
{
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/unsuspend');
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/unsuspend');
}
/**
@ -67,7 +67,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function delete()
{
return $this->getHttpClient()->request('DELETE', '/server/' . $this->getAccessServer());
return $this->getHttpClient()->request('DELETE', 'server/' . $this->getAccessServer());
}
/**
@ -75,7 +75,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function details()
{
return $this->getHttpClient()->request('GET', '/server/' . $this->getAccessServer());
return $this->getHttpClient()->request('GET', 'server/' . $this->getAccessServer());
}
/**