#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

@ -6,20 +6,14 @@
use App\Exceptions\SSHError;
use App\Models\Server;
use App\Models\SshKey;
use App\Models\User;
use Illuminate\Validation\Rule;
class DeployKeyToServer
{
/**
* @param array<string, mixed> $input
*
* @throws SSHError
*/
public function deploy(Server $server, array $input): void
public function deploy(Server $server, SshKey $sshKey): void
{
/** @var SshKey $sshKey */
$sshKey = SshKey::query()->findOrFail($input['key_id']);
$server->sshKeys()->attach($sshKey, [
'status' => SshKeyStatus::ADDING,
]);
@ -28,18 +22,4 @@ public function deploy(Server $server, array $input): void
'status' => SshKeyStatus::ADDED,
]);
}
/**
* @return array<string, array<string>>
*/
public static function rules(User $user, Server $server): array
{
return [
'key_id' => [
'required',
Rule::exists('ssh_keys', 'id')->where('user_id', $user->id),
Rule::unique('server_ssh_keys', 'ssh_key_id')->where('server_id', $server->id),
],
];
}
}