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