misc_pterodactyl-panel/app/Repositories/Daemon/ServerRepository.php

135 lines
3.8 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Repositories\Daemon;
2017-08-27 19:55:25 +00:00
use Webmozart\Assert\Assert;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
class ServerRepository extends BaseRepository implements ServerRepositoryInterface
{
/**
* Create a new server on the daemon for the panel.
*
* @param array $structure
* @param array $overrides
* @return \Psr\Http\Message\ResponseInterface
*
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function create(array $structure, array $overrides = []): ResponseInterface
{
foreach ($overrides as $key => $value) {
$structure[$key] = value($value);
}
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'servers', [
'json' => $structure,
]);
}
/**
* Update server details on the daemon.
*
* @param array $data
* @return \Psr\Http\Message\ResponseInterface
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function update(array $data): ResponseInterface
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('PATCH', 'server', [
'json' => $data,
]);
}
/**
* Mark a server to be reinstalled on the system.
*
* @param array|null $data
* @return \Psr\Http\Message\ResponseInterface
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function reinstall(array $data = null): ResponseInterface
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/reinstall', [
'json' => $data ?? [],
]);
}
/**
* Mark a server as needing a container rebuild the next time the server is booted.
*
* @return \Psr\Http\Message\ResponseInterface
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function rebuild(): ResponseInterface
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/rebuild');
}
/**
* Suspend a server on the daemon.
*
* @return \Psr\Http\Message\ResponseInterface
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function suspend(): ResponseInterface
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/suspend');
}
/**
* Un-suspend a server on the daemon.
*
* @return \Psr\Http\Message\ResponseInterface
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function unsuspend(): ResponseInterface
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/unsuspend');
}
/**
* Delete a server on the daemon.
*
* @return \Psr\Http\Message\ResponseInterface
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function delete(): ResponseInterface
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('DELETE', 'servers');
}
/**
2018-05-13 14:50:56 +00:00
* Return details on a specific server.
*
* @return \Psr\Http\Message\ResponseInterface
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function details(): ResponseInterface
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('GET', 'server');
}
/**
* Revoke an access key on the daemon before the time is expired.
*
* @param string|array $key
* @return \Psr\Http\Message\ResponseInterface
*
2018-05-13 16:19:35 +00:00
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function revokeAccessKey($key): ResponseInterface
{
if (is_array($key)) {
return $this->getHttpClient()->request('POST', 'keys/batch-delete', [
2018-03-04 03:53:07 +00:00
'json' => ['keys' => $key],
]);
}
Assert::stringNotEmpty($key, 'First argument passed to revokeAccessKey must be a non-empty string or array, received %s.');
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('DELETE', 'keys/' . $key);
}
}