Finish API routes for users.
This commit is contained in:
parent
97773300ed
commit
c071efd008
5 changed files with 61 additions and 16 deletions
|
@ -25,6 +25,7 @@
|
|||
namespace Pterodactyl\Repositories\Daemon;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class CommandRepository
|
||||
|
@ -60,20 +61,20 @@ class CommandRepository
|
|||
{
|
||||
// We don't use the user's specific daemon secret here since we
|
||||
// are assuming that a call to this function has been validated.
|
||||
// Additionally not all calls to this will be from a logged in user.
|
||||
// (e.g. task queue or API)
|
||||
try {
|
||||
$response = $this->server->node->guzzleClient([
|
||||
'X-Access-Token' => $this->server->daemonSecret,
|
||||
'X-Access-Server' => $this->server->uuid,
|
||||
])->request('POST', '/server/command', ['json' => ['command' => $command]]);
|
||||
$response = $this->server->guzzleClient()->request('PUT', '/server/command', [
|
||||
'http_errors' => false,
|
||||
'json' => [
|
||||
'command' => $command,
|
||||
],
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
|
||||
throw new DisplayException('Command sending responded with a non-200 error code.');
|
||||
throw new DisplayException('Command sending responded with a non-200 error code (HTTP/' . $response->getStatusCode() . ').');
|
||||
}
|
||||
|
||||
return $response->getBody();
|
||||
} catch (\Exception $ex) {
|
||||
} catch (ConnectException $ex) {
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
namespace Pterodactyl\Repositories\Daemon;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class PowerRepository
|
||||
|
@ -60,20 +61,20 @@ class PowerRepository
|
|||
{
|
||||
// We don't use the user's specific daemon secret here since we
|
||||
// are assuming that a call to this function has been validated.
|
||||
// Additionally not all calls to this will be from a logged in user.
|
||||
// (e.g. task queue or API)
|
||||
try {
|
||||
$response = $this->server->node->guzzleClient([
|
||||
'X-Access-Token' => $this->server->daemonSecret,
|
||||
'X-Access-Server' => $this->server->uuid,
|
||||
])->request('PUT', '/server/power', ['json' => ['action' => $action]]);
|
||||
$response = $this->server->guzzleClient()->request('PUT', '/server/power', [
|
||||
'http_errors' => false,
|
||||
'json' => [
|
||||
'action' => $action,
|
||||
],
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
|
||||
throw new DisplayException('Power status responded with a non-200 error code.');
|
||||
throw new DisplayException('Power toggle endpoint responded with a non-200 error code (HTTP/' . $response->getStatusCode() . ').');
|
||||
}
|
||||
|
||||
return $response->getBody();
|
||||
} catch (\Exception $ex) {
|
||||
} catch (ConnectException $ex) {
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue