Add run command of predefined server
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
|
||||
use App\Actions\RemoteProcess\DispatchRemoteProcess;
|
||||
use App\Data\RemoteProcessArgs;
|
||||
use App\Models\Server;
|
||||
use Spatie\Activitylog\Contracts\Activity;
|
||||
|
||||
if (! function_exists('remoteProcess')) {
|
||||
if (!function_exists('remoteProcess')) {
|
||||
/**
|
||||
* Run a Coolify Process, which SSH's asynchronously into a machine to run the command(s).
|
||||
* @TODO Change 'root' to 'coolify' when it's able to run Docker commands without sudo
|
||||
@@ -12,17 +13,22 @@ if (! function_exists('remoteProcess')) {
|
||||
*/
|
||||
function remoteProcess(
|
||||
string $command,
|
||||
string $destination,
|
||||
?int $port = 22,
|
||||
?string $user = 'root',
|
||||
): Activity
|
||||
{
|
||||
string $destination
|
||||
): Activity {
|
||||
$found_server = Server::where('name', $destination)->first();
|
||||
if (!$found_server) {
|
||||
throw new \RuntimeException('Server not found.');
|
||||
}
|
||||
$found_team = auth()->user()->teams->pluck('id')->contains($found_server->team_id);
|
||||
if (!$found_team) {
|
||||
throw new \RuntimeException('You do not have access to this server.');
|
||||
}
|
||||
return resolve(DispatchRemoteProcess::class, [
|
||||
'remoteProcessArgs' => new RemoteProcessArgs(
|
||||
destination: $destination,
|
||||
destination: $found_server->ip,
|
||||
command: $command,
|
||||
port: $port,
|
||||
user: $user,
|
||||
port: $found_server->port,
|
||||
user: $found_server->user,
|
||||
),
|
||||
])();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user