Deprecate old way of using repositories for daemon things
This commit is contained in:
parent
a9976c723e
commit
161e0f6165
17 changed files with 178 additions and 65 deletions
88
app/Repositories/Wings/DaemonRepository.php
Normal file
88
app/Repositories/Wings/DaemonRepository.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?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.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $application
|
||||
*/
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
$this->app = $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the server model this request is stemming from.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @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.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @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.
|
||||
*
|
||||
* @param array $headers
|
||||
* @return \GuzzleHttp\Client
|
||||
*/
|
||||
public function getHttpClient(array $headers = []): Client
|
||||
{
|
||||
Assert::isInstanceOf(Node::class, $this->node);
|
||||
|
||||
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, [
|
||||
'Authorization' => 'Bearer ' . $this->node->daemonSecret,
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
Reference in a new issue