api(application): fix requests, again
This commit is contained in:
parent
da3c7fa455
commit
18bdde8b81
15 changed files with 27 additions and 237 deletions
|
@ -64,10 +64,8 @@ abstract class ApplicationApiController extends Controller
|
||||||
{
|
{
|
||||||
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
|
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
|
||||||
$transformer = Container::getInstance()->make($abstract);
|
$transformer = Container::getInstance()->make($abstract);
|
||||||
|
|
||||||
$apiKey = $this->request->attributes->get('api_key');
|
|
||||||
$transformer->setKey($this->request->attributes->get('api_key'));
|
|
||||||
$transformer->setRootAdmin($this->request->user()->root_admin);
|
$transformer->setRootAdmin($this->request->user()->root_admin);
|
||||||
|
$transformer->setKey($this->request->attributes->get('api_key'));
|
||||||
|
|
||||||
Assert::isInstanceOf($transformer, BaseTransformer::class);
|
Assert::isInstanceOf($transformer, BaseTransformer::class);
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class GetServerDatabaseRequest extends ApplicationApiRequest
|
class GetServerDatabaseRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
protected string $resource = AdminAcl::RESOURCE_SERVER_DATABASES;
|
||||||
* @var string
|
protected int $permission = AdminAcl::READ;
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVER_DATABASES;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::READ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the requested server database exists.
|
|
||||||
*/
|
|
||||||
public function resourceExists(): bool
|
public function resourceExists(): bool
|
||||||
{
|
{
|
||||||
$server = $this->route()->parameter('server');
|
$server = $this->route()->parameter('server');
|
||||||
|
|
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class GetServerDatabasesRequest extends ApplicationApiRequest
|
class GetServerDatabasesRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
protected string $resource = AdminAcl::RESOURCE_SERVER_DATABASES;
|
||||||
* @var string
|
protected int $permission = AdminAcl::READ;
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVER_DATABASES;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::READ;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,5 @@ use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
|
||||||
class ServerDatabaseWriteRequest extends GetServerDatabasesRequest
|
class ServerDatabaseWriteRequest extends GetServerDatabasesRequest
|
||||||
{
|
{
|
||||||
/**
|
protected int $permission = AdminAcl::WRITE;
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::WRITE;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class StoreServerDatabaseRequest extends ApplicationApiRequest
|
class StoreServerDatabaseRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
protected string $resource = AdminAcl::RESOURCE_SERVER_DATABASES;
|
||||||
* @var string
|
protected int $permission = AdminAcl::WRITE;
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVER_DATABASES;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::WRITE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validation rules for database creation.
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$server = $this->route()->parameter('server');
|
$server = $this->route()->parameter('server');
|
||||||
|
@ -44,12 +34,7 @@ class StoreServerDatabaseRequest extends ApplicationApiRequest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function validated(): array
|
||||||
* Return data formatted in the correct format for the service to consume.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function validated()
|
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'database' => $this->input('database'),
|
'database' => $this->input('database'),
|
||||||
|
@ -58,12 +43,7 @@ class StoreServerDatabaseRequest extends ApplicationApiRequest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function attributes(): array
|
||||||
* Format error messages in a more understandable format for API output.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function attributes()
|
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'host' => 'Database Host Server ID',
|
'host' => 'Database Host Server ID',
|
||||||
|
@ -72,9 +52,6 @@ class StoreServerDatabaseRequest extends ApplicationApiRequest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the database name in the expected format.
|
|
||||||
*/
|
|
||||||
public function databaseName(): string
|
public function databaseName(): string
|
||||||
{
|
{
|
||||||
$server = $this->route()->parameter('server');
|
$server = $this->route()->parameter('server');
|
||||||
|
|
|
@ -10,24 +10,10 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class GetExternalServerRequest extends ApplicationApiRequest
|
class GetExternalServerRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
private Server $serverModel;
|
||||||
* @var \Pterodactyl\Models\Server
|
protected string $resource = AdminAcl::RESOURCE_SERVERS;
|
||||||
*/
|
protected int $permission = AdminAcl::READ;
|
||||||
private $serverModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVERS;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::READ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the requested external user exists.
|
|
||||||
*/
|
|
||||||
public function resourceExists(): bool
|
public function resourceExists(): bool
|
||||||
{
|
{
|
||||||
$repository = $this->container->make(ServerRepositoryInterface::class);
|
$repository = $this->container->make(ServerRepositoryInterface::class);
|
||||||
|
@ -43,9 +29,6 @@ class GetExternalServerRequest extends ApplicationApiRequest
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the server model for the requested external server.
|
|
||||||
*/
|
|
||||||
public function getServerModel(): Server
|
public function getServerModel(): Server
|
||||||
{
|
{
|
||||||
return $this->serverModel;
|
return $this->serverModel;
|
||||||
|
|
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class GetServerRequest extends ApplicationApiRequest
|
class GetServerRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
protected string $resource = AdminAcl::RESOURCE_SERVERS;
|
||||||
* @var string
|
protected int $permission = AdminAcl::READ;
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVERS;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::READ;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class ServerWriteRequest extends ApplicationApiRequest
|
class ServerWriteRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
protected string $resource = AdminAcl::RESOURCE_SERVERS;
|
||||||
* @var string
|
protected int $permission = AdminAcl::WRITE;
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVERS;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::WRITE;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class StoreServerRequest extends ApplicationApiRequest
|
class StoreServerRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
protected string $resource = AdminAcl::RESOURCE_SERVERS;
|
||||||
* @var string
|
protected int $permission = AdminAcl::WRITE;
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVERS;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::WRITE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rules to be applied to this request.
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = Server::getRules();
|
$rules = Server::getRules();
|
||||||
|
@ -71,12 +61,7 @@ class StoreServerRequest extends ApplicationApiRequest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function validated(): array
|
||||||
* Normalize the data into a format that can be consumed by the service.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function validated()
|
|
||||||
{
|
{
|
||||||
$data = parent::validated();
|
$data = parent::validated();
|
||||||
|
|
||||||
|
@ -105,11 +90,6 @@ class StoreServerRequest extends ApplicationApiRequest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Run validation after the rules above have been applied.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
|
||||||
*/
|
|
||||||
public function withValidator(Validator $validator)
|
public function withValidator(Validator $validator)
|
||||||
{
|
{
|
||||||
$validator->sometimes('allocation.default', [
|
$validator->sometimes('allocation.default', [
|
||||||
|
@ -139,12 +119,7 @@ class StoreServerRequest extends ApplicationApiRequest
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getDeploymentObject(): ?DeploymentObject
|
||||||
* Return a deployment object that can be passed to the server creation service.
|
|
||||||
*
|
|
||||||
* @return \Pterodactyl\Models\Objects\DeploymentObject|null
|
|
||||||
*/
|
|
||||||
public function getDeploymentObject()
|
|
||||||
{
|
{
|
||||||
if (is_null($this->input('deploy'))) {
|
if (is_null($this->input('deploy'))) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -12,7 +12,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = Server::getRulesForUpdate($this->getModel(Server::class));
|
$rules = Server::getRulesForUpdate($this->route()->parameter('server')->id);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'allocation' => $rules['allocation_id'],
|
'allocation' => $rules['allocation_id'],
|
||||||
|
|
|
@ -11,7 +11,7 @@ class UpdateServerDetailsRequest extends ServerWriteRequest
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = Server::getRulesForUpdate($this->getModel(Server::class));
|
$rules = Server::getRulesForUpdate($this->route()->parameter('server')->id);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'external_id' => $rules['external_id'],
|
'external_id' => $rules['external_id'],
|
||||||
|
|
|
@ -8,22 +8,12 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
class UpdateServerStartupRequest extends ApplicationApiRequest
|
class UpdateServerStartupRequest extends ApplicationApiRequest
|
||||||
{
|
{
|
||||||
/**
|
protected string $resource = AdminAcl::RESOURCE_SERVERS;
|
||||||
* @var string
|
protected int $permission = AdminAcl::WRITE;
|
||||||
*/
|
|
||||||
protected $resource = AdminAcl::RESOURCE_SERVERS;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $permission = AdminAcl::WRITE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validation rules to run the input against.
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$data = Server::getRulesForUpdate($this->getModel(Server::class));
|
$data = Server::getRulesForUpdate($this->route()->parameter('server')->id);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'startup' => $data['startup'],
|
'startup' => $data['startup'],
|
||||||
|
@ -34,12 +24,7 @@ class UpdateServerStartupRequest extends ApplicationApiRequest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function validated(): array
|
||||||
* Return the validated data in a format that is expected by the service.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function validated()
|
|
||||||
{
|
{
|
||||||
$data = parent::validated();
|
$data = parent::validated();
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Pterodactyl\Models;
|
||||||
* @property string $username
|
* @property string $username
|
||||||
* @property string $password
|
* @property string $password
|
||||||
* @property int|null $max_databases
|
* @property int|null $max_databases
|
||||||
* @property int|null $node_id
|
|
||||||
* @property \Carbon\CarbonImmutable $created_at
|
* @property \Carbon\CarbonImmutable $created_at
|
||||||
* @property \Carbon\CarbonImmutable $updated_at
|
* @property \Carbon\CarbonImmutable $updated_at
|
||||||
*/
|
*/
|
||||||
|
@ -82,14 +81,4 @@ class DatabaseHost extends Model
|
||||||
{
|
{
|
||||||
return $this->hasMany(Database::class);
|
return $this->hasMany(Database::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the nodes associated with a database host.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
||||||
*/
|
|
||||||
public function nodes()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany(Node::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property int $node_id
|
|
||||||
* @property int $database_host_id
|
|
||||||
*/
|
|
||||||
class DatabaseHostNode extends Model
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $table = 'database_host_node';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var null
|
|
||||||
*/
|
|
||||||
protected $primaryKey = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $incrementing = false;
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
|
|
||||||
class AddDatabaseHostNodeTable extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::create('database_host_node', function (Blueprint $table) {
|
|
||||||
$table->integer('node_id')->unique();
|
|
||||||
$table->integer('database_host_id');
|
|
||||||
|
|
||||||
$table->unique(['node_id', 'database_host_id']);
|
|
||||||
});
|
|
||||||
|
|
||||||
DB::transaction(function () {
|
|
||||||
foreach (DB::select('SELECT id, node_id FROM database_hosts') as $datum) {
|
|
||||||
if (! is_null($datum->node_id)) {
|
|
||||||
DB::insert('INSERT INTO database_host_node (node_id, database_host_id) VALUES (?, ?)', [
|
|
||||||
$datum->node_id,
|
|
||||||
$datum->id
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::table('database_hosts', function (Blueprint $table) {
|
|
||||||
$table->dropForeign(['node_id']);
|
|
||||||
$table->dropColumn('node_id');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table('database_hosts', function (Blueprint $table) {
|
|
||||||
$table->integer('node_id')->unsigned()->nullable()->after('max_databases');
|
|
||||||
|
|
||||||
$table->foreign('node_id')->references('id')->on('nodes')->onDelete('set null');
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::dropIfExists('database_host_node');
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue