2019-09-06 03:33:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Wings;
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use Pterodactyl\Models\Node;
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
|
|
|
|
|
|
abstract class DaemonRepository
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Foundation\Application
|
|
|
|
*/
|
|
|
|
protected $app;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Models\Server|null
|
|
|
|
*/
|
|
|
|
protected $server;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Models\Node|null
|
|
|
|
*/
|
|
|
|
protected $node;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BaseWingsRepository constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(Application $application)
|
|
|
|
{
|
|
|
|
$this->app = $application;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the server model this request is stemming from.
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setServer(Server $server)
|
|
|
|
{
|
|
|
|
$this->server = $server;
|
|
|
|
|
|
|
|
$this->setNode($this->server->node);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the node model this request is stemming from.
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setNode(Node $node)
|
|
|
|
{
|
|
|
|
$this->node = $node;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of the Guzzle HTTP Client to be used for requests.
|
|
|
|
*/
|
|
|
|
public function getHttpClient(array $headers = []): Client
|
|
|
|
{
|
2019-09-06 04:16:36 +00:00
|
|
|
Assert::isInstanceOf($this->node, Node::class);
|
2019-09-06 03:33:27 +00:00
|
|
|
|
|
|
|
return new Client([
|
|
|
|
'verify' => $this->app->environment('production'),
|
|
|
|
'base_uri' => $this->node->getConnectionAddress(),
|
|
|
|
'timeout' => config('pterodactyl.guzzle.timeout'),
|
|
|
|
'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
|
|
|
|
'headers' => array_merge($headers, [
|
2020-04-10 22:15:38 +00:00
|
|
|
'Authorization' => 'Bearer ' . $this->node->getDecryptedKey(),
|
2019-09-06 03:33:27 +00:00
|
|
|
'Accept' => 'application/json',
|
|
|
|
'Content-Type' => 'application/json',
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|