Add support for node management actions using new services
This commit is contained in:
parent
4391defb9f
commit
c1a078bdcf
33 changed files with 1375 additions and 745 deletions
|
@ -25,13 +25,15 @@
|
|||
namespace Pterodactyl\Models;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
use Sofa\Eloquence\Validable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Nicolaslopezj\Searchable\SearchableTrait;
|
||||
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
||||
|
||||
class Node extends Model
|
||||
class Node extends Model implements ValidableContract
|
||||
{
|
||||
use Notifiable, SearchableTrait;
|
||||
use Eloquence, Notifiable, Validable;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
|
@ -47,20 +49,20 @@ class Node extends Model
|
|||
*/
|
||||
protected $hidden = ['daemonSecret'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'public' => 'integer',
|
||||
'location_id' => 'integer',
|
||||
'memory' => 'integer',
|
||||
'disk' => 'integer',
|
||||
'daemonListen' => 'integer',
|
||||
'daemonSFTP' => 'integer',
|
||||
'behind_proxy' => 'boolean',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'public' => 'integer',
|
||||
'location_id' => 'integer',
|
||||
'memory' => 'integer',
|
||||
'disk' => 'integer',
|
||||
'daemonListen' => 'integer',
|
||||
'daemonSFTP' => 'integer',
|
||||
'behind_proxy' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
|
@ -81,22 +83,67 @@ class Node extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchable = [
|
||||
'columns' => [
|
||||
'nodes.name' => 10,
|
||||
'nodes.fqdn' => 8,
|
||||
'locations.short' => 4,
|
||||
'locations.long' => 4,
|
||||
],
|
||||
'joins' => [
|
||||
'locations' => ['locations.id', 'nodes.location_id'],
|
||||
],
|
||||
];
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'fqdn' => 8,
|
||||
'location.short' => 4,
|
||||
'location.long' => 4,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $applicationRules = [
|
||||
'name' => 'required',
|
||||
'location_id' => 'required',
|
||||
'fqdn' => 'required',
|
||||
'scheme' => 'required',
|
||||
'memory' => 'required',
|
||||
'memory_overallocate' => 'required',
|
||||
'disk' => 'required',
|
||||
'disk_overallocate' => 'required',
|
||||
'daemonBase' => 'sometimes|required',
|
||||
'daemonSFTP' => 'required',
|
||||
'daemonListen' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $dataIntegrityRules = [
|
||||
'name' => 'regex:/^([\w .-]{1,100})$/',
|
||||
'location_id' => 'exists:locations,id',
|
||||
'public' => 'boolean',
|
||||
'fqdn' => 'string',
|
||||
'behind_proxy' => 'boolean',
|
||||
'memory' => 'numeric|min:1',
|
||||
'memory_overallocate' => 'numeric|min:-1',
|
||||
'disk' => 'numeric|min:1',
|
||||
'disk_overallocate' => 'numeric|min:-1',
|
||||
'daemonBase' => 'regex:/^([\/][\d\w.\-\/]+)$/',
|
||||
'daemonSFTP' => 'numeric|between:1024,65535',
|
||||
'daemonListen' => 'numeric|between:1024,65535',
|
||||
];
|
||||
|
||||
/**
|
||||
* Default values for specific columns that are generally not changed on base installs.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'public' => true,
|
||||
'behind_proxy' => false,
|
||||
'memory_overallocate' => 0,
|
||||
'disk_overallocate' => 0,
|
||||
'daemonBase' => '/srv/daemon-data',
|
||||
'daemonSFTP' => 2022,
|
||||
'daemonListen' => 8080,
|
||||
];
|
||||
|
||||
/**
|
||||
* Return an instance of the Guzzle client for this specific node.
|
||||
*
|
||||
* @param array $headers
|
||||
* @param array $headers
|
||||
* @return \GuzzleHttp\Client
|
||||
*/
|
||||
public function guzzleClient($headers = [])
|
||||
|
@ -112,7 +159,7 @@ class Node extends Model
|
|||
/**
|
||||
* Returns the configuration in JSON format.
|
||||
*
|
||||
* @param bool $pretty
|
||||
* @param bool $pretty
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigurationAsJson($pretty = false)
|
||||
|
|
|
@ -67,6 +67,9 @@ class Server extends Model implements ValidableContract
|
|||
*/
|
||||
protected $guarded = ['id', 'installed', 'created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $applicationRules = [
|
||||
'owner_id' => 'required',
|
||||
'name' => 'required',
|
||||
|
@ -83,6 +86,9 @@ class Server extends Model implements ValidableContract
|
|||
'skip_scripts' => 'sometimes',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $dataIntegrityRules = [
|
||||
'owner_id' => 'exists:users,id',
|
||||
'name' => 'regex:/^([\w .-]{1,200})$/',
|
||||
|
@ -132,22 +138,15 @@ class Server extends Model implements ValidableContract
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchable = [
|
||||
'columns' => [
|
||||
'servers.name' => 10,
|
||||
'servers.username' => 10,
|
||||
'servers.uuidShort' => 9,
|
||||
'servers.uuid' => 8,
|
||||
'packs.name' => 7,
|
||||
'users.email' => 6,
|
||||
'users.username' => 6,
|
||||
'nodes.name' => 2,
|
||||
],
|
||||
'joins' => [
|
||||
'packs' => ['packs.id', 'servers.pack_id'],
|
||||
'users' => ['users.id', 'servers.owner_id'],
|
||||
'nodes' => ['nodes.id', 'servers.node_id'],
|
||||
],
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'username' => 10,
|
||||
'uuidShort' => 9,
|
||||
'uuid' => 8,
|
||||
'pack.name' => 7,
|
||||
'user.email' => 6,
|
||||
'user.username' => 6,
|
||||
'node.name' => 2,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -155,10 +154,11 @@ class Server extends Model implements ValidableContract
|
|||
* DO NOT USE THIS TO MODIFY SERVER DETAILS OR SAVE THOSE DETAILS.
|
||||
* YOU WILL OVERWRITE THE SECRET KEY AND BREAK THINGS.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @param array $with
|
||||
* @param array $withCount
|
||||
* @param string $uuid
|
||||
* @param array $with
|
||||
* @param array $withCount
|
||||
* @return \Pterodactyl\Models\Server
|
||||
* @throws \Exception
|
||||
* @todo Remove $with and $withCount due to cache issues, they aren't used anyways.
|
||||
*/
|
||||
public static function byUuid($uuid, array $with = [], array $withCount = [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue