feat(ssh-keys): add ssh key endpoints and ui components
This commit is contained in:
parent
9d64c6751b
commit
f9114e2de0
17 changed files with 375 additions and 7 deletions
|
@ -3,11 +3,9 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Application\Roles;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\AdminRole;
|
||||
use Spatie\QueryBuilder\QueryBuilder;
|
||||
use Pterodactyl\Transformers\Api\Application\LocationTransformer;
|
||||
use Pterodactyl\Transformers\Api\Application\AdminRoleTransformer;
|
||||
use Pterodactyl\Exceptions\Http\QueryValueOutOfRangeHttpException;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Roles\GetRoleRequest;
|
||||
|
|
58
app/Http/Controllers/Api/Client/SSHKeyController.php
Normal file
58
app/Http/Controllers/Api/Client/SSHKeyController.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Client;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\UserSSHKey;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Transformers\Api\Client\UserSSHKeyTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Account\StoreSSHKeyRequest;
|
||||
|
||||
class SSHKeyController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(Request $request): \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal
|
||||
{
|
||||
return $this->fractal->collection(UserSSHKey::query()->where('user_id', '=', $request->user()->id)->get())
|
||||
->transformWith($this->getTransformer(UserSSHKeyTransformer::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function store(StoreSSHKeyRequest $request): JsonResponse
|
||||
{
|
||||
if ($request->user()->sshKeys->count() >= 5) {
|
||||
throw new DisplayException('You have reached the account limit for number of SSH keys.');
|
||||
}
|
||||
|
||||
$data = array_merge($request->validated(), [
|
||||
'user_id' => $request->user()->id,
|
||||
]);
|
||||
$key = UserSSHKey::query()->create($data);
|
||||
|
||||
return $this->fractal->item($key)
|
||||
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
|
||||
->respond(JsonResponse::HTTP_CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* ?
|
||||
*/
|
||||
public function delete(Request $request, UserSSHKey $sshKey): Response
|
||||
{
|
||||
$sshKey->delete();
|
||||
|
||||
return new Response('', Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue