Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Wings/DaemonRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Wings;
4
5
use GuzzleHttp\Client;
6
use Pterodactyl\Models\Node;
7
use Webmozart\Assert\Assert;
8
use Pterodactyl\Models\Server;
9
use Illuminate\Contracts\Foundation\Application;
10
11
/**
12
* @method \Pterodactyl\Repositories\Wings\DaemonRepository setNode(\Pterodactyl\Models\Node $node)
13
* @method \Pterodactyl\Repositories\Wings\DaemonRepository setServer(\Pterodactyl\Models\Server $server)
14
*/
15
abstract class DaemonRepository
16
{
17
protected ?Server $server;
18
19
protected ?Node $node;
20
21
/**
22
* DaemonRepository constructor.
23
*/
24
public function __construct(protected Application $app)
25
{
26
}
27
28
/**
29
* Set the server model this request is stemming from.
30
*/
31
public function setServer(Server $server): self
32
{
33
$this->server = $server;
34
35
$this->setNode($this->server->node);
36
37
return $this;
38
}
39
40
/**
41
* Set the node model this request is stemming from.
42
*/
43
public function setNode(Node $node): self
44
{
45
$this->node = $node;
46
47
return $this;
48
}
49
50
/**
51
* Return an instance of the Guzzle HTTP Client to be used for requests.
52
*/
53
public function getHttpClient(array $headers = []): Client
54
{
55
Assert::isInstanceOf($this->node, Node::class);
56
57
return new Client([
58
'verify' => $this->app->environment('production'),
59
'base_uri' => $this->node->getConnectionAddress(),
60
'timeout' => config('pterodactyl.guzzle.timeout'),
61
'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
62
'headers' => array_merge($headers, [
63
'Authorization' => 'Bearer ' . $this->node->getDecryptedKey(),
64
'Accept' => 'application/json',
65
'Content-Type' => 'application/json',
66
]),
67
]);
68
}
69
}
70
71