feat: add deployments as activity
fix: tests refactor: remoteProcess
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
use App\Actions\RemoteProcess\DispatchRemoteProcess;
|
||||
use App\Data\RemoteProcessArgs;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\Activitylog\Contracts\Activity;
|
||||
|
||||
@@ -13,36 +14,33 @@ if (!function_exists('remoteProcess')) {
|
||||
*
|
||||
*/
|
||||
function remoteProcess(
|
||||
string $command,
|
||||
string $destination
|
||||
array $command,
|
||||
Server $server,
|
||||
string|null $deployment_uuid = null,
|
||||
Model|null $model = null,
|
||||
): Activity {
|
||||
$found_server = checkServer($destination);
|
||||
checkTeam($found_server->team_id);
|
||||
$command_string = implode("\n", $command);
|
||||
// @TODO: Check if the user has access to this server
|
||||
// checkTeam($server->team_id);
|
||||
|
||||
$temp_file = 'id.rsa_' . 'root' . '@' . $found_server->ip;
|
||||
Storage::disk('local')->put($temp_file, $found_server->privateKey->private_key, 'private');
|
||||
$temp_file = 'id.rsa_' . 'root' . '@' . $server->ip;
|
||||
Storage::disk('local')->put($temp_file, $server->privateKey->private_key, 'private');
|
||||
$private_key_location = '/var/www/html/storage/app/' . $temp_file;
|
||||
|
||||
return resolve(DispatchRemoteProcess::class, [
|
||||
'remoteProcessArgs' => new RemoteProcessArgs(
|
||||
destination: $found_server->ip,
|
||||
model: $model,
|
||||
server_ip: $server->ip,
|
||||
deployment_uuid: $deployment_uuid,
|
||||
private_key_location: $private_key_location,
|
||||
command: <<<EOT
|
||||
{$command}
|
||||
{$command_string}
|
||||
EOT,
|
||||
port: $found_server->port,
|
||||
user: $found_server->user,
|
||||
port: $server->port,
|
||||
user: $server->user,
|
||||
),
|
||||
])();
|
||||
}
|
||||
function checkServer(string $destination)
|
||||
{
|
||||
// @TODO: Use UUID instead of name
|
||||
$found_server = Server::where('name', $destination)->first();
|
||||
if (!$found_server) {
|
||||
throw new \RuntimeException('Server not found.');
|
||||
};
|
||||
return $found_server;
|
||||
}
|
||||
function checkTeam(string $team_id)
|
||||
{
|
||||
$found_team = auth()->user()->teams->pluck('id')->contains($team_id);
|
||||
|
||||
Reference in New Issue
Block a user