Skip to content

Commit d2afc29

Browse files
committed
Refactor how repositories for the daemon work.
1 parent 5f9fe4a commit d2afc29

File tree

58 files changed

+388
-997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+388
-997
lines changed

app/Console/Commands/Server/RebuildServerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function handle()
7777
$json = array_merge($this->configurationStructureService->handle($server), ['rebuild' => true]);
7878

7979
try {
80-
$this->daemonRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update($json);
80+
$this->daemonRepository->setServer($server)->update($json);
8181
} catch (RequestException $exception) {
8282
$this->output->error(trans('command/messages.server.rebuild_failed', [
8383
'name' => $server->name,
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,65 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository\Daemon;
114

5+
use GuzzleHttp\Client;
6+
use Pterodactyl\Models\Node;
7+
use Pterodactyl\Models\Server;
8+
129
interface BaseRepositoryInterface
1310
{
1411
/**
1512
* Set the node model to be used for this daemon connection.
1613
*
17-
* @param int $id
14+
* @param \Pterodactyl\Models\Node $node
1815
* @return $this
19-
*
20-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
2116
*/
22-
public function setNode($id);
17+
public function setNode(Node $node);
2318

2419
/**
2520
* Return the node model being used.
2621
*
2722
* @return \Pterodactyl\Models\Node
2823
*/
29-
public function getNode();
24+
public function getNode(): Node;
3025

3126
/**
32-
* Set the UUID for the server to be used in the X-Access-Server header for daemon requests.
27+
* Set the Server model to use when requesting information from the Daemon.
3328
*
34-
* @param null|string $server
29+
* @param \Pterodactyl\Models\Server $server
3530
* @return $this
3631
*/
37-
public function setAccessServer($server = null);
32+
public function setServer(Server $server);
3833

3934
/**
40-
* Return the UUID of the server being used in requests.
35+
* Return the Server model.
4136
*
42-
* @return string
37+
* @return \Pterodactyl\Models\Server|null
4338
*/
44-
public function getAccessServer();
39+
public function getServer();
4540

4641
/**
4742
* Set the token to be used in the X-Access-Token header for requests to the daemon.
4843
*
49-
* @param null|string $token
44+
* @param string $token
5045
* @return $this
5146
*/
52-
public function setAccessToken($token = null);
47+
public function setToken(string $token);
5348

5449
/**
5550
* Return the access token being used for requests.
5651
*
57-
* @return string
52+
* @return string|null
5853
*/
59-
public function getAccessToken();
54+
public function getToken();
6055

6156
/**
6257
* Return an instance of the Guzzle HTTP Client to be used for requests.
6358
*
6459
* @param array $headers
6560
* @return \GuzzleHttp\Client
61+
*
62+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6663
*/
67-
public function getHttpClient(array $headers = []);
64+
public function getHttpClient(array $headers = []): Client;
6865
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository\Daemon;
114

5+
use Psr\Http\Message\ResponseInterface;
6+
127
interface CommandRepositoryInterface extends BaseRepositoryInterface
138
{
149
/**
@@ -17,5 +12,5 @@ interface CommandRepositoryInterface extends BaseRepositoryInterface
1712
* @param string $command
1813
* @return \Psr\Http\Message\ResponseInterface
1914
*/
20-
public function send($command);
15+
public function send(string $command): ResponseInterface;
2116
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository\Daemon;
114

5+
use Psr\Http\Message\ResponseInterface;
6+
127
interface ConfigurationRepositoryInterface extends BaseRepositoryInterface
138
{
149
/**
@@ -17,5 +12,5 @@ interface ConfigurationRepositoryInterface extends BaseRepositoryInterface
1712
* @param array $overrides
1813
* @return \Psr\Http\Message\ResponseInterface
1914
*/
20-
public function update(array $overrides = []);
15+
public function update(array $overrides = []): ResponseInterface;
2116
}
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository\Daemon;
114

5+
use stdClass;
6+
use Psr\Http\Message\ResponseInterface;
7+
128
interface FileRepositoryInterface extends BaseRepositoryInterface
139
{
1410
/**
1511
* Return stat information for a given file.
1612
*
1713
* @param string $path
18-
* @return object
14+
* @return \stdClass
1915
*
2016
* @throws \GuzzleHttp\Exception\RequestException
2117
*/
22-
public function getFileStat($path);
18+
public function getFileStat(string $path): stdClass;
2319

2420
/**
2521
* Return the contents of a given file if it can be edited in the Panel.
2622
*
2723
* @param string $path
28-
* @return object
24+
* @return \stdClass
2925
*
3026
* @throws \GuzzleHttp\Exception\RequestException
3127
*/
32-
public function getContent($path);
28+
public function getContent(string $path): stdClass;
3329

3430
/**
3531
* Save new contents to a given file.
@@ -40,7 +36,7 @@ public function getContent($path);
4036
*
4137
* @throws \GuzzleHttp\Exception\RequestException
4238
*/
43-
public function putContent($path, $content);
39+
public function putContent(string $path, string $content): ResponseInterface;
4440

4541
/**
4642
* Return a directory listing for a given path.
@@ -50,5 +46,5 @@ public function putContent($path, $content);
5046
*
5147
* @throws \GuzzleHttp\Exception\RequestException
5248
*/
53-
public function getDirectory($path);
49+
public function getDirectory(string $path): array;
5450
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository\Daemon;
114

5+
use Psr\Http\Message\ResponseInterface;
6+
127
interface PowerRepositoryInterface extends BaseRepositoryInterface
138
{
149
const SIGNAL_START = 'start';
@@ -24,5 +19,5 @@ interface PowerRepositoryInterface extends BaseRepositoryInterface
2419
*
2520
* @throws \Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException
2621
*/
27-
public function sendSignal($signal);
22+
public function sendSignal(string $signal): ResponseInterface;
2823
}

app/Contracts/Repository/Daemon/ServerRepositoryInterface.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository\Daemon;
114

@@ -30,50 +23,50 @@ public function create(array $structure, array $overrides = []): ResponseInterfa
3023
* @param array $data
3124
* @return \Psr\Http\Message\ResponseInterface
3225
*/
33-
public function update(array $data);
26+
public function update(array $data): ResponseInterface;
3427

3528
/**
3629
* Mark a server to be reinstalled on the system.
3730
*
3831
* @param array|null $data
3932
* @return \Psr\Http\Message\ResponseInterface
4033
*/
41-
public function reinstall($data = null);
34+
public function reinstall(array $data = null): ResponseInterface;
4235

4336
/**
4437
* Mark a server as needing a container rebuild the next time the server is booted.
4538
*
4639
* @return \Psr\Http\Message\ResponseInterface
4740
*/
48-
public function rebuild();
41+
public function rebuild(): ResponseInterface;
4942

5043
/**
5144
* Suspend a server on the daemon.
5245
*
5346
* @return \Psr\Http\Message\ResponseInterface
5447
*/
55-
public function suspend();
48+
public function suspend(): ResponseInterface;
5649

5750
/**
5851
* Un-suspend a server on the daemon.
5952
*
6053
* @return \Psr\Http\Message\ResponseInterface
6154
*/
62-
public function unsuspend();
55+
public function unsuspend(): ResponseInterface;
6356

6457
/**
6558
* Delete a server on the daemon.
6659
*
6760
* @return \Psr\Http\Message\ResponseInterface
6861
*/
69-
public function delete();
62+
public function delete(): ResponseInterface;
7063

7164
/**
7265
* Return detials on a specific server.
7366
*
7467
* @return \Psr\Http\Message\ResponseInterface
7568
*/
76-
public function details();
69+
public function details(): ResponseInterface;
7770

7871
/**
7972
* Revoke an access key on the daemon before the time is expired.
@@ -83,5 +76,5 @@ public function details();
8376
*
8477
* @throws \GuzzleHttp\Exception\RequestException
8578
*/
86-
public function revokeAccessKey($key);
79+
public function revokeAccessKey($key): ResponseInterface;
8780
}

app/Http/Controllers/Admin/ServersController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,10 @@ public function reinstallServer(Server $server)
457457
*
458458
* @param \Pterodactyl\Models\Server $server
459459
* @return \Illuminate\Http\RedirectResponse
460-
*
461-
* @throws \Pterodactyl\Exceptions\DisplayException
462460
*/
463461
public function rebuildContainer(Server $server)
464462
{
465-
$this->containerRebuildService->rebuild($server);
463+
$this->containerRebuildService->handle($server);
466464
$this->alert->success(trans('admin/server.alerts.rebuild_on_boot'))->flash();
467465

468466
return redirect()->route('admin.servers.view.manage', $server->id);

app/Http/Controllers/Base/IndexController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ public function status(Request $request, $uuid)
8080
}
8181

8282
try {
83-
$response = $this->daemonRepository->setNode($server->node_id)
84-
->setAccessServer($server->uuid)
85-
->setAccessToken($token)
86-
->details();
83+
$response = $this->daemonRepository->setServer($server)->setToken($token)->details();
8784
} catch (RequestException $exception) {
8885
throw new HttpException(500, $exception->getMessage());
8986
}

app/Http/Controllers/Server/Files/FileActionsController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,14 @@ public function create(Request $request): View
9696
* @return \Illuminate\View\View
9797
*
9898
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
99-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
10099
*/
101100
public function view(UpdateFileContentsFormRequest $request, string $uuid, string $file): View
102101
{
103102
$server = $request->attributes->get('server');
104103

105104
$dirname = pathinfo($file, PATHINFO_DIRNAME);
106105
try {
107-
$content = $this->repository->setNode($server->node_id)->setAccessServer($server->uuid)
108-
->setAccessToken($request->attributes->get('server_token'))
109-
->getContent($file);
106+
$content = $this->repository->setServer($server)->setToken($request->attributes->get('server_token'))->getContent($file);
110107
} catch (RequestException $exception) {
111108
throw new DaemonConnectionException($exception);
112109
}

0 commit comments

Comments
 (0)