Remove deprecated function calls
This commit is contained in:
		
							parent
							
								
									38feac9f0b
								
							
						
					
					
						commit
						336234843d
					
				| @ -74,35 +74,6 @@ class Node extends Model | |||||||
|         'daemonSFTP', 'daemonListen', |         '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. |      * 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. |      * Returns the configuration in JSON format. | ||||||
|      * |      * | ||||||
| @ -194,12 +139,7 @@ class Node extends Model | |||||||
|             'keys' => [$this->daemonSecret], |             'keys' => [$this->daemonSecret], | ||||||
|         ]; |         ]; | ||||||
| 
 | 
 | ||||||
|         $json_options = JSON_UNESCAPED_SLASHES; |         return json_encode($config, ($pretty) ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : JSON_UNESCAPED_SLASHES); | ||||||
|         if ($pretty) { |  | ||||||
|             $json_options |= JSON_PRETTY_PRINT; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return json_encode($config, $json_options); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -32,14 +32,10 @@ use Pterodactyl\Exceptions\DisplayException; | |||||||
| class CommandRepository | class CommandRepository | ||||||
| { | { | ||||||
|     protected $server; |     protected $server; | ||||||
|     protected $node; |  | ||||||
|     protected $client; |  | ||||||
| 
 | 
 | ||||||
|     public function __construct($server) |     public function __construct($server) | ||||||
|     { |     { | ||||||
|         $this->server = ($server instanceof Models\Server) ? $server : Models\Server::findOrFail($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.
 |         // Additionally not all calls to this will be from a logged in user.
 | ||||||
|         // (e.g. task queue or API)
 |         // (e.g. task queue or API)
 | ||||||
|         try { |         try { | ||||||
|             $response = $this->client->request('POST', '/server/command', [ |             $response = $this->server->node->guzzleClient([ | ||||||
|                 'headers' => [ |                 'X-Access-Token' => $this->server->daemonSecret, | ||||||
|                     'X-Access-Token' => $this->server->daemonSecret, |                 'X-Access-Server' => $this->server->uuid, | ||||||
|                     'X-Access-Server' => $this->server->uuid, |             ])->request('POST', '/server/command', ['json' => ['command' => $command]]); | ||||||
|                 ], |  | ||||||
|                 'json' => [ |  | ||||||
|                     'command' => $command, |  | ||||||
|                 ], |  | ||||||
|             ]); |  | ||||||
| 
 | 
 | ||||||
|             if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |             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.'); | ||||||
|  | |||||||
| @ -31,14 +31,10 @@ use Pterodactyl\Exceptions\DisplayException; | |||||||
| class PowerRepository | class PowerRepository | ||||||
| { | { | ||||||
|     protected $server; |     protected $server; | ||||||
|     protected $node; |  | ||||||
|     protected $client; |  | ||||||
| 
 | 
 | ||||||
|     public function __construct($server) |     public function __construct($server) | ||||||
|     { |     { | ||||||
|         $this->server = ($server instanceof Models\Server) ? $server : Models\Server::findOrFail($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) |     public function do($action) | ||||||
| @ -48,15 +44,10 @@ class PowerRepository | |||||||
|         // Additionally not all calls to this will be from a logged in user.
 |         // Additionally not all calls to this will be from a logged in user.
 | ||||||
|         // (e.g. task queue or API)
 |         // (e.g. task queue or API)
 | ||||||
|         try { |         try { | ||||||
|             $response = $this->client->request('PUT', '/server/power', [ |             $response = $this->server->node->guzzleClient([ | ||||||
|                 'headers' => [ |                 'X-Access-Token' => $this->server->daemonSecret, | ||||||
|                     'X-Access-Token' => $this->server->daemonSecret, |                 'X-Access-Server' => $this->server->uuid, | ||||||
|                     'X-Access-Server' => $this->server->uuid, |             ])->request('PUT', '/server/power', ['json' => ['action' => $action]]); | ||||||
|                 ], |  | ||||||
|                 'json' => [ |  | ||||||
|                     'action' => $action, |  | ||||||
|                 ], |  | ||||||
|             ]); |  | ||||||
| 
 | 
 | ||||||
|             if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |             if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { | ||||||
|                 throw new DisplayException('Power status responded with a non-200 error code.'); |                 throw new DisplayException('Power status responded with a non-200 error code.'); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dane Everitt
						Dane Everitt