Remove daemon command repo

This commit is contained in:
Lance Pioch
2024-03-16 15:11:10 -04:00
parent 4e42cd784a
commit 4969aed383
7 changed files with 53 additions and 57 deletions

View File

@@ -2,8 +2,13 @@
namespace App\Models;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Facades\Http;
use Psr\Http\Message\ResponseInterface;
use Znck\Eloquent\Traits\BelongsToThrough;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -365,4 +370,20 @@ class Server extends Model
return $server;
}
/**
* Sends a command or multiple commands to a running server instance.
*
* @throws DaemonConnectionException|GuzzleException
*/
public function send(array|string $command): ResponseInterface
{
try {
return Http::daemon($this->node)->post("/api/servers/{$this->uuid}/commands", [
'commands' => is_array($command) ? $command : [$command],
])->toPsrResponse();
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}