#591 - server-ssh-keys

This commit is contained in:
Saeed Vaziry
2025-05-29 21:20:33 +02:00
parent 8b6f65db97
commit 0fce4dba9c
22 changed files with 438 additions and 195 deletions

View File

@ -5,6 +5,7 @@
use App\Actions\SshKey\CreateSshKey;
use App\Actions\SshKey\DeleteKeyFromServer;
use App\Actions\SshKey\DeployKeyToServer;
use App\Exceptions\SSHError;
use App\Http\Controllers\Controller;
use App\Http\Resources\SshKeyResource;
use App\Models\Project;
@ -41,6 +42,9 @@ public function index(Project $project, Server $server): ResourceCollection
return SshKeyResource::collection($server->sshKeys()->simplePaginate(25));
}
/**
* @throws SSHError
*/
#[Post('/', name: 'api.projects.servers.ssh-keys.create', middleware: 'ability:write')]
#[Endpoint(title: 'create', description: 'Deploy ssh key to server.')]
#[BodyParam(name: 'key_id', description: 'The ID of the key.')]
@ -58,9 +62,7 @@ public function create(Request $request, Project $project, Server $server): SshK
$sshKey = null;
if ($request->has('key_id')) {
$this->validate($request, DeployKeyToServer::rules($user, $server));
/** @var ?SshKey $sshKey */
/** @var SshKey $sshKey */
$sshKey = $user->sshKeys()->findOrFail($request->key_id);
}
@ -69,7 +71,7 @@ public function create(Request $request, Project $project, Server $server): SshK
$sshKey = app(CreateSshKey::class)->create($user, $request->all());
}
app(DeployKeyToServer::class)->deploy($server, ['key_id' => $sshKey->id]);
app(DeployKeyToServer::class)->deploy($server, $sshKey);
return new SshKeyResource($sshKey);
}