app = $app; $this->nodeRepository = $nodeRepository; } /** * Set the node model to be used for this daemon connection. * * @param \Pterodactyl\Models\Node $node * @return $this */ public function setNode(Node $node) { $this->node = $node; return $this; } /** * Return the node model being used. * * @return \Pterodactyl\Models\Node */ public function getNode(): Node { return $this->node; } /** * Set the Server model to use when requesting information from the Daemon. * * @param \Pterodactyl\Models\Server $server * @return $this */ public function setServer(Server $server) { $this->server = $server; return $this; } /** * Return the Server model. * * @return \Pterodactyl\Models\Server|null */ public function getServer() { return $this->server; } /** * Set the token to be used in the X-Access-Token header for requests to the daemon. * * @param string $token * @return $this */ public function setToken(string $token) { $this->token = $token; return $this; } /** * Return the access token being used for requests. * * @return string|null */ public function getToken() { return $this->token; } /** * 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 { // If no node is set, load the relationship onto the Server model // and pass that to the setNode function. if (! $this->getNode() instanceof Node) { if (! $this->getServer() instanceof Server) { throw new RuntimeException('An instance of ' . Node::class . ' or ' . Server::class . ' must be set on this repository in order to return a client.'); } $this->getServer()->loadMissing('node'); $this->setNode($this->getServer()->getRelation('node')); } if ($this->getServer() instanceof Server) { $headers['X-Access-Server'] = $this->getServer()->uuid; } $headers['X-Access-Token'] = $this->getToken() ?? $this->getNode()->daemonSecret; return new Client([ 'base_uri' => sprintf('%s://%s:%s/v1/', $this->getNode()->scheme, $this->getNode()->fqdn, $this->getNode()->daemonListen), 'timeout' => config('pterodactyl.guzzle.timeout'), 'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'), 'headers' => $headers, ]); } }