Skip to content

Commit f24b238

Browse files
committed
Base node route implementation
1 parent 75b8753 commit f24b238

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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\Http\Controllers\API\Admin;
26+
27+
use Fractal;
28+
use Illuminate\Http\Request;
29+
use Pterodactyl\Models\Node;
30+
use Pterodactyl\Http\Controllers\Controller;
31+
use Pterodactyl\Transformers\Admin\NodeTransformer;
32+
33+
class NodeController extends Controller
34+
{
35+
/**
36+
* Controller to handle returning all nodes on the system.
37+
*
38+
* @param \Illuminate\Http\Request $request
39+
* @return array
40+
*/
41+
public function index(Request $request)
42+
{
43+
$this->authorize('node-list', $request->apiKey());
44+
45+
$fractal = Fractal::create()->collection(Node::all());
46+
if ($request->input('include')) {
47+
$fractal->parseIncludes(explode(',', $request->input('include')));
48+
}
49+
50+
return $fractal->transformWith(new NodeTransformer($request))
51+
->withResourceName('node')
52+
->toArray();
53+
}
54+
55+
/**
56+
* Display information about a single node on the system.
57+
*
58+
* @param \Illuminate\Http\Request $request
59+
* @param int $id
60+
* @return array
61+
*/
62+
public function view(Request $request, $id)
63+
{
64+
$this->authorize('node-view', $request->apiKey());
65+
66+
$fractal = Fractal::create()->item(Node::findOrFail($id));
67+
if ($request->input('include')) {
68+
$fractal->parseIncludes(explode(',', $request->input('include')));
69+
}
70+
71+
return $fractal->transformWith(new NodeTransformer($request))
72+
->withResourceName('node')
73+
->toArray();
74+
}
75+
}

app/Transformers/Admin/NodeTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function transform(Node $node)
8080
*/
8181
public function includeAllocations(Node $node)
8282
{
83-
if ($this->request && ! $this->request->apiKeyHasPermission('view-node')) {
83+
if ($this->request && ! $this->request->apiKeyHasPermission('node-view')) {
8484
return;
8585
}
8686

@@ -94,7 +94,7 @@ public function includeAllocations(Node $node)
9494
*/
9595
public function includeLocation(Node $node)
9696
{
97-
if ($this->request && ! $this->request->apiKeyHasPermission('view-node')) {
97+
if ($this->request && ! $this->request->apiKeyHasPermission('node-view')) {
9898
return;
9999
}
100100

@@ -108,7 +108,7 @@ public function includeLocation(Node $node)
108108
*/
109109
public function includeServers(Node $node)
110110
{
111-
if ($this->request && ! $this->request->apiKeyHasPermission('list-servers')) {
111+
if ($this->request && ! $this->request->apiKeyHasPermission('server-list')) {
112112
return;
113113
}
114114

routes/api-admin.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,16 @@
6262
Route::group(['prefix' => '/locations'], function () {
6363
Route::get('/', 'LocationController@index');
6464
});
65+
66+
/*
67+
|--------------------------------------------------------------------------
68+
| Node Controller Routes
69+
|--------------------------------------------------------------------------
70+
|
71+
| Endpoint: /api/admin/nodes
72+
|
73+
*/
74+
Route::group(['prefix' => '/nodes'], function () {
75+
Route::get('/', 'NodeController@index');
76+
Route::get('/{id}', 'NodeController@view');
77+
});

0 commit comments

Comments
 (0)