mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
#591 - server-ssh-keys
This commit is contained in:
60
app/Http/Controllers/SshKeyController.php
Normal file
60
app/Http/Controllers/SshKeyController.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\SshKey\CreateSshKey;
|
||||
use App\Http\Resources\SshKeyResource;
|
||||
use App\Models\SshKey;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Spatie\RouteAttributes\Attributes\Delete;
|
||||
use Spatie\RouteAttributes\Attributes\Get;
|
||||
use Spatie\RouteAttributes\Attributes\Middleware;
|
||||
use Spatie\RouteAttributes\Attributes\Post;
|
||||
use Spatie\RouteAttributes\Attributes\Prefix;
|
||||
|
||||
#[Prefix('settings/ssh-keys')]
|
||||
#[Middleware(['auth'])]
|
||||
class SshKeyController extends Controller
|
||||
{
|
||||
#[Get('/', name: 'ssh-keys')]
|
||||
public function index(): Response
|
||||
{
|
||||
$this->authorize('viewAny', SshKey::class);
|
||||
|
||||
return Inertia::render('ssh-keys/index', [
|
||||
'sshKeys' => SshKeyResource::collection(user()->sshKeys()->simplePaginate(config('web.pagination_size'))),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Get('/json', name: 'ssh-keys.json')]
|
||||
public function json(): ResourceCollection
|
||||
{
|
||||
$this->authorize('viewAny', SshKey::class);
|
||||
|
||||
return SshKeyResource::collection(user()->sshKeys()->get());
|
||||
}
|
||||
|
||||
#[Post('/', name: 'ssh-keys.store')]
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorize('create', SshKey::class);
|
||||
|
||||
app(CreateSshKey::class)->create(user(), $request->input());
|
||||
|
||||
return back()->with('success', 'SSH key created.');
|
||||
}
|
||||
|
||||
#[Delete('/{sshKey}', name: 'ssh-keys.destroy')]
|
||||
public function destroy(SshKey $sshKey): RedirectResponse
|
||||
{
|
||||
$this->authorize('delete', $sshKey);
|
||||
|
||||
$sshKey->delete();
|
||||
|
||||
return back()->with('success', 'SSH key deleted.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user