2020-05-20 17:29:03 -06:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Models;
|
2020-05-20 17:29:03 -06:00
|
|
|
|
2025-01-30 16:39:00 -05:00
|
|
|
use App\Contracts\Validatable;
|
|
|
|
|
use App\Traits\HasValidation;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2022-10-14 10:59:20 -06:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2020-10-17 14:42:08 -06:00
|
|
|
|
2020-05-20 17:29:03 -06:00
|
|
|
/**
|
2021-01-27 20:52:11 -08:00
|
|
|
* @property int $id
|
|
|
|
|
* @property string $uuid
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property string $description
|
|
|
|
|
* @property string $source
|
|
|
|
|
* @property string $target
|
|
|
|
|
* @property bool $read_only
|
|
|
|
|
* @property bool $user_mountable
|
2024-03-12 22:39:16 -04:00
|
|
|
* @property \App\Models\Egg[]|\Illuminate\Database\Eloquent\Collection $eggs
|
|
|
|
|
* @property \App\Models\Node[]|\Illuminate\Database\Eloquent\Collection $nodes
|
|
|
|
|
* @property \App\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
|
2020-05-20 17:29:03 -06:00
|
|
|
*/
|
2025-01-30 16:39:00 -05:00
|
|
|
class Mount extends Model implements Validatable
|
2020-05-20 17:29:03 -06:00
|
|
|
{
|
2025-01-30 16:39:00 -05:00
|
|
|
use HasValidation { getRules as getValidationRules; }
|
|
|
|
|
|
2020-05-20 17:29:03 -06:00
|
|
|
/**
|
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
|
* API representation using fractal.
|
|
|
|
|
*/
|
2021-01-23 12:33:34 -08:00
|
|
|
public const RESOURCE_NAME = 'mount';
|
2020-05-20 17:29:03 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fields that are not mass assignable.
|
2025-03-03 14:41:19 -05:00
|
|
|
*
|
|
|
|
|
* @var string[]
|
2020-05-20 17:29:03 -06:00
|
|
|
*/
|
2024-05-11 22:08:23 -04:00
|
|
|
protected $guarded = ['id'];
|
2020-05-20 18:00:53 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rules verifying that the data being stored matches the expectations of the database.
|
2025-03-03 14:41:19 -05:00
|
|
|
*
|
2025-03-08 19:56:06 -05:00
|
|
|
* @var array<array-key, string[]>
|
2020-05-20 18:00:53 -06:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public static array $validationRules = [
|
2025-03-08 19:56:06 -05:00
|
|
|
'name' => ['required', 'string', 'min:2', 'max:64', 'unique:mounts,name'],
|
|
|
|
|
'description' => ['nullable', 'string', 'max:255'],
|
|
|
|
|
'source' => ['required', 'string'],
|
|
|
|
|
'target' => ['required', 'string'],
|
|
|
|
|
'read_only' => ['sometimes', 'boolean'],
|
|
|
|
|
'user_mountable' => ['sometimes', 'boolean'],
|
2020-05-20 18:00:53 -06:00
|
|
|
];
|
|
|
|
|
|
2020-10-17 14:42:08 -06:00
|
|
|
/**
|
2025-03-03 14:41:19 -05:00
|
|
|
* Implement language verification by overriding Eloquence's gather rules function.
|
|
|
|
|
*
|
2025-03-08 19:56:06 -05:00
|
|
|
* @return array<array-key, string[]>
|
2020-10-17 14:42:08 -06:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public static function getRules(): array
|
2020-10-17 14:42:08 -06:00
|
|
|
{
|
2025-01-30 16:39:00 -05:00
|
|
|
$rules = self::getValidationRules();
|
2025-03-08 19:56:06 -05:00
|
|
|
$rules['source'][] = 'not_in:' . implode(',', Mount::$invalidSourcePaths);
|
|
|
|
|
$rules['target'][] = 'not_in:' . implode(',', Mount::$invalidTargetPaths);
|
2020-10-17 14:42:08 -06:00
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 18:55:59 -06:00
|
|
|
/**
|
|
|
|
|
* Disable timestamps on this model.
|
|
|
|
|
*/
|
|
|
|
|
public $timestamps = false;
|
|
|
|
|
|
2020-10-17 14:37:18 -06:00
|
|
|
/**
|
2021-01-23 12:09:16 -08:00
|
|
|
* Blacklisted source paths.
|
2025-03-03 14:41:19 -05:00
|
|
|
*
|
|
|
|
|
* @var string[]
|
2020-10-17 14:37:18 -06:00
|
|
|
*/
|
2024-10-19 21:00:11 -04:00
|
|
|
public static array $invalidSourcePaths = [
|
2024-04-12 12:52:00 -04:00
|
|
|
'/etc/pelican',
|
|
|
|
|
'/var/lib/pelican/volumes',
|
2020-10-17 14:37:18 -06:00
|
|
|
'/srv/daemon-data',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-23 12:09:16 -08:00
|
|
|
* Blacklisted target paths.
|
2025-03-03 14:41:19 -05:00
|
|
|
*
|
|
|
|
|
* @var string[]
|
2020-10-17 14:37:18 -06:00
|
|
|
*/
|
2024-10-19 21:00:11 -04:00
|
|
|
public static array $invalidTargetPaths = [
|
2020-10-17 14:37:18 -06:00
|
|
|
'/home/container',
|
|
|
|
|
];
|
|
|
|
|
|
2024-03-19 21:08:49 -04:00
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'id' => 'int',
|
|
|
|
|
'read_only' => 'bool',
|
|
|
|
|
'user_mountable' => 'bool',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 18:00:53 -06:00
|
|
|
/**
|
|
|
|
|
* Returns all eggs that have this mount assigned.
|
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function eggs(): BelongsToMany
|
2020-05-20 18:00:53 -06:00
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Egg::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns all nodes that have this mount assigned.
|
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function nodes(): BelongsToMany
|
2020-05-20 18:00:53 -06:00
|
|
|
{
|
2020-08-25 21:54:41 -07:00
|
|
|
return $this->belongsToMany(Node::class);
|
2020-05-20 18:00:53 -06:00
|
|
|
}
|
2020-05-21 14:23:12 -06:00
|
|
|
|
|
|
|
|
/**
|
2020-08-25 21:54:41 -07:00
|
|
|
* Returns all servers that have this mount assigned.
|
2020-05-21 14:23:12 -06:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function servers(): BelongsToMany
|
2020-05-21 14:23:12 -06:00
|
|
|
{
|
2020-08-25 21:54:41 -07:00
|
|
|
return $this->belongsToMany(Server::class);
|
2020-05-21 14:23:12 -06:00
|
|
|
}
|
2020-05-20 17:29:03 -06:00
|
|
|
}
|