2018-01-26 04:34:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Api\Application\Servers\Databases;
|
|
|
|
|
2019-03-02 23:31:25 +00:00
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
use Illuminate\Database\Query\Builder;
|
2018-01-26 04:34:53 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
|
|
|
|
|
|
|
class StoreServerDatabaseRequest extends ApplicationApiRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $resource = AdminAcl::RESOURCE_SERVER_DATABASES;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $permission = AdminAcl::WRITE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation rules for database creation.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
2019-03-02 23:31:25 +00:00
|
|
|
'database' => [
|
|
|
|
'required',
|
|
|
|
'string',
|
|
|
|
'min:1',
|
|
|
|
'max:24',
|
|
|
|
Rule::unique('databases')->where(function (Builder $query) {
|
|
|
|
$query->where('database_host_id', $this->input('host') ?? 0);
|
|
|
|
}),
|
|
|
|
],
|
2018-05-21 01:11:52 +01:00
|
|
|
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
2018-01-26 04:34:53 +00:00
|
|
|
'host' => 'required|integer|exists:database_hosts,id',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return data formatted in the correct format for the service to consume.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function validated()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'database' => $this->input('database'),
|
|
|
|
'remote' => $this->input('remote'),
|
|
|
|
'database_host_id' => $this->input('host'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format error messages in a more understandable format for API output.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function attributes()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'host' => 'Database Host Server ID',
|
|
|
|
'remote' => 'Remote Connection String',
|
|
|
|
'database' => 'Database Name',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|