mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 15:02:34 +00:00
#591 - server-ssh-keys
This commit is contained in:
@ -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),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user