mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
refactoring (#116)
- refactoring architecture - fix incomplete ssh logs - code editor for scripts in the app - remove Jobs and SSHCommands
This commit is contained in:
19
app/Actions/SshKey/DeleteKeyFromServer.php
Normal file
19
app/Actions/SshKey/DeleteKeyFromServer.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\SshKey;
|
||||
|
||||
use App\Enums\SshKeyStatus;
|
||||
use App\Models\Server;
|
||||
use App\Models\SshKey;
|
||||
|
||||
class DeleteKeyFromServer
|
||||
{
|
||||
public function delete(Server $server, SshKey $sshKey): void
|
||||
{
|
||||
$sshKey->servers()->updateExistingPivot($server->id, [
|
||||
'status' => SshKeyStatus::DELETING,
|
||||
]);
|
||||
$server->os()->deleteSSHKey($sshKey->public_key);
|
||||
$server->sshKeys()->detach($sshKey);
|
||||
}
|
||||
}
|
38
app/Actions/SshKey/DeployKeyToServer.php
Normal file
38
app/Actions/SshKey/DeployKeyToServer.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\SshKey;
|
||||
|
||||
use App\Enums\SshKeyStatus;
|
||||
use App\Models\Server;
|
||||
use App\Models\SshKey;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class DeployKeyToServer
|
||||
{
|
||||
public function deploy(User $user, Server $server, array $input): void
|
||||
{
|
||||
$this->validate($user, $input);
|
||||
|
||||
/** @var SshKey $sshKey */
|
||||
$sshKey = SshKey::findOrFail($input['key_id']);
|
||||
$server->sshKeys()->attach($sshKey, [
|
||||
'status' => SshKeyStatus::ADDING,
|
||||
]);
|
||||
$server->os()->deploySSHKey($sshKey->public_key);
|
||||
$sshKey->servers()->updateExistingPivot($server->id, [
|
||||
'status' => SshKeyStatus::ADDED,
|
||||
]);
|
||||
}
|
||||
|
||||
private function validate(User $user, array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'key_id' => [
|
||||
'required',
|
||||
Rule::exists('ssh_keys', 'id')->where('user_id', $user->id),
|
||||
],
|
||||
])->validate();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user