Begin implementation of services for services/service options

This commit is contained in:
Dane Everitt 2017-08-08 23:24:55 -05:00
parent 7277f728a9
commit 2c77d5c44d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
21 changed files with 567 additions and 408 deletions

View file

@ -24,10 +24,15 @@
namespace Pterodactyl\Models;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Validable;
use Illuminate\Database\Eloquent\Model;
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
class ServiceOption extends Model
class ServiceOption extends Model implements ValidableContract
{
use Eloquence, Validable;
/**
* The table associated with the model.
*
@ -42,15 +47,61 @@ class ServiceOption extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*
* @var array
*/
protected $casts = [
'service_id' => 'integer',
'script_is_privileged' => 'boolean',
];
/**
* Cast values to correct type.
*
* @var array
*/
protected $casts = [
'service_id' => 'integer',
'script_is_privileged' => 'boolean',
];
/**
* @var array
*/
protected static $applicationRules = [
'service_id' => 'required',
'name' => 'required',
'description' => 'required',
'tag' => 'required',
'docker_image' => 'sometimes',
'startup' => 'sometimes',
'config_from' => 'sometimes',
'config_stop' => 'required_without:config_from',
'config_startup' => 'required_without:config_from',
'config_logs' => 'required_without:config_from',
'config_files' => 'required_without:config_from',
];
/**
* @var array
*/
protected static $dataIntegrityRules = [
'service_id' => 'numeric|exists:services,id',
'name' => 'string|max:255',
'description' => 'string',
'tag' => 'alpha_num|max:60|unique:service_options,tag',
'docker_image' => 'string|max:255',
'startup' => 'nullable|string',
'config_from' => 'nullable|numeric|exists:service_options,id',
'config_stop' => 'nullable|string|max:255',
'config_startup' => 'nullable|json',
'config_logs' => 'nullable|json',
'config_files' => 'nullable|json',
];
/**
* @var array
*/
protected $attributes = [
'config_stop' => null,
'config_startup' => null,
'config_logs' => null,
'config_files' => null,
'startup' => null,
'docker_image' => null,
];
/**
* Returns the display startup string for the option and will use the parent
@ -136,6 +187,11 @@ class ServiceOption extends Model
return $this->hasMany(Pack::class, 'option_id');
}
/**
* Get the parent service option from which to copy scripts.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function copyFrom()
{
return $this->belongsTo(self::class, 'copy_script_from');

View file

@ -24,10 +24,22 @@
namespace Pterodactyl\Models;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Validable;
use Illuminate\Database\Eloquent\Model;
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
class ServiceVariable extends Model
class ServiceVariable extends Model implements ValidableContract
{
use Eloquence, Validable;
/**
* Reserved environment variable names.
*
* @var array
*/
const RESERVED_ENV_NAMES = 'SERVER_MEMORY,SERVER_IP,SERVER_PORT,ENV,HOME,USER,STARTUP,SERVER_UUID,UUID';
/**
* The table associated with the model.
*
@ -54,28 +66,35 @@ class ServiceVariable extends Model
];
/**
* Reserved environment variable names.
*
* @var array
*/
protected static $reservedNames = [
'SERVER_MEMORY',
'SERVER_IP',
'SERVER_PORT',
'ENV',
'HOME',
'USER',
protected static $applicationRules = [
'name' => 'required',
'env_variable' => 'required',
'rules' => 'required',
];
/**
* Returns an array of environment variable names that cannot be used.
*
* @return array
* @var array
*/
public static function reservedNames()
{
return self::$reservedNames;
}
protected static $dataIntegrityRules = [
'option_id' => 'exists:service_options,id',
'name' => 'string|between:1,255',
'description' => 'nullable|string',
'env_variable' => 'regex:/^[\w]{1,255}$/|notIn:' . self::RESERVED_ENV_NAMES,
'default_value' => 'string',
'user_viewable' => 'boolean',
'user_editable' => 'boolean',
'rules' => 'string',
];
/**
* @var array
*/
protected $attributes = [
'user_editable' => 0,
'user_viewable' => 0,
];
/**
* Returns the display executable for the option and will use the parent