Remove deprecated function calls

This commit is contained in:
Dane Everitt 2017-02-16 13:31:25 -05:00
parent 38feac9f0b
commit 336234843d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 9 additions and 87 deletions

View file

@ -74,35 +74,6 @@ class Node extends Model
'daemonSFTP', 'daemonListen',
];
/**
* @var array
*/
protected static $guzzle = [];
/**
* @var array
*/
protected static $nodes = [];
/**
* Returns an instance of the database object for the requested node ID.
*
* @param int $id
* @return \Illuminate\Database\Eloquent\Model
*/
public static function getByID($id)
{
// The Node is already cached.
if (array_key_exists($id, self::$nodes)) {
return self::$nodes[$id];
}
self::$nodes[$id] = self::where('id', $id)->first();
return self::$nodes[$id];
}
/**
* Return an instance of the Guzzle client for this specific node.
*
@ -119,32 +90,6 @@ class Node extends Model
]);
}
/**
* Returns a Guzzle Client for the node in question.
*
* @param int $node
* @return \GuzzleHttp\Client
* @deprecated
*/
public static function guzzleRequest($node)
{
// The Guzzle Client is cached already.
if (array_key_exists($node, self::$guzzle)) {
return self::$guzzle[$node];
}
$nodeData = self::getByID($node);
self::$guzzle[$node] = new Client([
'base_uri' => sprintf('%s://%s:%s/', $nodeData->scheme, $nodeData->fqdn, $nodeData->daemonListen),
'timeout' => 5.0,
'connect_timeout' => 3.0,
]);
return self::$guzzle[$node];
}
/**
* Returns the configuration in JSON format.
*
@ -194,12 +139,7 @@ class Node extends Model
'keys' => [$this->daemonSecret],
];
$json_options = JSON_UNESCAPED_SLASHES;
if ($pretty) {
$json_options |= JSON_PRETTY_PRINT;
}
return json_encode($config, $json_options);
return json_encode($config, ($pretty) ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : JSON_UNESCAPED_SLASHES);
}
/**

View file

@ -32,14 +32,10 @@ use Pterodactyl\Exceptions\DisplayException;
class CommandRepository
{
protected $server;
protected $node;
protected $client;
public function __construct($server)
{
$this->server = ($server instanceof Models\Server) ? $server : Models\Server::findOrFail($server);
$this->node = Models\Node::getByID($this->server->node);
$this->client = Models\Node::guzzleRequest($this->server->node);
}
/**
@ -56,15 +52,10 @@ class CommandRepository
// Additionally not all calls to this will be from a logged in user.
// (e.g. task queue or API)
try {
$response = $this->client->request('POST', '/server/command', [
'headers' => [
'X-Access-Token' => $this->server->daemonSecret,
'X-Access-Server' => $this->server->uuid,
],
'json' => [
'command' => $command,
],
]);
$response = $this->server->node->guzzleClient([
'X-Access-Token' => $this->server->daemonSecret,
'X-Access-Server' => $this->server->uuid,
])->request('POST', '/server/command', ['json' => ['command' => $command]]);
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
throw new DisplayException('Command sending responded with a non-200 error code.');

View file

@ -31,14 +31,10 @@ use Pterodactyl\Exceptions\DisplayException;
class PowerRepository
{
protected $server;
protected $node;
protected $client;
public function __construct($server)
{
$this->server = ($server instanceof Models\Server) ? $server : Models\Server::findOrFail($server);
$this->node = Models\Node::getByID($this->server->node);
$this->client = Models\Node::guzzleRequest($this->server->node);
}
public function do($action)
@ -48,15 +44,10 @@ class PowerRepository
// Additionally not all calls to this will be from a logged in user.
// (e.g. task queue or API)
try {
$response = $this->client->request('PUT', '/server/power', [
'headers' => [
'X-Access-Token' => $this->server->daemonSecret,
'X-Access-Server' => $this->server->uuid,
],
'json' => [
'action' => $action,
],
]);
$response = $this->server->node->guzzleClient([
'X-Access-Token' => $this->server->daemonSecret,
'X-Access-Server' => $this->server->uuid,
])->request('PUT', '/server/power', ['json' => ['action' => $action]]);
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
throw new DisplayException('Power status responded with a non-200 error code.');