mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 14:06:15 +00:00
#591 - fix server-ssh-keys
This commit is contained in:
@ -14,6 +14,7 @@
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Knuckles\Scribe\Attributes\BodyParam;
|
use Knuckles\Scribe\Attributes\BodyParam;
|
||||||
use Knuckles\Scribe\Attributes\Endpoint;
|
use Knuckles\Scribe\Attributes\Endpoint;
|
||||||
use Knuckles\Scribe\Attributes\Group;
|
use Knuckles\Scribe\Attributes\Group;
|
||||||
@ -62,8 +63,14 @@ public function create(Request $request, Project $project, Server $server): SshK
|
|||||||
|
|
||||||
$sshKey = null;
|
$sshKey = null;
|
||||||
if ($request->has('key_id')) {
|
if ($request->has('key_id')) {
|
||||||
/** @var SshKey $sshKey */
|
/** @var ?SshKey $sshKey */
|
||||||
$sshKey = $user->sshKeys()->findOrFail($request->key_id);
|
$sshKey = $user->sshKeys()->find($request->key_id);
|
||||||
|
|
||||||
|
if (! $sshKey) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'key' => ['The selected SSH key does not exist.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $sshKey) {
|
if (! $sshKey) {
|
||||||
@ -76,6 +83,9 @@ public function create(Request $request, Project $project, Server $server): SshK
|
|||||||
return new SshKeyResource($sshKey);
|
return new SshKeyResource($sshKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
#[Delete('{sshKey}', name: 'api.projects.servers.ssh-keys.delete', middleware: 'ability:write')]
|
#[Delete('{sshKey}', name: 'api.projects.servers.ssh-keys.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete ssh key from server.')]
|
#[Endpoint(title: 'delete', description: 'Delete ssh key from server.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
use App\Models\SshKey;
|
use App\Models\SshKey;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
use Inertia\Response;
|
use Inertia\Response;
|
||||||
use Spatie\RouteAttributes\Attributes\Delete;
|
use Spatie\RouteAttributes\Attributes\Delete;
|
||||||
@ -40,8 +41,14 @@ public function store(Request $request, Server $server): RedirectResponse
|
|||||||
{
|
{
|
||||||
$this->authorize('createServer', [SshKey::class, $server]);
|
$this->authorize('createServer', [SshKey::class, $server]);
|
||||||
|
|
||||||
/** @var SshKey $sshKey */
|
/** @var ?SshKey $sshKey */
|
||||||
$sshKey = user()->sshKeys()->findOrFail($request->input('key'));
|
$sshKey = user()->sshKeys()->find($request->input('key'));
|
||||||
|
|
||||||
|
if (! $sshKey) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'key' => ['The selected SSH key does not exist.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
app(DeployKeyToServer::class)->deploy($server, $sshKey);
|
app(DeployKeyToServer::class)->deploy($server, $sshKey);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user