Skip to content

Commit 84a4c8b

Browse files
committed
API enhancements, return node config, return 200 not 201
1 parent ab19e2e commit 84a4c8b

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
55

66
## v0.5.0-pre.2 (Bodacious Boreopterus)
77

8+
### Added
9+
* Return node configuration from remote API by using `/api/nodes/{id}/config` endpoint. Only accepts SSL connections.
10+
11+
### Changed
12+
* Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID.
13+
14+
## v0.5.0-pre.2 (Bodacious Boreopterus)
15+
816
### Added
917
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
1018
* Creating new files and folders directly from the right-click dropdown menu in the file manager.

app/Http/Controllers/API/NodeController.php

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function list(Request $request)
8585
* 'daemonSFTP' => 2022,
8686
* 'daemonListen' => 8080
8787
* }, headers={"Authorization": "Bearer <jwt-token>"}),
88-
* @Response(201),
88+
* @Response(200),
8989
* @Response(422, body={
9090
* "message": "A validation error occured.",
9191
* "errors": {},
@@ -102,9 +102,7 @@ public function create(Request $request)
102102
try {
103103
$node = new NodeRepository;
104104
$new = $node->create($request->all());
105-
return $this->response->created(route('api.nodes.view', [
106-
'id' => $new
107-
]));
105+
return [ 'id' => $new ];
108106
} catch (DisplayValidationException $ex) {
109107
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
110108
} catch (DisplayException $ex) {
@@ -129,23 +127,23 @@ public function create(Request $request)
129127
*/
130128
public function view(Request $request, $id, $fields = null)
131129
{
132-
$query = Models\Node::where('id', $id);
130+
$node = Models\Node::where('id', $id);
133131

134132
if (!is_null($request->input('fields'))) {
135133
foreach(explode(',', $request->input('fields')) as $field) {
136134
if (!empty($field)) {
137-
$query->addSelect($field);
135+
$node->addSelect($field);
138136
}
139137
}
140138
}
141139

142140
try {
143-
if (!$query->first()) {
141+
if (!$node->first()) {
144142
throw new NotFoundHttpException('No node by that ID was found.');
145143
}
146144

147145
return [
148-
'node' => $query->first(),
146+
'node' => $node->first(),
149147
'allocations' => [
150148
'assigned' => Models\Allocation::where('node', $id)->whereNotNull('assigned_to')->get(),
151149
'unassigned' => Models\Allocation::where('node', $id)->whereNull('assigned_to')->get()
@@ -158,6 +156,59 @@ public function view(Request $request, $id, $fields = null)
158156
}
159157
}
160158

159+
public function config(Request $request, $id)
160+
{
161+
if (!$request->secure()) {
162+
throw new BadRequestHttpException('This API route can only be accessed using a secure connection.');
163+
}
164+
165+
$node = Models\Node::where('id', $id)->first();
166+
if (!$node) {
167+
throw new NotFoundHttpException('No node by that ID was found.');
168+
}
169+
170+
return [
171+
'web' => [
172+
'listen' => $node->daemonListen,
173+
'ssl' => [
174+
'enabled' => ($node->scheme === 'https'),
175+
'certificate' => '/etc/certs/' . $node->fqdn . '/fullchain.pem',
176+
'key' => '/etc/certs/' . $node->fqdn . '/privkey.pem'
177+
]
178+
],
179+
'docker' => [
180+
'socket' => '/var/run/docker.sock',
181+
'autoupdate_images' => true
182+
],
183+
'sftp' => [
184+
'path' => $node->daemonBase,
185+
'port' => (int) $node->daemonSFTP,
186+
'container' => '0x0000'
187+
],
188+
'logger' => [
189+
'path' => 'logs/',
190+
'src' => false,
191+
'level' => 'info',
192+
'period' => '1d',
193+
'count' => 3
194+
],
195+
'remote' => [
196+
'download' => route('remote.download'),
197+
'installed' => route('remote.install')
198+
],
199+
'uploads' => [
200+
'maximumSize' => 100000000
201+
],
202+
'keys' => [
203+
$node->daemonSecret
204+
],
205+
'query' => [
206+
'kill_on_fail' => true,
207+
'fail_limit' => 3
208+
]
209+
];
210+
}
211+
161212
/**
162213
* List all Node Allocations
163214
*

app/Http/Controllers/API/ServerController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ public function create(Request $request)
7777
try {
7878
$server = new ServerRepository;
7979
$new = $server->create($request->all());
80-
return $this->response->created(route('api.servers.view', [
81-
'id' => $new
82-
]));
80+
return [ 'id' => $new ];
8381
} catch (DisplayValidationException $ex) {
8482
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
8583
} catch (DisplayException $ex) {

app/Http/Controllers/API/UserController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ public function create(Request $request)
129129
try {
130130
$user = new UserRepository;
131131
$create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'), $request->input('custom_id'));
132-
return $this->response->created(route('api.users.view', [
133-
'id' => $create
134-
]));
132+
return [ 'id' => $create ];
135133
} catch (DisplayValidationException $ex) {
136134
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
137135
} catch (DisplayException $ex) {

app/Http/Routes/APIRoutes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function map(Router $router) {
128128
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@view'
129129
]);
130130

131+
$api->get('nodes/{id}/config', [
132+
'as' => 'api.nodes.view',
133+
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@config'
134+
]);
135+
131136
$api->delete('nodes/{id}', [
132137
'as' => 'api.nodes.delete',
133138
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@delete'

0 commit comments

Comments
 (0)