Add ApiKey service, cleanup old API key methods
https://zube.io/pterodactyl/panel/c/525
This commit is contained in:
parent
2235481765
commit
4ee9d38ad1
10 changed files with 569 additions and 85 deletions
|
@ -24,16 +24,14 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
use Sofa\Eloquence\Validable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
||||
|
||||
class APIKey extends Model
|
||||
class APIKey extends Model implements ValidableContract
|
||||
{
|
||||
/**
|
||||
* Public key defined length used in verification methods.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PUBLIC_KEY_LEN = 16;
|
||||
use Eloquence, Validable;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
|
@ -65,6 +63,32 @@ class APIKey extends Model
|
|||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Rules defining what fields must be passed when making a model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $applicationRules = [
|
||||
'memo' => 'required',
|
||||
'user_id' => 'required',
|
||||
'secret' => 'required',
|
||||
'public' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* Rules to protect aganist invalid data entry to DB.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $dataIntegrityRules = [
|
||||
'user_id' => 'exists:users,id',
|
||||
'public' => 'string|size:16',
|
||||
'secret' => 'string',
|
||||
'memo' => 'nullable|string|max:500',
|
||||
'allowed_ips' => 'nullable|json',
|
||||
'expires_at' => 'nullable|datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets the permissions associated with a key.
|
||||
*
|
||||
|
|
|
@ -24,46 +24,19 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
use Sofa\Eloquence\Validable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
||||
|
||||
class APIPermission extends Model
|
||||
class APIPermission extends Model implements ValidableContract
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'api_permissions';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'key_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Disable timestamps for this table.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
use Eloquence, Validable;
|
||||
|
||||
/**
|
||||
* List of permissions available for the API.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $permissions = [
|
||||
const PERMISSIONS = [
|
||||
// Items within this block are available to non-adminitrative users.
|
||||
'_user' => [
|
||||
'server' => [
|
||||
|
@ -119,13 +92,49 @@ class APIPermission extends Model
|
|||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'api_permissions';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'key_id' => 'integer',
|
||||
];
|
||||
|
||||
protected static $dataIntegrityRules = [
|
||||
'key_id' => 'required|numeric',
|
||||
'permission' => 'required|string|max:200',
|
||||
];
|
||||
|
||||
/**
|
||||
* Disable timestamps for this table.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Return permissions for API.
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public static function permissions()
|
||||
{
|
||||
return self::$permissions;
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue