API enhancements, return node config, return 200 not 201

This commit is contained in:
Dane Everitt 2016-10-12 15:42:23 -04:00
parent ab19e2ee96
commit 84a4c8b7f4
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
5 changed files with 74 additions and 14 deletions

View File

@ -5,6 +5,14 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
## v0.5.0-pre.2 (Bodacious Boreopterus) ## v0.5.0-pre.2 (Bodacious Boreopterus)
### Added
* Return node configuration from remote API by using `/api/nodes/{id}/config` endpoint. Only accepts SSL connections.
### Changed
* Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID.
## v0.5.0-pre.2 (Bodacious Boreopterus)
### Added ### Added
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127) * Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
* Creating new files and folders directly from the right-click dropdown menu in the file manager. * Creating new files and folders directly from the right-click dropdown menu in the file manager.

View File

@ -85,7 +85,7 @@ class NodeController extends BaseController
* 'daemonSFTP' => 2022, * 'daemonSFTP' => 2022,
* 'daemonListen' => 8080 * 'daemonListen' => 8080
* }, headers={"Authorization": "Bearer <jwt-token>"}), * }, headers={"Authorization": "Bearer <jwt-token>"}),
* @Response(201), * @Response(200),
* @Response(422, body={ * @Response(422, body={
* "message": "A validation error occured.", * "message": "A validation error occured.",
* "errors": {}, * "errors": {},
@ -102,9 +102,7 @@ class NodeController extends BaseController
try { try {
$node = new NodeRepository; $node = new NodeRepository;
$new = $node->create($request->all()); $new = $node->create($request->all());
return $this->response->created(route('api.nodes.view', [ return [ 'id' => $new ];
'id' => $new
]));
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
@ -129,23 +127,23 @@ class NodeController extends BaseController
*/ */
public function view(Request $request, $id, $fields = null) public function view(Request $request, $id, $fields = null)
{ {
$query = Models\Node::where('id', $id); $node = Models\Node::where('id', $id);
if (!is_null($request->input('fields'))) { if (!is_null($request->input('fields'))) {
foreach(explode(',', $request->input('fields')) as $field) { foreach(explode(',', $request->input('fields')) as $field) {
if (!empty($field)) { if (!empty($field)) {
$query->addSelect($field); $node->addSelect($field);
} }
} }
} }
try { try {
if (!$query->first()) { if (!$node->first()) {
throw new NotFoundHttpException('No node by that ID was found.'); throw new NotFoundHttpException('No node by that ID was found.');
} }
return [ return [
'node' => $query->first(), 'node' => $node->first(),
'allocations' => [ 'allocations' => [
'assigned' => Models\Allocation::where('node', $id)->whereNotNull('assigned_to')->get(), 'assigned' => Models\Allocation::where('node', $id)->whereNotNull('assigned_to')->get(),
'unassigned' => Models\Allocation::where('node', $id)->whereNull('assigned_to')->get() 'unassigned' => Models\Allocation::where('node', $id)->whereNull('assigned_to')->get()
@ -158,6 +156,59 @@ class NodeController extends BaseController
} }
} }
public function config(Request $request, $id)
{
if (!$request->secure()) {
throw new BadRequestHttpException('This API route can only be accessed using a secure connection.');
}
$node = Models\Node::where('id', $id)->first();
if (!$node) {
throw new NotFoundHttpException('No node by that ID was found.');
}
return [
'web' => [
'listen' => $node->daemonListen,
'ssl' => [
'enabled' => ($node->scheme === 'https'),
'certificate' => '/etc/certs/' . $node->fqdn . '/fullchain.pem',
'key' => '/etc/certs/' . $node->fqdn . '/privkey.pem'
]
],
'docker' => [
'socket' => '/var/run/docker.sock',
'autoupdate_images' => true
],
'sftp' => [
'path' => $node->daemonBase,
'port' => (int) $node->daemonSFTP,
'container' => '0x0000'
],
'logger' => [
'path' => 'logs/',
'src' => false,
'level' => 'info',
'period' => '1d',
'count' => 3
],
'remote' => [
'download' => route('remote.download'),
'installed' => route('remote.install')
],
'uploads' => [
'maximumSize' => 100000000
],
'keys' => [
$node->daemonSecret
],
'query' => [
'kill_on_fail' => true,
'fail_limit' => 3
]
];
}
/** /**
* List all Node Allocations * List all Node Allocations
* *

View File

@ -77,9 +77,7 @@ class ServerController extends BaseController
try { try {
$server = new ServerRepository; $server = new ServerRepository;
$new = $server->create($request->all()); $new = $server->create($request->all());
return $this->response->created(route('api.servers.view', [ return [ 'id' => $new ];
'id' => $new
]));
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {

View File

@ -129,9 +129,7 @@ class UserController extends BaseController
try { try {
$user = new UserRepository; $user = new UserRepository;
$create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'), $request->input('custom_id')); $create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'), $request->input('custom_id'));
return $this->response->created(route('api.users.view', [ return [ 'id' => $create ];
'id' => $create
]));
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {

View File

@ -128,6 +128,11 @@ class APIRoutes
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@view' 'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@view'
]); ]);
$api->get('nodes/{id}/config', [
'as' => 'api.nodes.view',
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@config'
]);
$api->delete('nodes/{id}', [ $api->delete('nodes/{id}', [
'as' => 'api.nodes.delete', 'as' => 'api.nodes.delete',
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@delete' 'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@delete'