Skip to content

Commit 72735c2

Browse files
committed
Complete move from old repository to new repository structure!
1 parent 2cabb61 commit 72735c2

27 files changed

+964
-730
lines changed

app/Contracts/Repository/Daemon/BaseRepositoryInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ interface BaseRepositoryInterface
3131
*
3232
* @param int $id
3333
* @return $this
34+
*
35+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
3436
*/
3537
public function setNode($id);
3638

@@ -77,5 +79,5 @@ public function getAccessToken();
7779
* @param array $headers
7880
* @return \GuzzleHttp\Client
7981
*/
80-
public function getHttpClient($headers = []);
82+
public function getHttpClient(array $headers = []);
8183
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository\Daemon;
26+
27+
interface CommandRepositoryInterface extends BaseRepositoryInterface
28+
{
29+
/**
30+
* Send a command to a server.
31+
*
32+
* @param string $command
33+
* @return \Psr\Http\Message\ResponseInterface
34+
*/
35+
public function send($command);
36+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository\Daemon;
26+
27+
interface FileRepositoryInterface extends BaseRepositoryInterface
28+
{
29+
/**
30+
* Return stat information for a given file.
31+
*
32+
* @param string $path
33+
* @return object
34+
*/
35+
public function getFileStat($path);
36+
37+
/**
38+
* Return the contents of a given file if it can be edited in the Panel.
39+
*
40+
* @param string $path
41+
* @return object
42+
*/
43+
public function getContent($path);
44+
45+
/**
46+
* Save new contents to a given file.
47+
*
48+
* @param string $path
49+
* @param string $content
50+
* @return \Psr\Http\Message\ResponseInterface
51+
*/
52+
public function putContent($path, $content);
53+
54+
/**
55+
* Return a directory listing for a given path.
56+
*
57+
* @param string $path
58+
* @return array
59+
*/
60+
public function getDirectory($path);
61+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository\Daemon;
26+
27+
interface PowerRepositoryInterface extends BaseRepositoryInterface
28+
{
29+
const SIGNAL_START = 'start';
30+
const SIGNAL_STOP = 'stop';
31+
const SIGNAL_RESTART = 'restart';
32+
const SIGNAL_KILL = 'kill';
33+
34+
/**
35+
* Send a power signal to a server.
36+
*
37+
* @param string $signal
38+
* @return \Psr\Http\Message\ResponseInterface
39+
*
40+
* @throws \Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException
41+
*/
42+
public function sendSignal($signal);
43+
}

app/Contracts/Repository/Daemon/ServerRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface ServerRepositoryInterface extends BaseRepositoryInterface
3434
* @param bool $start
3535
* @return \Psr\Http\Message\ResponseInterface
3636
*/
37-
public function create($id, $overrides = [], $start = false);
37+
public function create($id, array $overrides = [], $start = false);
3838

3939
/**
4040
* Set an access token and associated permissions for a server.

app/Contracts/Repository/SubuserRepositoryInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626

2727
interface SubuserRepositoryInterface extends RepositoryInterface
2828
{
29+
/**
30+
* Return a subuser with the associated server relationship.
31+
*
32+
* @param int $id
33+
* @return \Illuminate\Database\Eloquent\Collection
34+
*
35+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
36+
*/
37+
public function getWithServer($id);
38+
2939
/**
3040
* Find a subuser and return with server and permissions relationships.
3141
*
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Repository\Daemon;
26+
27+
class InvalidPowerSignalException extends \Exception
28+
{
29+
}

app/Repositories/Daemon/BaseRepository.php

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,47 @@
2929
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
3030
use Illuminate\Contracts\Config\Repository as ConfigRepository;
3131
use Pterodactyl\Contracts\Repository\Daemon\BaseRepositoryInterface;
32+
use Webmozart\Assert\Assert;
3233

3334
class BaseRepository implements BaseRepositoryInterface
3435
{
36+
/**
37+
* @var \Illuminate\Foundation\Application
38+
*/
3539
protected $app;
40+
41+
/**
42+
* @var
43+
*/
3644
protected $accessServer;
45+
46+
/**
47+
* @var
48+
*/
3749
protected $accessToken;
50+
51+
/**
52+
* @var
53+
*/
3854
protected $node;
55+
56+
/**
57+
* @var \Illuminate\Contracts\Config\Repository
58+
*/
3959
protected $config;
60+
61+
/**
62+
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
63+
*/
4064
protected $nodeRepository;
4165

66+
/**
67+
* BaseRepository constructor.
68+
*
69+
* @param \Illuminate\Foundation\Application $app
70+
* @param \Illuminate\Contracts\Config\Repository $config
71+
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $nodeRepository
72+
*/
4273
public function __construct(
4374
Application $app,
4475
ConfigRepository $config,
@@ -49,44 +80,70 @@ public function __construct(
4980
$this->nodeRepository = $nodeRepository;
5081
}
5182

83+
/**
84+
* {@inheritdoc}
85+
*/
5286
public function setNode($id)
5387
{
54-
// @todo accept a model
88+
Assert::numeric($id, 'The first argument passed to setNode must be numeric, received %s.');
89+
5590
$this->node = $this->nodeRepository->find($id);
5691

5792
return $this;
5893
}
5994

95+
/**
96+
* {@inheritdoc}
97+
*/
6098
public function getNode()
6199
{
62100
return $this->node;
63101
}
64102

103+
/**
104+
* {@inheritdoc}
105+
*/
65106
public function setAccessServer($server = null)
66107
{
108+
Assert::nullOrString($server, 'The first argument passed to setAccessServer must be null or a string, received %s.');
109+
67110
$this->accessServer = $server;
68111

69112
return $this;
70113
}
71114

115+
/**
116+
* {@inheritdoc}
117+
*/
72118
public function getAccessServer()
73119
{
74120
return $this->accessServer;
75121
}
76122

123+
/**
124+
* {@inheritdoc}
125+
*/
77126
public function setAccessToken($token = null)
78127
{
128+
Assert::nullOrString($token, 'The first argument passed to setAccessToken must be null or a string, received %s.');
129+
79130
$this->accessToken = $token;
80131

81132
return $this;
82133
}
83134

135+
/**
136+
* {@inheritdoc}
137+
*/
84138
public function getAccessToken()
85139
{
86140
return $this->accessToken;
87141
}
88142

89-
public function getHttpClient($headers = [])
143+
/**
144+
* {@inheritdoc}
145+
*/
146+
public function getHttpClient(array $headers = [])
90147
{
91148
if (! is_null($this->accessServer)) {
92149
$headers['X-Access-Server'] = $this->getAccessServer();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Repositories\Daemon;
26+
27+
use Webmozart\Assert\Assert;
28+
use Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface;
29+
30+
class CommandRepository extends BaseRepository implements CommandRepositoryInterface
31+
{
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function send($command)
36+
{
37+
Assert::stringNotEmpty($command, 'First argument passed to send must be a non-empty string, received %s.');
38+
39+
return $this->getHttpClient()->request('POST', '/server/command', [
40+
'json' => [
41+
'command' => $command,
42+
],
43+
]);
44+
}
45+
}

0 commit comments

Comments
 (0)