Merge branch 'feature/api-integration-testing' into develop
This commit is contained in:
commit
68f0811273
30 changed files with 1374 additions and 80 deletions
|
@ -17,6 +17,13 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* Laravel's validation parser formats custom rules using the class name
|
||||
* resulting in some weird rule names. This string will be parsed out and
|
||||
* replaced with 'p_' in the response code.
|
||||
*/
|
||||
private const PTERODACTYL_RULE_STRING = 'pterodactyl\_rules\_';
|
||||
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
|
@ -156,7 +163,9 @@ class Handler extends ExceptionHandler
|
|||
$response = [];
|
||||
foreach ($errors as $key => $error) {
|
||||
$response[] = [
|
||||
'code' => array_get($codes, str_replace('.', '_', $field) . '.' . $key),
|
||||
'code' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
|
||||
$codes, str_replace('.', '_', $field) . '.' . $key
|
||||
)),
|
||||
'detail' => $error,
|
||||
'source' => ['field' => $field],
|
||||
];
|
||||
|
|
|
@ -9,19 +9,14 @@
|
|||
|
||||
namespace Pterodactyl\Services\Helpers;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
|
||||
class TemporaryPasswordService
|
||||
{
|
||||
const HMAC_ALGO = 'sha256';
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
|
@ -35,16 +30,11 @@ class TemporaryPasswordService
|
|||
/**
|
||||
* TemporaryPasswordService constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigRepository $config,
|
||||
ConnectionInterface $connection,
|
||||
Hasher $hasher
|
||||
) {
|
||||
$this->config = $config;
|
||||
public function __construct(ConnectionInterface $connection, Hasher $hasher)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->hasher = $hasher;
|
||||
}
|
||||
|
@ -57,7 +47,7 @@ class TemporaryPasswordService
|
|||
*/
|
||||
public function handle($email)
|
||||
{
|
||||
$token = hash_hmac(self::HMAC_ALGO, str_random(40), $this->config->get('app.key'));
|
||||
$token = hash_hmac(self::HMAC_ALGO, Uuid::uuid4()->toString(), config('app.key'));
|
||||
|
||||
$this->connection->table('password_resets')->insert([
|
||||
'email' => $email,
|
||||
|
|
|
@ -5,10 +5,15 @@ namespace Pterodactyl\Transformers\Api\Application;
|
|||
use Cake\Chronos\Chronos;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
|
||||
use Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException;
|
||||
|
||||
/**
|
||||
* @method array transform(Model $model)
|
||||
*/
|
||||
abstract class BaseTransformer extends TransformerAbstract
|
||||
{
|
||||
const RESPONSE_TIMEZONE = 'UTC';
|
||||
|
@ -88,7 +93,7 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
$transformer = Container::getInstance()->makeWith($abstract, $parameters);
|
||||
$transformer->setKey($this->getKey());
|
||||
|
||||
if (! $transformer instanceof self) {
|
||||
if (! $transformer instanceof self || $transformer instanceof BaseClientTransformer) {
|
||||
throw new InvalidTransformerLevelException('Calls to ' . __METHOD__ . ' must return a transformer that is an instance of ' . __CLASS__);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,10 +46,10 @@ class EggTransformer extends BaseTransformer
|
|||
'description' => $model->description,
|
||||
'docker_image' => $model->docker_image,
|
||||
'config' => [
|
||||
'files' => json_decode($model->config_files),
|
||||
'startup' => json_decode($model->config_startup),
|
||||
'files' => json_decode($model->config_files, true),
|
||||
'startup' => json_decode($model->config_startup, true),
|
||||
'stop' => $model->config_stop,
|
||||
'logs' => json_decode($model->config_logs),
|
||||
'logs' => json_decode($model->config_logs, true),
|
||||
'extends' => $model->config_from,
|
||||
],
|
||||
'startup' => $model->startup,
|
||||
|
|
|
@ -32,7 +32,13 @@ class LocationTransformer extends BaseTransformer
|
|||
*/
|
||||
public function transform(Location $location): array
|
||||
{
|
||||
return $location->toArray();
|
||||
return [
|
||||
'id' => $location->id,
|
||||
'short' => $location->short,
|
||||
'long' => $location->long,
|
||||
$location->getUpdatedAtColumn() => $this->formatTimestamp($location->updated_at),
|
||||
$location->getCreatedAtColumn() => $this->formatTimestamp($location->created_at),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +46,8 @@ class LocationTransformer extends BaseTransformer
|
|||
*
|
||||
* @param \Pterodactyl\Models\Location $location
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Location $location)
|
||||
{
|
||||
|
@ -57,6 +65,8 @@ class LocationTransformer extends BaseTransformer
|
|||
*
|
||||
* @param \Pterodactyl\Models\Location $location
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeNodes(Location $location)
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Pterodactyl\Transformers\Api\Application;
|
|||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class NestTransformer extends BaseTransformer
|
||||
|
@ -49,6 +50,8 @@ class NestTransformer extends BaseTransformer
|
|||
*
|
||||
* @param \Pterodactyl\Models\Nest $model
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeEggs(Nest $model)
|
||||
{
|
||||
|
@ -60,4 +63,23 @@ class NestTransformer extends BaseTransformer
|
|||
|
||||
return $this->collection($model->getRelation('eggs'), $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the servers relationship on the given Nest model.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Nest $model
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Nest $model)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('servers');
|
||||
|
||||
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ class UserTransformer extends BaseTransformer
|
|||
*
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(User $user)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue