forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaemonRepository.php
More file actions
81 lines (68 loc) · 1.87 KB
/
DaemonRepository.php
File metadata and controls
81 lines (68 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?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
{
Assert::isInstanceOf($this->node, Node::class);
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->getDecryptedKey(),
'Accept' => 'application/json',
'Content-Type' => 'application/json',
]),
]);
}
}