mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-19 09:51:37 +00:00
Add phpstan level 7(#544)
This commit is contained in:
parent
c22bb1fa80
commit
493cbb0849
42
.github/workflows/code-quality.yml
vendored
Normal file
42
.github/workflows/code-quality.yml
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
name: code-quality
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 2.x
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 2.x
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
php: [ 8.2 ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
|
||||||
|
- name: Cache Composer packages
|
||||||
|
id: composer-cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: vendor
|
||||||
|
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-php-
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
if: steps.composer-cache.outputs.cache-hit != 'true'
|
||||||
|
run: composer install --prefer-dist --no-progress --no-suggest
|
||||||
|
|
||||||
|
- name: Run PHPStan
|
||||||
|
run: ./vendor/bin/phpstan analyse
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
class CreateCronJob
|
class CreateCronJob
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function create(Server $server, array $input): CronJob
|
public function create(Server $server, array $input): CronJob
|
||||||
{
|
{
|
||||||
$cronJob = new CronJob([
|
$cronJob = new CronJob([
|
||||||
@ -28,6 +31,10 @@ public function create(Server $server, array $input): CronJob
|
|||||||
return $cronJob;
|
return $cronJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<mixed>>
|
||||||
|
*/
|
||||||
public static function rules(array $input, Server $server): array
|
public static function rules(array $input, Server $server): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
|
@ -5,11 +5,15 @@
|
|||||||
use App\Enums\DatabaseStatus;
|
use App\Enums\DatabaseStatus;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class CreateDatabase
|
class CreateDatabase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function create(Server $server, array $input): Database
|
public function create(Server $server, array $input): Database
|
||||||
{
|
{
|
||||||
$database = new Database([
|
$database = new Database([
|
||||||
@ -18,8 +22,12 @@ public function create(Server $server, array $input): Database
|
|||||||
'collation' => $input['collation'],
|
'collation' => $input['collation'],
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $server->database();
|
||||||
|
|
||||||
/** @var \App\SSH\Services\Database\Database $databaseHandler */
|
/** @var \App\SSH\Services\Database\Database $databaseHandler */
|
||||||
$databaseHandler = $server->database()->handler();
|
$databaseHandler = $service->handler();
|
||||||
$databaseHandler->create($database->name, $database->charset, $database->collation);
|
$databaseHandler->create($database->name, $database->charset, $database->collation);
|
||||||
$database->status = DatabaseStatus::READY;
|
$database->status = DatabaseStatus::READY;
|
||||||
$database->save();
|
$database->save();
|
||||||
@ -34,6 +42,9 @@ public function create(Server $server, array $input): Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public static function rules(Server $server, array $input): array
|
public static function rules(Server $server, array $input): array
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use App\Enums\DatabaseUserStatus;
|
use App\Enums\DatabaseUserStatus;
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use App\SSH\Services\Database\Database;
|
use App\SSH\Services\Database\Database;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
@ -12,6 +13,9 @@
|
|||||||
class CreateDatabaseUser
|
class CreateDatabaseUser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @param array<string> $links
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function create(Server $server, array $input, array $links = []): DatabaseUser
|
public function create(Server $server, array $input, array $links = []): DatabaseUser
|
||||||
@ -23,8 +27,12 @@ public function create(Server $server, array $input, array $links = []): Databas
|
|||||||
'host' => (isset($input['remote']) && $input['remote']) || isset($input['host']) ? $input['host'] : 'localhost',
|
'host' => (isset($input['remote']) && $input['remote']) || isset($input['host']) ? $input['host'] : 'localhost',
|
||||||
'databases' => $links,
|
'databases' => $links,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $server->database();
|
||||||
|
|
||||||
/** @var Database $databaseHandler */
|
/** @var Database $databaseHandler */
|
||||||
$databaseHandler = $server->database()->handler();
|
$databaseHandler = $service->handler();
|
||||||
$databaseHandler->createUser(
|
$databaseHandler->createUser(
|
||||||
$databaseUser->username,
|
$databaseUser->username,
|
||||||
$databaseUser->password,
|
$databaseUser->password,
|
||||||
@ -41,6 +49,9 @@ public function create(Server $server, array $input, array $links = []): Databas
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public static function rules(Server $server, array $input): array
|
public static function rules(Server $server, array $input): array
|
||||||
|
@ -4,12 +4,17 @@
|
|||||||
|
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
|
|
||||||
class DeleteDatabase
|
class DeleteDatabase
|
||||||
{
|
{
|
||||||
public function delete(Server $server, Database $database): void
|
public function delete(Server $server, Database $database): void
|
||||||
{
|
{
|
||||||
$server->database()->handler()->delete($database->name);
|
/** @var Service $service */
|
||||||
|
$service = $server->database();
|
||||||
|
/** @var \App\SSH\Services\Database\Database $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
$handler->delete($database->name);
|
||||||
$database->delete();
|
$database->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,18 @@
|
|||||||
|
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
|
use App\SSH\Services\Database\Database;
|
||||||
|
|
||||||
class DeleteDatabaseUser
|
class DeleteDatabaseUser
|
||||||
{
|
{
|
||||||
public function delete(Server $server, DatabaseUser $databaseUser): void
|
public function delete(Server $server, DatabaseUser $databaseUser): void
|
||||||
{
|
{
|
||||||
$server->database()->handler()->deleteUser($databaseUser->username, $databaseUser->host);
|
/** @var Service $service */
|
||||||
|
$service = $server->database();
|
||||||
|
/** @var Database $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
$handler->deleteUser($databaseUser->username, $databaseUser->host);
|
||||||
$databaseUser->delete();
|
$databaseUser->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,16 @@
|
|||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class LinkUser
|
class LinkUser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return DatabaseUser $databaseUser
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function link(DatabaseUser $databaseUser, array $input): DatabaseUser
|
public function link(DatabaseUser $databaseUser, array $input): DatabaseUser
|
||||||
@ -29,14 +33,20 @@ public function link(DatabaseUser $databaseUser, array $input): DatabaseUser
|
|||||||
|
|
||||||
$databaseUser->databases = $input['databases'];
|
$databaseUser->databases = $input['databases'];
|
||||||
|
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $databaseUser->server->database();
|
||||||
|
|
||||||
|
/** @var \App\SSH\Services\Database\Database $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
|
||||||
// Unlink the user from all databases
|
// Unlink the user from all databases
|
||||||
$databaseUser->server->database()->handler()->unlink(
|
$handler->unlink(
|
||||||
$databaseUser->username,
|
$databaseUser->username,
|
||||||
$databaseUser->host
|
$databaseUser->host
|
||||||
);
|
);
|
||||||
|
|
||||||
// Link the user to the selected databases
|
// Link the user to the selected databases
|
||||||
$databaseUser->server->database()->handler()->link(
|
$handler->link(
|
||||||
$databaseUser->username,
|
$databaseUser->username,
|
||||||
$databaseUser->host,
|
$databaseUser->host,
|
||||||
$databaseUser->databases
|
$databaseUser->databases
|
||||||
@ -49,6 +59,10 @@ public function link(DatabaseUser $databaseUser, array $input): DatabaseUser
|
|||||||
return $databaseUser;
|
return $databaseUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(Server $server, array $input): array
|
public static function rules(Server $server, array $input): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
class ManageBackup
|
class ManageBackup
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws AuthorizationException
|
* @throws AuthorizationException
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
@ -35,6 +37,9 @@ public function create(Server $server, array $input): Backup
|
|||||||
return $backup;
|
return $backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function update(Backup $backup, array $input): void
|
public function update(Backup $backup, array $input): void
|
||||||
{
|
{
|
||||||
$backup->interval = $input['interval'] == 'custom' ? $input['custom_interval'] : $input['interval'];
|
$backup->interval = $input['interval'] == 'custom' ? $input['custom_interval'] : $input['interval'];
|
||||||
@ -47,7 +52,7 @@ public function delete(Backup $backup): void
|
|||||||
$backup->status = BackupStatus::DELETING;
|
$backup->status = BackupStatus::DELETING;
|
||||||
$backup->save();
|
$backup->save();
|
||||||
|
|
||||||
dispatch(function () use ($backup) {
|
dispatch(function () use ($backup): void {
|
||||||
$files = $backup->files;
|
$files = $backup->files;
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$file->status = BackupFileStatus::DELETING;
|
$file->status = BackupFileStatus::DELETING;
|
||||||
@ -60,6 +65,10 @@ public function delete(Backup $backup): void
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(Server $server, array $input): array
|
public static function rules(Server $server, array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
|
@ -28,7 +28,7 @@ public function delete(BackupFile $file): void
|
|||||||
$file->status = BackupFileStatus::DELETING;
|
$file->status = BackupFileStatus::DELETING;
|
||||||
$file->save();
|
$file->save();
|
||||||
|
|
||||||
dispatch(function () use ($file) {
|
dispatch(function () use ($file): void {
|
||||||
$file->deleteFile();
|
$file->deleteFile();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,13 @@
|
|||||||
use App\Enums\BackupFileStatus;
|
use App\Enums\BackupFileStatus;
|
||||||
use App\Models\BackupFile;
|
use App\Models\BackupFile;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
|
use App\Models\Service;
|
||||||
|
|
||||||
class RestoreBackup
|
class RestoreBackup
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function restore(BackupFile $backupFile, array $input): void
|
public function restore(BackupFile $backupFile, array $input): void
|
||||||
{
|
{
|
||||||
/** @var Database $database */
|
/** @var Database $database */
|
||||||
@ -16,19 +20,24 @@ public function restore(BackupFile $backupFile, array $input): void
|
|||||||
$backupFile->restored_to = $database->name;
|
$backupFile->restored_to = $database->name;
|
||||||
$backupFile->save();
|
$backupFile->save();
|
||||||
|
|
||||||
dispatch(function () use ($backupFile, $database) {
|
dispatch(function () use ($backupFile, $database): void {
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $database->server->database();
|
||||||
/** @var \App\SSH\Services\Database\Database $databaseHandler */
|
/** @var \App\SSH\Services\Database\Database $databaseHandler */
|
||||||
$databaseHandler = $database->server->database()->handler();
|
$databaseHandler = $service->handler();
|
||||||
$databaseHandler->restoreBackup($backupFile, $database->name);
|
$databaseHandler->restoreBackup($backupFile, $database->name);
|
||||||
$backupFile->status = BackupFileStatus::RESTORED;
|
$backupFile->status = BackupFileStatus::RESTORED;
|
||||||
$backupFile->restored_at = now();
|
$backupFile->restored_at = now();
|
||||||
$backupFile->save();
|
$backupFile->save();
|
||||||
})->catch(function () use ($backupFile) {
|
})->catch(function () use ($backupFile): void {
|
||||||
$backupFile->status = BackupFileStatus::RESTORE_FAILED;
|
$backupFile->status = BackupFileStatus::RESTORE_FAILED;
|
||||||
$backupFile->save();
|
$backupFile->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
use App\Enums\BackupStatus;
|
use App\Enums\BackupStatus;
|
||||||
use App\Models\Backup;
|
use App\Models\Backup;
|
||||||
use App\Models\BackupFile;
|
use App\Models\BackupFile;
|
||||||
|
use App\Models\Service;
|
||||||
use App\SSH\Services\Database\Database;
|
use App\SSH\Services\Database\Database;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
@ -20,9 +21,11 @@ public function run(Backup $backup): BackupFile
|
|||||||
]);
|
]);
|
||||||
$file->save();
|
$file->save();
|
||||||
|
|
||||||
dispatch(function () use ($file, $backup) {
|
dispatch(function () use ($file, $backup): void {
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $backup->server->database();
|
||||||
/** @var Database $databaseHandler */
|
/** @var Database $databaseHandler */
|
||||||
$databaseHandler = $file->backup->server->database()->handler();
|
$databaseHandler = $service->handler();
|
||||||
$databaseHandler->runBackup($file);
|
$databaseHandler->runBackup($file);
|
||||||
$file->status = BackupFileStatus::CREATED;
|
$file->status = BackupFileStatus::CREATED;
|
||||||
$file->save();
|
$file->save();
|
||||||
@ -31,7 +34,7 @@ public function run(Backup $backup): BackupFile
|
|||||||
$backup->status = BackupStatus::RUNNING;
|
$backup->status = BackupStatus::RUNNING;
|
||||||
$backup->save();
|
$backup->save();
|
||||||
}
|
}
|
||||||
})->catch(function () use ($file, $backup) {
|
})->catch(function () use ($file, $backup): void {
|
||||||
$backup->status = BackupStatus::FAILED;
|
$backup->status = BackupStatus::FAILED;
|
||||||
$backup->save();
|
$backup->save();
|
||||||
$file->status = BackupFileStatus::FAILED;
|
$file->status = BackupFileStatus::FAILED;
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
class FetchFiles
|
class FetchFiles
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws SSHError
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function fetch(User $user, Server $server, array $input): void
|
public function fetch(User $user, Server $server, array $input): void
|
||||||
@ -24,6 +26,9 @@ public function fetch(User $user, Server $server, array $input): void
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Server $server): array
|
public static function rules(Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -5,10 +5,16 @@
|
|||||||
use App\Enums\FirewallRuleStatus;
|
use App\Enums\FirewallRuleStatus;
|
||||||
use App\Models\FirewallRule;
|
use App\Models\FirewallRule;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use App\SSH\Services\Firewall\Firewall;
|
use App\SSH\Services\Firewall\Firewall;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class ManageRule
|
class ManageRule
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return FirewallRule $rule
|
||||||
|
*/
|
||||||
public function create(Server $server, array $input): FirewallRule
|
public function create(Server $server, array $input): FirewallRule
|
||||||
{
|
{
|
||||||
$sourceAny = $input['source_any'] ?? empty($input['source'] ?? null);
|
$sourceAny = $input['source_any'] ?? empty($input['source'] ?? null);
|
||||||
@ -30,6 +36,10 @@ public function create(Server $server, array $input): FirewallRule
|
|||||||
return $rule;
|
return $rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return FirewallRule $rule
|
||||||
|
*/
|
||||||
public function update(FirewallRule $rule, array $input): FirewallRule
|
public function update(FirewallRule $rule, array $input): FirewallRule
|
||||||
{
|
{
|
||||||
$sourceAny = $input['source_any'] ?? empty($input['source'] ?? null);
|
$sourceAny = $input['source_any'] ?? empty($input['source'] ?? null);
|
||||||
@ -56,18 +66,20 @@ public function delete(FirewallRule $rule): void
|
|||||||
dispatch(fn () => $this->applyRule($rule));
|
dispatch(fn () => $this->applyRule($rule));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function applyRule($rule): void
|
protected function applyRule(FirewallRule $rule): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $rule->server->firewall();
|
||||||
/** @var Firewall $handler */
|
/** @var Firewall $handler */
|
||||||
$handler = $rule->server->firewall()->handler();
|
$handler = $service->handler();
|
||||||
$handler->applyRules();
|
$handler->applyRules();
|
||||||
} catch (\Exception $e) {
|
} catch (Exception) {
|
||||||
$rule->server->firewallRules()
|
$rule->server->firewallRules()
|
||||||
->where('status', '!=', FirewallRuleStatus::READY)
|
->where('status', '!=', FirewallRuleStatus::READY)
|
||||||
->update(['status' => FirewallRuleStatus::FAILED]);
|
->update(['status' => FirewallRuleStatus::FAILED]);
|
||||||
|
|
||||||
throw $e;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rule->status === FirewallRuleStatus::DELETING) {
|
if ($rule->status === FirewallRuleStatus::DELETING) {
|
||||||
@ -80,6 +92,9 @@ protected function applyRule($rule): void
|
|||||||
$rule->save();
|
$rule->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
class GetMetrics
|
class GetMetrics
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return Collection<int, mixed>
|
||||||
|
*/
|
||||||
public function filter(Server $server, array $input): Collection
|
public function filter(Server $server, array $input): Collection
|
||||||
{
|
{
|
||||||
if (isset($input['from']) && isset($input['to']) && $input['from'] === $input['to']) {
|
if (isset($input['from']) && isset($input['to']) && $input['from'] === $input['to']) {
|
||||||
@ -32,6 +36,9 @@ public function filter(Server $server, array $input): Collection
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, mixed>
|
||||||
|
*/
|
||||||
private function metrics(
|
private function metrics(
|
||||||
Server $server,
|
Server $server,
|
||||||
Carbon $fromDate,
|
Carbon $fromDate,
|
||||||
@ -57,13 +64,16 @@ private function metrics(
|
|||||||
->groupByRaw('date_interval')
|
->groupByRaw('date_interval')
|
||||||
->orderBy('date_interval')
|
->orderBy('date_interval')
|
||||||
->get()
|
->get()
|
||||||
->map(function ($item) {
|
->map(function ($item): \stdClass {
|
||||||
$item->date = Carbon::parse($item->date)->format('Y-m-d H:i');
|
$item->date = Carbon::parse($item->date)->format('Y-m-d H:i');
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
private function getFromDate(array $input): Carbon
|
private function getFromDate(array $input): Carbon
|
||||||
{
|
{
|
||||||
if ($input['period'] === 'custom') {
|
if ($input['period'] === 'custom') {
|
||||||
@ -73,6 +83,9 @@ private function getFromDate(array $input): Carbon
|
|||||||
return Carbon::parse('-'.convert_time_format($input['period']));
|
return Carbon::parse('-'.convert_time_format($input['period']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
private function getToDate(array $input): Carbon
|
private function getToDate(array $input): Carbon
|
||||||
{
|
{
|
||||||
if ($input['period'] === 'custom') {
|
if ($input['period'] === 'custom') {
|
||||||
@ -82,6 +95,9 @@ private function getToDate(array $input): Carbon
|
|||||||
return Carbon::now();
|
return Carbon::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
private function getInterval(array $input): Expression
|
private function getInterval(array $input): Expression
|
||||||
{
|
{
|
||||||
if ($input['period'] === 'custom') {
|
if ($input['period'] === 'custom') {
|
||||||
@ -107,6 +123,10 @@ private function getInterval(array $input): Expression
|
|||||||
return DB::raw("strftime('%Y-%m-%d 00:00:00', created_at) as date_interval");
|
return DB::raw("strftime('%Y-%m-%d 00:00:00', created_at) as date_interval");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
|
@ -3,19 +3,29 @@
|
|||||||
namespace App\Actions\Monitoring;
|
namespace App\Actions\Monitoring;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
|
use App\SSH\Services\ServiceInterface;
|
||||||
|
|
||||||
class UpdateMetricSettings
|
class UpdateMetricSettings
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function update(Server $server, array $input): void
|
public function update(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
|
/** @var Service $service */
|
||||||
$service = $server->monitoring();
|
$service = $server->monitoring();
|
||||||
|
/** @var ServiceInterface $handler */
|
||||||
$data = $service->handler()->data();
|
$handler = $service->handler();
|
||||||
|
$data = $handler->data();
|
||||||
$data['data_retention'] = $input['data_retention'];
|
$data['data_retention'] = $input['data_retention'];
|
||||||
$service->type_data = $data;
|
$service->type_data = $data;
|
||||||
$service->save();
|
$service->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -3,24 +3,38 @@
|
|||||||
namespace App\Actions\NodeJS;
|
namespace App\Actions\NodeJS;
|
||||||
|
|
||||||
use App\Enums\ServiceStatus;
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use App\SSH\Services\NodeJS\NodeJS;
|
use App\SSH\Services\NodeJS\NodeJS;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ChangeDefaultCli
|
class ChangeDefaultCli
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function change(Server $server, array $input): void
|
public function change(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($server, $input);
|
$this->validate($server, $input);
|
||||||
|
/** @var Service $service */
|
||||||
$service = $server->nodejs($input['version']);
|
$service = $server->nodejs($input['version']);
|
||||||
/** @var NodeJS $handler */
|
/** @var NodeJS $handler */
|
||||||
$handler = $service->handler();
|
$handler = $service->handler();
|
||||||
$handler->setDefaultCli();
|
$handler->setDefaultCli();
|
||||||
$server->defaultService('nodejs')->update(['is_default' => 0]);
|
$server->defaultService('nodejs')?->update(['is_default' => 0]);
|
||||||
$service->update(['is_default' => 1]);
|
$service->update(['is_default' => 1]);
|
||||||
$service->update(['status' => ServiceStatus::READY]);
|
$service->update(['status' => ServiceStatus::READY]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function validate(Server $server, array $input): void
|
public function validate(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
if (! isset($input['version']) || ! in_array($input['version'], $server->installedNodejsVersions())) {
|
if (! isset($input['version']) || ! in_array($input['version'], $server->installedNodejsVersions())) {
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
class InstallNewNodeJsVersion
|
class InstallNewNodeJsVersion
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function install(Server $server, array $input): void
|
public function install(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$nodejs = new Service([
|
$nodejs = new Service([
|
||||||
@ -23,15 +26,18 @@ public function install(Server $server, array $input): void
|
|||||||
]);
|
]);
|
||||||
$nodejs->save();
|
$nodejs->save();
|
||||||
|
|
||||||
dispatch(function () use ($nodejs) {
|
dispatch(function () use ($nodejs): void {
|
||||||
$nodejs->handler()->install();
|
$nodejs->handler()->install();
|
||||||
$nodejs->status = ServiceStatus::READY;
|
$nodejs->status = ServiceStatus::READY;
|
||||||
$nodejs->save();
|
$nodejs->save();
|
||||||
})->catch(function () use ($nodejs) {
|
})->catch(function () use ($nodejs): void {
|
||||||
$nodejs->delete();
|
$nodejs->delete();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Server $server): array
|
public static function rules(Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -10,6 +10,11 @@
|
|||||||
|
|
||||||
class UninstallNodeJS
|
class UninstallNodeJS
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function uninstall(Server $server, array $input): void
|
public function uninstall(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($server, $input);
|
$this->validate($server, $input);
|
||||||
@ -19,16 +24,18 @@ public function uninstall(Server $server, array $input): void
|
|||||||
$nodejs->status = ServiceStatus::UNINSTALLING;
|
$nodejs->status = ServiceStatus::UNINSTALLING;
|
||||||
$nodejs->save();
|
$nodejs->save();
|
||||||
|
|
||||||
dispatch(function () use ($nodejs) {
|
dispatch(function () use ($nodejs): void {
|
||||||
$nodejs->handler()->uninstall();
|
$nodejs->handler()->uninstall();
|
||||||
$nodejs->delete();
|
$nodejs->delete();
|
||||||
})->catch(function () use ($nodejs) {
|
})->catch(function () use ($nodejs): void {
|
||||||
$nodejs->status = ServiceStatus::FAILED;
|
$nodejs->status = ServiceStatus::FAILED;
|
||||||
$nodejs->save();
|
$nodejs->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private function validate(Server $server, array $input): void
|
private function validate(Server $server, array $input): void
|
||||||
|
@ -11,8 +11,9 @@
|
|||||||
class AddChannel
|
class AddChannel
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function add(User $user, array $input): void
|
public function add(User $user, array $input): void
|
||||||
{
|
{
|
||||||
@ -42,13 +43,19 @@ public function add(User $user, array $input): void
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$channel->delete();
|
$channel->delete();
|
||||||
|
|
||||||
throw $e;
|
throw ValidationException::withMessages([
|
||||||
|
'provider' => $e->getMessage(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$channel->connected = true;
|
$channel->connected = true;
|
||||||
$channel->save();
|
$channel->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
@ -59,9 +66,13 @@ public static function rules(array $input): array
|
|||||||
'label' => 'required',
|
'label' => 'required',
|
||||||
];
|
];
|
||||||
|
|
||||||
return array_merge($rules, static::providerRules($input));
|
return array_merge($rules, self::providerRules($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
private static function providerRules(array $input): array
|
private static function providerRules(array $input): array
|
||||||
{
|
{
|
||||||
if (! isset($input['provider'])) {
|
if (! isset($input['provider'])) {
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
class EditChannel
|
class EditChannel
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function edit(NotificationChannel $notificationChannel, User $user, array $input): void
|
public function edit(NotificationChannel $notificationChannel, User $user, array $input): void
|
||||||
{
|
{
|
||||||
$notificationChannel->fill([
|
$notificationChannel->fill([
|
||||||
@ -16,6 +19,10 @@ public function edit(NotificationChannel $notificationChannel, User $user, array
|
|||||||
$notificationChannel->save();
|
$notificationChannel->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -3,24 +3,37 @@
|
|||||||
namespace App\Actions\PHP;
|
namespace App\Actions\PHP;
|
||||||
|
|
||||||
use App\Enums\ServiceStatus;
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use App\SSH\Services\PHP\PHP;
|
use App\SSH\Services\PHP\PHP;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ChangeDefaultCli
|
class ChangeDefaultCli
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function change(Server $server, array $input): void
|
public function change(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($server, $input);
|
$this->validate($server, $input);
|
||||||
|
/** @var Service $service */
|
||||||
$service = $server->php($input['version']);
|
$service = $server->php($input['version']);
|
||||||
/** @var PHP $handler */
|
/** @var PHP $handler */
|
||||||
$handler = $service->handler();
|
$handler = $service->handler();
|
||||||
$handler->setDefaultCli();
|
$handler->setDefaultCli();
|
||||||
$server->defaultService('php')->update(['is_default' => 0]);
|
$server->defaultService('php')?->update(['is_default' => 0]);
|
||||||
$service->update(['is_default' => 1]);
|
$service->update(['is_default' => 1]);
|
||||||
$service->update(['status' => ServiceStatus::READY]);
|
$service->update(['status' => ServiceStatus::READY]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function validate(Server $server, array $input): void
|
public function validate(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
if (! isset($input['version']) || ! in_array($input['version'], $server->installedPHPVersions())) {
|
if (! isset($input['version']) || ! in_array($input['version'], $server->installedPHPVersions())) {
|
||||||
|
@ -4,17 +4,25 @@
|
|||||||
|
|
||||||
use App\Enums\PHPIniType;
|
use App\Enums\PHPIniType;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use App\SSH\Services\PHP\PHP;
|
use App\SSH\Services\PHP\PHP;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class GetPHPIni
|
class GetPHPIni
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function getIni(Server $server, array $input): string
|
public function getIni(Server $server, array $input): string
|
||||||
{
|
{
|
||||||
$this->validate($server, $input);
|
$this->validate($server, $input);
|
||||||
|
|
||||||
|
/** @var Service $php */
|
||||||
$php = $server->php($input['version']);
|
$php = $server->php($input['version']);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -22,13 +30,18 @@ public function getIni(Server $server, array $input): string
|
|||||||
$handler = $php->handler();
|
$handler = $php->handler();
|
||||||
|
|
||||||
return $handler->getPHPIni($input['type']);
|
return $handler->getPHPIni($input['type']);
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
throw ValidationException::withMessages(
|
throw ValidationException::withMessages(
|
||||||
['ini' => $e->getMessage()]
|
['ini' => $e->getMessage()]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function validate(Server $server, array $input): void
|
public function validate(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
class InstallNewPHP
|
class InstallNewPHP
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function install(Server $server, array $input): void
|
public function install(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$php = new Service([
|
$php = new Service([
|
||||||
@ -26,15 +29,18 @@ public function install(Server $server, array $input): void
|
|||||||
]);
|
]);
|
||||||
$php->save();
|
$php->save();
|
||||||
|
|
||||||
dispatch(function () use ($php) {
|
dispatch(function () use ($php): void {
|
||||||
$php->handler()->install();
|
$php->handler()->install();
|
||||||
$php->status = ServiceStatus::READY;
|
$php->status = ServiceStatus::READY;
|
||||||
$php->save();
|
$php->save();
|
||||||
})->catch(function () use ($php) {
|
})->catch(function () use ($php): void {
|
||||||
$php->delete();
|
$php->delete();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Server $server): array
|
public static function rules(Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Actions\PHP;
|
namespace App\Actions\PHP;
|
||||||
|
|
||||||
use App\Exceptions\SSHCommandError;
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
use App\SSH\Services\PHP\PHP;
|
use App\SSH\Services\PHP\PHP;
|
||||||
@ -11,6 +10,11 @@
|
|||||||
|
|
||||||
class InstallPHPExtension
|
class InstallPHPExtension
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function install(Server $server, array $input): Service
|
public function install(Server $server, array $input): Service
|
||||||
{
|
{
|
||||||
/** @var Service $service */
|
/** @var Service $service */
|
||||||
@ -23,20 +27,17 @@ public function install(Server $server, array $input): Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
$typeData = $service->type_data;
|
$typeData = $service->type_data;
|
||||||
$typeData['extensions'] = $typeData['extensions'] ?? [];
|
$typeData['extensions'] ??= [];
|
||||||
$typeData['extensions'][] = $input['extension'];
|
$typeData['extensions'][] = $input['extension'];
|
||||||
$service->type_data = $typeData;
|
$service->type_data = $typeData;
|
||||||
$service->save();
|
$service->save();
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
/**
|
function () use ($service, $input): void {
|
||||||
* @throws SSHCommandError
|
|
||||||
*/
|
|
||||||
function () use ($service, $input) {
|
|
||||||
/** @var PHP $handler */
|
/** @var PHP $handler */
|
||||||
$handler = $service->handler();
|
$handler = $service->handler();
|
||||||
$handler->installExtension($input['extension']);
|
$handler->installExtension($input['extension']);
|
||||||
})->catch(function () use ($service, $input) {
|
})->catch(function () use ($service, $input): void {
|
||||||
$service->refresh();
|
$service->refresh();
|
||||||
$typeData = $service->type_data;
|
$typeData = $service->type_data;
|
||||||
$typeData['extensions'] = array_values(array_diff($typeData['extensions'], [$input['extension']]));
|
$typeData['extensions'] = array_values(array_diff($typeData['extensions'], [$input['extension']]));
|
||||||
@ -47,6 +48,9 @@ function () use ($service, $input) {
|
|||||||
return $service;
|
return $service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Server $server): array
|
public static function rules(Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -10,6 +10,11 @@
|
|||||||
|
|
||||||
class UninstallPHP
|
class UninstallPHP
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function uninstall(Server $server, array $input): void
|
public function uninstall(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($server, $input);
|
$this->validate($server, $input);
|
||||||
@ -19,16 +24,18 @@ public function uninstall(Server $server, array $input): void
|
|||||||
$php->status = ServiceStatus::UNINSTALLING;
|
$php->status = ServiceStatus::UNINSTALLING;
|
||||||
$php->save();
|
$php->save();
|
||||||
|
|
||||||
dispatch(function () use ($php) {
|
dispatch(function () use ($php): void {
|
||||||
$php->handler()->uninstall();
|
$php->handler()->uninstall();
|
||||||
$php->delete();
|
$php->delete();
|
||||||
})->catch(function () use ($php) {
|
})->catch(function () use ($php): void {
|
||||||
$php->status = ServiceStatus::FAILED;
|
$php->status = ServiceStatus::FAILED;
|
||||||
$php->save();
|
$php->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private function validate(Server $server, array $input): void
|
private function validate(Server $server, array $input): void
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Enums\PHPIniType;
|
use App\Enums\PHPIniType;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -14,10 +15,13 @@
|
|||||||
class UpdatePHPIni
|
class UpdatePHPIni
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function update(Server $server, array $input): void
|
public function update(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
|
/** @var Service $service */
|
||||||
$service = $server->php($input['version']);
|
$service = $server->php($input['version']);
|
||||||
|
|
||||||
$tmpName = Str::random(10).strtotime('now');
|
$tmpName = Str::random(10).strtotime('now');
|
||||||
@ -48,6 +52,9 @@ private function deleteTempFile(string $name): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Server $server): array
|
public static function rules(Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
class AddUser
|
class AddUser
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function add(Project $project, array $input): void
|
public function add(Project $project, array $input): void
|
||||||
{
|
{
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
@ -18,13 +21,16 @@ public function add(Project $project, array $input): void
|
|||||||
$project->users()->attach($user);
|
$project->users()->attach($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Project $project): array
|
public static function rules(Project $project): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'user' => [
|
'user' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::exists('users', 'id'),
|
Rule::exists('users', 'id'),
|
||||||
Rule::unique('user_project', 'user_id')->where(function (Builder $query) use ($project) {
|
Rule::unique('user_project', 'user_id')->where(function (Builder $query) use ($project): void {
|
||||||
$query->where('project_id', $project->id);
|
$query->where('project_id', $project->id);
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -8,10 +8,13 @@
|
|||||||
|
|
||||||
class CreateProject
|
class CreateProject
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function create(User $user, array $input): Project
|
public function create(User $user, array $input): Project
|
||||||
{
|
{
|
||||||
if (isset($input['name'])) {
|
if (isset($input['name'])) {
|
||||||
$input['name'] = strtolower($input['name']);
|
$input['name'] = strtolower((string) $input['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->validate($input);
|
$this->validate($input);
|
||||||
@ -27,6 +30,9 @@ public function create(User $user, array $input): Project
|
|||||||
return $project;
|
return $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -40,6 +46,9 @@ public static function rules(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
private function validate(array $input): void
|
private function validate(array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, self::rules())->validate();
|
Validator::make($input, self::rules())->validate();
|
||||||
|
@ -8,10 +8,13 @@
|
|||||||
|
|
||||||
class UpdateProject
|
class UpdateProject
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function update(Project $project, array $input): Project
|
public function update(Project $project, array $input): Project
|
||||||
{
|
{
|
||||||
if (isset($input['name'])) {
|
if (isset($input['name'])) {
|
||||||
$input['name'] = strtolower($input['name']);
|
$input['name'] = strtolower((string) $input['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->validate($project, $input);
|
$this->validate($project, $input);
|
||||||
@ -23,6 +26,9 @@ public function update(Project $project, array $input): Project
|
|||||||
return $project;
|
return $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Project $project): array
|
public static function rules(Project $project): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -36,6 +42,9 @@ public static function rules(Project $project): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
private function validate(Project $project, array $input): void
|
private function validate(Project $project, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, self::rules($project))->validate();
|
Validator::make($input, self::rules($project))->validate();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use App\Enums\QueueStatus;
|
use App\Enums\QueueStatus;
|
||||||
use App\Models\Queue;
|
use App\Models\Queue;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\Services\ProcessManager\ProcessManager;
|
use App\SSH\Services\ProcessManager\ProcessManager;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
@ -13,6 +14,9 @@
|
|||||||
class CreateQueue
|
class CreateQueue
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param Server|Site $queueable
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function create(mixed $queueable, array $input): void
|
public function create(mixed $queueable, array $input): void
|
||||||
@ -29,9 +33,11 @@ public function create(mixed $queueable, array $input): void
|
|||||||
]);
|
]);
|
||||||
$queue->save();
|
$queue->save();
|
||||||
|
|
||||||
dispatch(function () use ($queue) {
|
dispatch(function () use ($queue): void {
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $queue->server->processManager();
|
||||||
/** @var ProcessManager $processManager */
|
/** @var ProcessManager $processManager */
|
||||||
$processManager = $queue->server->processManager()->handler();
|
$processManager = $service->handler();
|
||||||
$processManager->create(
|
$processManager->create(
|
||||||
$queue->id,
|
$queue->id,
|
||||||
$queue->command,
|
$queue->command,
|
||||||
@ -44,11 +50,14 @@ public function create(mixed $queueable, array $input): void
|
|||||||
);
|
);
|
||||||
$queue->status = QueueStatus::RUNNING;
|
$queue->status = QueueStatus::RUNNING;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
})->catch(function () use ($queue) {
|
})->catch(function () use ($queue): void {
|
||||||
$queue->delete();
|
$queue->delete();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Site $site): array
|
public static function rules(Site $site): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use App\Enums\QueueStatus;
|
use App\Enums\QueueStatus;
|
||||||
use App\Models\Queue;
|
use App\Models\Queue;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\Service;
|
||||||
use App\SSH\Services\ProcessManager\ProcessManager;
|
use App\SSH\Services\ProcessManager\ProcessManager;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
@ -12,6 +13,8 @@
|
|||||||
class EditQueue
|
class EditQueue
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function edit(Queue $queue, array $input): void
|
public function edit(Queue $queue, array $input): void
|
||||||
@ -26,9 +29,11 @@ public function edit(Queue $queue, array $input): void
|
|||||||
]);
|
]);
|
||||||
$queue->save();
|
$queue->save();
|
||||||
|
|
||||||
dispatch(function () use ($queue) {
|
dispatch(function () use ($queue): void {
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $queue->server->processManager();
|
||||||
/** @var ProcessManager $processManager */
|
/** @var ProcessManager $processManager */
|
||||||
$processManager = $queue->server->processManager()->handler();
|
$processManager = $service->handler();
|
||||||
$processManager->delete($queue->id, $queue->site_id);
|
$processManager->delete($queue->id, $queue->site_id);
|
||||||
|
|
||||||
$processManager->create(
|
$processManager->create(
|
||||||
@ -43,12 +48,15 @@ public function edit(Queue $queue, array $input): void
|
|||||||
);
|
);
|
||||||
$queue->status = QueueStatus::RUNNING;
|
$queue->status = QueueStatus::RUNNING;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
})->catch(function () use ($queue) {
|
})->catch(function () use ($queue): void {
|
||||||
$queue->status = QueueStatus::FAILED;
|
$queue->status = QueueStatus::FAILED;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Server $server): array
|
public static function rules(Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -3,11 +3,19 @@
|
|||||||
namespace App\Actions\Queue;
|
namespace App\Actions\Queue;
|
||||||
|
|
||||||
use App\Models\Queue;
|
use App\Models\Queue;
|
||||||
|
use App\Models\Service;
|
||||||
|
use App\SSH\Services\ProcessManager\ProcessManager;
|
||||||
|
|
||||||
class GetQueueLogs
|
class GetQueueLogs
|
||||||
{
|
{
|
||||||
public function getLogs(Queue $queue): string
|
public function getLogs(Queue $queue): string
|
||||||
{
|
{
|
||||||
return $queue->server->processManager()->handler()->getLogs($queue->user, $queue->getLogFile());
|
/** @var Service $service */
|
||||||
|
$service = $queue->server->processManager();
|
||||||
|
|
||||||
|
/** @var ProcessManager $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
|
||||||
|
return $handler->getLogs($queue->user, $queue->getLogFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
use App\Enums\QueueStatus;
|
use App\Enums\QueueStatus;
|
||||||
use App\Models\Queue;
|
use App\Models\Queue;
|
||||||
|
use App\Models\Service;
|
||||||
|
use App\SSH\Services\ProcessManager\ProcessManager;
|
||||||
|
|
||||||
class ManageQueue
|
class ManageQueue
|
||||||
{
|
{
|
||||||
@ -11,8 +13,12 @@ public function start(Queue $queue): void
|
|||||||
{
|
{
|
||||||
$queue->status = QueueStatus::STARTING;
|
$queue->status = QueueStatus::STARTING;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
dispatch(function () use ($queue) {
|
dispatch(function () use ($queue): void {
|
||||||
$queue->server->processManager()->handler()->start($queue->id, $queue->site_id);
|
/** @var Service $service */
|
||||||
|
$service = $queue->server->processManager();
|
||||||
|
/** @var ProcessManager $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
$handler->start($queue->id, $queue->site_id);
|
||||||
$queue->status = QueueStatus::RUNNING;
|
$queue->status = QueueStatus::RUNNING;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
@ -22,8 +28,12 @@ public function stop(Queue $queue): void
|
|||||||
{
|
{
|
||||||
$queue->status = QueueStatus::STOPPING;
|
$queue->status = QueueStatus::STOPPING;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
dispatch(function () use ($queue) {
|
dispatch(function () use ($queue): void {
|
||||||
$queue->server->processManager()->handler()->stop($queue->id, $queue->site_id);
|
/** @var Service $service */
|
||||||
|
$service = $queue->server->processManager();
|
||||||
|
/** @var ProcessManager $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
$handler->stop($queue->id, $queue->site_id);
|
||||||
$queue->status = QueueStatus::STOPPED;
|
$queue->status = QueueStatus::STOPPED;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
@ -33,8 +43,12 @@ public function restart(Queue $queue): void
|
|||||||
{
|
{
|
||||||
$queue->status = QueueStatus::RESTARTING;
|
$queue->status = QueueStatus::RESTARTING;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
dispatch(function () use ($queue) {
|
dispatch(function () use ($queue): void {
|
||||||
$queue->server->processManager()->handler()->restart($queue->id, $queue->site_id);
|
/** @var Service $service */
|
||||||
|
$service = $queue->server->processManager();
|
||||||
|
/** @var ProcessManager $handler */
|
||||||
|
$handler = $service->handler();
|
||||||
|
$handler->restart($queue->id, $queue->site_id);
|
||||||
$queue->status = QueueStatus::RUNNING;
|
$queue->status = QueueStatus::RUNNING;
|
||||||
$queue->save();
|
$queue->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use App\Enums\SslStatus;
|
use App\Enums\SslStatus;
|
||||||
use App\Enums\SslType;
|
use App\Enums\SslType;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
|
use App\Models\Service;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Models\Ssl;
|
use App\Models\Ssl;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
@ -14,6 +15,8 @@
|
|||||||
class CreateSSL
|
class CreateSSL
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function create(Site $site, array $input): void
|
public function create(Site $site, array $input): void
|
||||||
@ -40,19 +43,25 @@ public function create(Site $site, array $input): void
|
|||||||
$ssl->log_id = ServerLog::log($site->server, 'create-ssl', '', $site)->id;
|
$ssl->log_id = ServerLog::log($site->server, 'create-ssl', '', $site)->id;
|
||||||
$ssl->save();
|
$ssl->save();
|
||||||
|
|
||||||
dispatch(function () use ($site, $ssl) {
|
dispatch(function () use ($site, $ssl): void {
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $site->server->webserver();
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $site->server->webserver()->handler();
|
$webserver = $service->handler();
|
||||||
$webserver->setupSSL($ssl);
|
$webserver->setupSSL($ssl);
|
||||||
$ssl->status = SslStatus::CREATED;
|
$ssl->status = SslStatus::CREATED;
|
||||||
$ssl->save();
|
$ssl->save();
|
||||||
$webserver->updateVHost($site);
|
$webserver->updateVHost($site);
|
||||||
})->catch(function () use ($ssl) {
|
})->catch(function () use ($ssl): void {
|
||||||
$ssl->status = SslStatus::FAILED;
|
$ssl->status = SslStatus::FAILED;
|
||||||
$ssl->save();
|
$ssl->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Actions\SSL;
|
namespace App\Actions\SSL;
|
||||||
|
|
||||||
use App\Enums\SslStatus;
|
use App\Enums\SslStatus;
|
||||||
|
use App\Models\Service;
|
||||||
use App\Models\Ssl;
|
use App\Models\Ssl;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
|
|
||||||
@ -12,8 +13,10 @@ public function delete(Ssl $ssl): void
|
|||||||
{
|
{
|
||||||
$ssl->status = SslStatus::DELETING;
|
$ssl->status = SslStatus::DELETING;
|
||||||
$ssl->save();
|
$ssl->save();
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $ssl->site->server->webserver();
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $ssl->site->server->webserver()->handler();
|
$webserver = $service->handler();
|
||||||
$webserver->removeSSL($ssl);
|
$webserver->removeSSL($ssl);
|
||||||
$ssl->delete();
|
$ssl->delete();
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
class CreateScript
|
class CreateScript
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function create(User $user, array $input): Script
|
public function create(User $user, array $input): Script
|
||||||
{
|
{
|
||||||
$script = new Script([
|
$script = new Script([
|
||||||
@ -20,6 +23,9 @@ public function create(User $user, array $input): Script
|
|||||||
return $script;
|
return $script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
class EditScript
|
class EditScript
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function edit(Script $script, User $user, array $input): Script
|
public function edit(Script $script, User $user, array $input): Script
|
||||||
{
|
{
|
||||||
$script->name = $input['name'];
|
$script->name = $input['name'];
|
||||||
@ -18,6 +21,9 @@ public function edit(Script $script, User $user, array $input): Script
|
|||||||
return $script;
|
return $script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
class ExecuteScript
|
class ExecuteScript
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function execute(Script $script, array $input): ScriptExecution
|
public function execute(Script $script, array $input): ScriptExecution
|
||||||
{
|
{
|
||||||
$execution = new ScriptExecution([
|
$execution = new ScriptExecution([
|
||||||
@ -22,16 +25,19 @@ public function execute(Script $script, array $input): ScriptExecution
|
|||||||
]);
|
]);
|
||||||
$execution->save();
|
$execution->save();
|
||||||
|
|
||||||
dispatch(function () use ($execution, $script) {
|
dispatch(function () use ($execution, $script): void {
|
||||||
|
/** @var Server $server */
|
||||||
|
$server = $execution->server;
|
||||||
|
|
||||||
$content = $execution->getContent();
|
$content = $execution->getContent();
|
||||||
$log = ServerLog::make($execution->server, 'script-'.$script->id.'-'.strtotime('now'));
|
$log = ServerLog::newLog($server, 'script-'.$script->id.'-'.strtotime('now'));
|
||||||
$log->save();
|
$log->save();
|
||||||
$execution->server_log_id = $log->id;
|
$execution->server_log_id = $log->id;
|
||||||
$execution->save();
|
$execution->save();
|
||||||
$execution->server->os()->runScript('~/', $content, $log, $execution->user);
|
$server->os()->runScript('~/', $content, $log, $execution->user);
|
||||||
$execution->status = ScriptExecutionStatus::COMPLETED;
|
$execution->status = ScriptExecutionStatus::COMPLETED;
|
||||||
$execution->save();
|
$execution->save();
|
||||||
})->catch(function () use ($execution) {
|
})->catch(function () use ($execution): void {
|
||||||
$execution->status = ScriptExecutionStatus::FAILED;
|
$execution->status = ScriptExecutionStatus::FAILED;
|
||||||
$execution->save();
|
$execution->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
@ -39,12 +45,16 @@ public function execute(Script $script, array $input): ScriptExecution
|
|||||||
return $execution;
|
return $execution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$users = ['root'];
|
$users = ['root'];
|
||||||
if (isset($input['server'])) {
|
if (isset($input['server'])) {
|
||||||
/** @var ?Server $server */
|
/** @var Server $server */
|
||||||
$server = Server::query()->find($input['server']);
|
$server = Server::query()->findOrFail($input['server']);
|
||||||
$users = $server->getSshUsers();
|
$users = $server->getSshUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
|
|
||||||
class CreateServer
|
class CreateServer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function create(User $creator, Project $project, array $input): Server
|
public function create(User $creator, Project $project, array $input): Server
|
||||||
{
|
{
|
||||||
$server = new Server([
|
$server = new Server([
|
||||||
@ -81,7 +84,7 @@ public function create(User $creator, Project $project, array $input): Server
|
|||||||
|
|
||||||
private function install(Server $server): void
|
private function install(Server $server): void
|
||||||
{
|
{
|
||||||
dispatch(function () use ($server) {
|
dispatch(function () use ($server): void {
|
||||||
$maxWait = 180;
|
$maxWait = 180;
|
||||||
while ($maxWait > 0) {
|
while ($maxWait > 0) {
|
||||||
sleep(10);
|
sleep(10);
|
||||||
@ -102,7 +105,7 @@ private function install(Server $server): void
|
|||||||
]);
|
]);
|
||||||
Notifier::send($server, new ServerInstallationSucceed($server));
|
Notifier::send($server, new ServerInstallationSucceed($server));
|
||||||
})
|
})
|
||||||
->catch(function (Throwable $e) use ($server) {
|
->catch(function (Throwable $e) use ($server): void {
|
||||||
$server->update([
|
$server->update([
|
||||||
'status' => ServerStatus::INSTALLATION_FAILED,
|
'status' => ServerStatus::INSTALLATION_FAILED,
|
||||||
]);
|
]);
|
||||||
@ -114,6 +117,10 @@ private function install(Server $server): void
|
|||||||
->onConnection('ssh');
|
->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(Project $project, array $input): array
|
public static function rules(Project $project, array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
@ -129,28 +136,22 @@ public static function rules(Project $project, array $input): array
|
|||||||
Rule::in(config('core.operating_systems')),
|
Rule::in(config('core.operating_systems')),
|
||||||
],
|
],
|
||||||
'server_provider' => [
|
'server_provider' => [
|
||||||
Rule::when(function () use ($input) {
|
Rule::when(fn (): bool => isset($input['provider']) && $input['provider'] != ServerProvider::CUSTOM, [
|
||||||
return isset($input['provider']) && $input['provider'] != ServerProvider::CUSTOM;
|
|
||||||
}, [
|
|
||||||
'required',
|
'required',
|
||||||
Rule::exists('server_providers', 'id')->where(function (Builder $query) use ($project) {
|
Rule::exists('server_providers', 'id')->where(function (Builder $query) use ($project): void {
|
||||||
$query->where('project_id', $project->id)
|
$query->where('project_id', $project->id)
|
||||||
->orWhereNull('project_id');
|
->orWhereNull('project_id');
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
'ip' => [
|
'ip' => [
|
||||||
Rule::when(function () use ($input) {
|
Rule::when(fn (): bool => isset($input['provider']) && $input['provider'] == ServerProvider::CUSTOM, [
|
||||||
return isset($input['provider']) && $input['provider'] == ServerProvider::CUSTOM;
|
|
||||||
}, [
|
|
||||||
'required',
|
'required',
|
||||||
new RestrictedIPAddressesRule,
|
new RestrictedIPAddressesRule,
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
'port' => [
|
'port' => [
|
||||||
Rule::when(function () use ($input) {
|
Rule::when(fn (): bool => isset($input['provider']) && $input['provider'] == ServerProvider::CUSTOM, [
|
||||||
return isset($input['provider']) && $input['provider'] == ServerProvider::CUSTOM;
|
|
||||||
}, [
|
|
||||||
'required',
|
'required',
|
||||||
'numeric',
|
'numeric',
|
||||||
'min:1',
|
'min:1',
|
||||||
@ -162,6 +163,10 @@ public static function rules(Project $project, array $input): array
|
|||||||
return array_merge($rules, self::typeRules($input), self::providerRules($input));
|
return array_merge($rules, self::typeRules($input), self::providerRules($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
private static function typeRules(array $input): array
|
private static function typeRules(array $input): array
|
||||||
{
|
{
|
||||||
if (! isset($input['type']) || ! in_array($input['type'], config('core.server_types'))) {
|
if (! isset($input['type']) || ! in_array($input['type'], config('core.server_types'))) {
|
||||||
@ -173,6 +178,10 @@ private static function typeRules(array $input): array
|
|||||||
return $server->type()->createRules($input);
|
return $server->type()->createRules($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
private static function providerRules(array $input): array
|
private static function providerRules(array $input): array
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
class CreateServerLog
|
class CreateServerLog
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function create(Server $server, array $input): void
|
public function create(Server $server, array $input): void
|
||||||
@ -20,6 +22,9 @@ public function create(Server $server, array $input): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
class EditServer
|
class EditServer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return Server $server
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function edit(Server $server, array $input): Server
|
public function edit(Server $server, array $input): Server
|
||||||
@ -42,6 +45,9 @@ public function edit(Server $server, array $input): Server
|
|||||||
return $server;
|
return $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(Server $server): array
|
public static function rules(Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -13,11 +13,11 @@ public function update(Server $server): void
|
|||||||
{
|
{
|
||||||
$server->status = ServerStatus::UPDATING;
|
$server->status = ServerStatus::UPDATING;
|
||||||
$server->save();
|
$server->save();
|
||||||
dispatch(function () use ($server) {
|
dispatch(function () use ($server): void {
|
||||||
$server->os()->upgrade();
|
$server->os()->upgrade();
|
||||||
$server->checkConnection();
|
$server->checkConnection();
|
||||||
$server->checkForUpdates();
|
$server->checkForUpdates();
|
||||||
})->catch(function () use ($server) {
|
})->catch(function () use ($server): void {
|
||||||
Notifier::send($server, new ServerUpdateFailed($server));
|
Notifier::send($server, new ServerUpdateFailed($server));
|
||||||
$server->checkConnection();
|
$server->checkConnection();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Actions\ServerProvider;
|
namespace App\Actions\ServerProvider;
|
||||||
|
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
|
use App\Models\Server;
|
||||||
use App\Models\ServerProvider;
|
use App\Models\ServerProvider;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\ServerProviders\ServerProvider as ServerProviderContract;
|
use App\ServerProviders\ServerProvider as ServerProviderContract;
|
||||||
@ -13,11 +14,13 @@
|
|||||||
class CreateServerProvider
|
class CreateServerProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function create(User $user, Project $project, array $input): ServerProvider
|
public function create(User $user, Project $project, array $input): ServerProvider
|
||||||
{
|
{
|
||||||
$provider = static::getProvider($input['provider']);
|
$provider = self::getProvider($input['provider']);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$provider->connect($input);
|
$provider->connect($input);
|
||||||
@ -40,13 +43,19 @@ public function create(User $user, Project $project, array $input): ServerProvid
|
|||||||
return $serverProvider;
|
return $serverProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getProvider($name): ServerProviderContract
|
private static function getProvider(string $name): ServerProviderContract
|
||||||
{
|
{
|
||||||
$providerClass = config('core.server_providers_class.'.$name);
|
$providerClass = config('core.server_providers_class.'.$name);
|
||||||
|
/** @var ServerProviderContract $provider */
|
||||||
|
$provider = new $providerClass(new ServerProvider, new Server);
|
||||||
|
|
||||||
return new $providerClass;
|
return $provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
@ -60,15 +69,19 @@ public static function rules(array $input): array
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
return array_merge($rules, static::providerRules($input));
|
return array_merge($rules, self::providerRules($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
private static function providerRules(array $input): array
|
private static function providerRules(array $input): array
|
||||||
{
|
{
|
||||||
if (! isset($input['provider'])) {
|
if (! isset($input['provider'])) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::getProvider($input['provider'])->credentialValidationRules($input);
|
return self::getProvider($input['provider'])->credentialValidationRules($input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
class EditServerProvider
|
class EditServerProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function edit(ServerProvider $serverProvider, Project $project, array $input): ServerProvider
|
public function edit(ServerProvider $serverProvider, Project $project, array $input): ServerProvider
|
||||||
{
|
{
|
||||||
$serverProvider->profile = $input['name'];
|
$serverProvider->profile = $input['name'];
|
||||||
@ -17,6 +20,9 @@ public function edit(ServerProvider $serverProvider, Project $project, array $in
|
|||||||
return $serverProvider;
|
return $serverProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
class Install
|
class Install
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function install(Server $server, array $input): Service
|
public function install(Server $server, array $input): Service
|
||||||
{
|
{
|
||||||
$input['type'] = config('core.service_types')[$input['name']];
|
$input['type'] = config('core.service_types')[$input['name']];
|
||||||
@ -28,11 +31,11 @@ public function install(Server $server, array $input): Service
|
|||||||
|
|
||||||
$service->save();
|
$service->save();
|
||||||
|
|
||||||
dispatch(function () use ($service) {
|
dispatch(function () use ($service): void {
|
||||||
$service->handler()->install();
|
$service->handler()->install();
|
||||||
$service->status = ServiceStatus::READY;
|
$service->status = ServiceStatus::READY;
|
||||||
$service->save();
|
$service->save();
|
||||||
})->catch(function () use ($service) {
|
})->catch(function () use ($service): void {
|
||||||
$service->status = ServiceStatus::INSTALLATION_FAILED;
|
$service->status = ServiceStatus::INSTALLATION_FAILED;
|
||||||
$service->save();
|
$service->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
@ -40,6 +43,10 @@ public function install(Server $server, array $input): Service
|
|||||||
return $service;
|
return $service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
|
@ -11,7 +11,7 @@ public function start(Service $service): void
|
|||||||
{
|
{
|
||||||
$service->status = ServiceStatus::STARTING;
|
$service->status = ServiceStatus::STARTING;
|
||||||
$service->save();
|
$service->save();
|
||||||
dispatch(function () use ($service) {
|
dispatch(function () use ($service): void {
|
||||||
$status = $service->server->systemd()->start($service->unit);
|
$status = $service->server->systemd()->start($service->unit);
|
||||||
if (str($status)->contains('Active: active')) {
|
if (str($status)->contains('Active: active')) {
|
||||||
$service->status = ServiceStatus::READY;
|
$service->status = ServiceStatus::READY;
|
||||||
@ -26,7 +26,7 @@ public function stop(Service $service): void
|
|||||||
{
|
{
|
||||||
$service->status = ServiceStatus::STOPPING;
|
$service->status = ServiceStatus::STOPPING;
|
||||||
$service->save();
|
$service->save();
|
||||||
dispatch(function () use ($service) {
|
dispatch(function () use ($service): void {
|
||||||
$status = $service->server->systemd()->stop($service->unit);
|
$status = $service->server->systemd()->stop($service->unit);
|
||||||
if (str($status)->contains('Active: inactive')) {
|
if (str($status)->contains('Active: inactive')) {
|
||||||
$service->status = ServiceStatus::STOPPED;
|
$service->status = ServiceStatus::STOPPED;
|
||||||
@ -41,7 +41,7 @@ public function restart(Service $service): void
|
|||||||
{
|
{
|
||||||
$service->status = ServiceStatus::RESTARTING;
|
$service->status = ServiceStatus::RESTARTING;
|
||||||
$service->save();
|
$service->save();
|
||||||
dispatch(function () use ($service) {
|
dispatch(function () use ($service): void {
|
||||||
$status = $service->server->systemd()->restart($service->unit);
|
$status = $service->server->systemd()->restart($service->unit);
|
||||||
if (str($status)->contains('Active: active')) {
|
if (str($status)->contains('Active: active')) {
|
||||||
$service->status = ServiceStatus::READY;
|
$service->status = ServiceStatus::READY;
|
||||||
@ -56,7 +56,7 @@ public function enable(Service $service): void
|
|||||||
{
|
{
|
||||||
$service->status = ServiceStatus::ENABLING;
|
$service->status = ServiceStatus::ENABLING;
|
||||||
$service->save();
|
$service->save();
|
||||||
dispatch(function () use ($service) {
|
dispatch(function () use ($service): void {
|
||||||
$status = $service->server->systemd()->enable($service->unit);
|
$status = $service->server->systemd()->enable($service->unit);
|
||||||
if (str($status)->contains('Active: active')) {
|
if (str($status)->contains('Active: active')) {
|
||||||
$service->status = ServiceStatus::READY;
|
$service->status = ServiceStatus::READY;
|
||||||
@ -71,7 +71,7 @@ public function disable(Service $service): void
|
|||||||
{
|
{
|
||||||
$service->status = ServiceStatus::DISABLING;
|
$service->status = ServiceStatus::DISABLING;
|
||||||
$service->save();
|
$service->save();
|
||||||
dispatch(function () use ($service) {
|
dispatch(function () use ($service): void {
|
||||||
$status = $service->server->systemd()->disable($service->unit);
|
$status = $service->server->systemd()->disable($service->unit);
|
||||||
if (str($status)->contains('Active: inactive')) {
|
if (str($status)->contains('Active: inactive')) {
|
||||||
$service->status = ServiceStatus::DISABLED;
|
$service->status = ServiceStatus::DISABLED;
|
||||||
|
@ -20,10 +20,10 @@ public function uninstall(Service $service): void
|
|||||||
$service->status = ServiceStatus::UNINSTALLING;
|
$service->status = ServiceStatus::UNINSTALLING;
|
||||||
$service->save();
|
$service->save();
|
||||||
|
|
||||||
dispatch(function () use ($service) {
|
dispatch(function () use ($service): void {
|
||||||
$service->handler()->uninstall();
|
$service->handler()->uninstall();
|
||||||
$service->delete();
|
$service->delete();
|
||||||
})->catch(function () use ($service) {
|
})->catch(function () use ($service): void {
|
||||||
$service->status = ServiceStatus::FAILED;
|
$service->status = ServiceStatus::FAILED;
|
||||||
$service->save();
|
$service->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
class CreateCommand
|
class CreateCommand
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function create(Site $site, array $input): Command
|
public function create(Site $site, array $input): Command
|
||||||
{
|
{
|
||||||
$script = new Command([
|
$script = new Command([
|
||||||
@ -19,6 +22,9 @@ public function create(Site $site, array $input): Command
|
|||||||
return $script;
|
return $script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -19,6 +19,11 @@
|
|||||||
|
|
||||||
class CreateSite
|
class CreateSite
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function create(Server $server, array $input): Site
|
public function create(Server $server, array $input): Site
|
||||||
{
|
{
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
@ -40,7 +45,7 @@ public function create(Server $server, array $input): Site
|
|||||||
// check has access to repository
|
// check has access to repository
|
||||||
try {
|
try {
|
||||||
if ($site->sourceControl) {
|
if ($site->sourceControl) {
|
||||||
$site->sourceControl?->getRepo($site->repository);
|
$site->sourceControl->getRepo($site->repository);
|
||||||
}
|
}
|
||||||
} catch (SourceControlIsNotConnected) {
|
} catch (SourceControlIsNotConnected) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
@ -72,14 +77,14 @@ public function create(Server $server, array $input): Site
|
|||||||
$site->commands()->createMany($site->type()->baseCommands());
|
$site->commands()->createMany($site->type()->baseCommands());
|
||||||
|
|
||||||
// install site
|
// install site
|
||||||
dispatch(function () use ($site) {
|
dispatch(function () use ($site): void {
|
||||||
$site->type()->install();
|
$site->type()->install();
|
||||||
$site->update([
|
$site->update([
|
||||||
'status' => SiteStatus::READY,
|
'status' => SiteStatus::READY,
|
||||||
'progress' => 100,
|
'progress' => 100,
|
||||||
]);
|
]);
|
||||||
Notifier::send($site, new SiteInstallationSucceed($site));
|
Notifier::send($site, new SiteInstallationSucceed($site));
|
||||||
})->catch(function () use ($site) {
|
})->catch(function () use ($site): void {
|
||||||
$site->status = SiteStatus::INSTALLATION_FAILED;
|
$site->status = SiteStatus::INSTALLATION_FAILED;
|
||||||
$site->save();
|
$site->save();
|
||||||
Notifier::send($site, new SiteInstallationFailed($site));
|
Notifier::send($site, new SiteInstallationFailed($site));
|
||||||
@ -96,6 +101,10 @@ public function create(Server $server, array $input): Site
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(Server $server, array $input): array
|
public static function rules(Server $server, array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
@ -106,9 +115,7 @@ public static function rules(Server $server, array $input): array
|
|||||||
'domain' => [
|
'domain' => [
|
||||||
'required',
|
'required',
|
||||||
new DomainRule,
|
new DomainRule,
|
||||||
Rule::unique('sites', 'domain')->where(function ($query) use ($server) {
|
Rule::unique('sites', 'domain')->where(fn ($query) => $query->where('server_id', $server->id)),
|
||||||
return $query->where('server_id', $server->id);
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
'aliases.*' => [
|
'aliases.*' => [
|
||||||
new DomainRule,
|
new DomainRule,
|
||||||
@ -125,6 +132,10 @@ public static function rules(Server $server, array $input): array
|
|||||||
return array_merge($rules, self::typeRules($server, $input));
|
return array_merge($rules, self::typeRules($server, $input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
private static function typeRules(Server $server, array $input): array
|
private static function typeRules(Server $server, array $input): array
|
||||||
{
|
{
|
||||||
if (! isset($input['type']) || ! in_array($input['type'], config('core.site_types'))) {
|
if (! isset($input['type']) || ! in_array($input['type'], config('core.site_types'))) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
use App\Exceptions\SSHError;
|
use App\Exceptions\SSHError;
|
||||||
|
use App\Models\Service;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\Services\PHP\PHP;
|
use App\SSH\Services\PHP\PHP;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
@ -14,13 +15,18 @@ class DeleteSite
|
|||||||
*/
|
*/
|
||||||
public function delete(Site $site): void
|
public function delete(Site $site): void
|
||||||
{
|
{
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $site->server->webserver();
|
||||||
|
|
||||||
/** @var Webserver $webserverHandler */
|
/** @var Webserver $webserverHandler */
|
||||||
$webserverHandler = $site->server->webserver()->handler();
|
$webserverHandler = $service->handler();
|
||||||
$webserverHandler->deleteSite($site);
|
$webserverHandler->deleteSite($site);
|
||||||
|
|
||||||
if ($site->isIsolated()) {
|
if ($site->isIsolated()) {
|
||||||
|
/** @var Service $phpService */
|
||||||
|
$phpService = $site->server->php();
|
||||||
/** @var PHP $php */
|
/** @var PHP $php */
|
||||||
$php = $site->server->php()->handler();
|
$php = $phpService->handler();
|
||||||
$php->removeFpmPool($site->user, $site->php_version, $site->id);
|
$php->removeFpmPool($site->user, $site->php_version, $site->id);
|
||||||
|
|
||||||
$os = $site->server->os();
|
$os = $site->server->os();
|
||||||
|
@ -39,9 +39,8 @@ public function run(Site $site): Deployment
|
|||||||
}
|
}
|
||||||
$deployment->save();
|
$deployment->save();
|
||||||
|
|
||||||
dispatch(function () use ($site, $deployment) {
|
dispatch(function () use ($site, $deployment): void {
|
||||||
/** @var ServerLog $log */
|
$log = ServerLog::newLog($site->server, 'deploy-'.strtotime('now'))
|
||||||
$log = ServerLog::make($site->server, 'deploy-'.strtotime('now'))
|
|
||||||
->forSite($site);
|
->forSite($site);
|
||||||
$log->save();
|
$log->save();
|
||||||
$deployment->log_id = $log->id;
|
$deployment->log_id = $log->id;
|
||||||
@ -56,7 +55,7 @@ public function run(Site $site): Deployment
|
|||||||
$deployment->status = DeploymentStatus::FINISHED;
|
$deployment->status = DeploymentStatus::FINISHED;
|
||||||
$deployment->save();
|
$deployment->save();
|
||||||
Notifier::send($site, new DeploymentCompleted($deployment, $site));
|
Notifier::send($site, new DeploymentCompleted($deployment, $site));
|
||||||
})->catch(function () use ($deployment, $site) {
|
})->catch(function () use ($deployment, $site): void {
|
||||||
$deployment->status = DeploymentStatus::FAILED;
|
$deployment->status = DeploymentStatus::FAILED;
|
||||||
$deployment->save();
|
$deployment->save();
|
||||||
Notifier::send($site, new DeploymentCompleted($deployment, $site));
|
Notifier::send($site, new DeploymentCompleted($deployment, $site));
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
class EditCommand
|
class EditCommand
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function edit(Command $command, array $input): Command
|
public function edit(Command $command, array $input): Command
|
||||||
{
|
{
|
||||||
$command->name = $input['name'];
|
$command->name = $input['name'];
|
||||||
@ -15,6 +18,9 @@ public function edit(Command $command, array $input): Command
|
|||||||
return $command;
|
return $command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
class ExecuteCommand
|
class ExecuteCommand
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function execute(Command $command, User $user, array $input): CommandExecution
|
public function execute(Command $command, User $user, array $input): CommandExecution
|
||||||
{
|
{
|
||||||
$execution = new CommandExecution([
|
$execution = new CommandExecution([
|
||||||
@ -21,22 +24,22 @@ public function execute(Command $command, User $user, array $input): CommandExec
|
|||||||
]);
|
]);
|
||||||
$execution->save();
|
$execution->save();
|
||||||
|
|
||||||
dispatch(function () use ($execution, $command) {
|
dispatch(function () use ($execution, $command): void {
|
||||||
$content = $execution->getContent();
|
$content = $execution->getContent();
|
||||||
$log = ServerLog::make($execution->server, 'command-'.$command->id.'-'.strtotime('now'));
|
$log = ServerLog::newLog($execution->server, 'command-'.$command->id.'-'.strtotime('now'));
|
||||||
$log->save();
|
$log->save();
|
||||||
$execution->server_log_id = $log->id;
|
$execution->server_log_id = $log->id;
|
||||||
$execution->save();
|
$execution->save();
|
||||||
$execution->server->os()->runScript(
|
$execution->server->os()->runScript(
|
||||||
path: $command->site->path,
|
path: $command->site->path,
|
||||||
script: $content,
|
script: $content,
|
||||||
user: $command->site->user,
|
|
||||||
serverLog: $log,
|
serverLog: $log,
|
||||||
|
user: $command->site->user,
|
||||||
variables: $execution->variables
|
variables: $execution->variables
|
||||||
);
|
);
|
||||||
$execution->status = CommandExecutionStatus::COMPLETED;
|
$execution->status = CommandExecutionStatus::COMPLETED;
|
||||||
$execution->save();
|
$execution->save();
|
||||||
})->catch(function () use ($execution) {
|
})->catch(function () use ($execution): void {
|
||||||
$execution->status = CommandExecutionStatus::FAILED;
|
$execution->status = CommandExecutionStatus::FAILED;
|
||||||
$execution->save();
|
$execution->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
@ -44,6 +47,10 @@ public function execute(Command $command, User $user, array $input): CommandExec
|
|||||||
return $execution;
|
return $execution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, string|array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -2,23 +2,33 @@
|
|||||||
|
|
||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Models\Service;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
use App\ValidationRules\DomainRule;
|
use App\ValidationRules\DomainRule;
|
||||||
|
|
||||||
class UpdateAliases
|
class UpdateAliases
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
$site->aliases = $input['aliases'] ?? [];
|
$site->aliases = $input['aliases'] ?? [];
|
||||||
|
|
||||||
|
/** @var Service $service */
|
||||||
|
$service = $site->server->webserver();
|
||||||
|
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $site->server->webserver()->handler();
|
$webserver = $service->handler();
|
||||||
$webserver->updateVHost($site);
|
$webserver->updateVHost($site);
|
||||||
|
|
||||||
$site->save();
|
$site->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
use App\Exceptions\SSHError;
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\Git\Git;
|
use App\SSH\Git\Git;
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class UpdateBranch
|
class UpdateBranch
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws SSHError
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
@ -22,7 +22,7 @@ public function update(Site $site, array $input): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
|
@ -2,23 +2,24 @@
|
|||||||
|
|
||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Models\DeploymentScript;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class UpdateDeploymentScript
|
class UpdateDeploymentScript
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @param array<string, mixed> $input
|
||||||
*/
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
|
/** @var DeploymentScript $script */
|
||||||
$script = $site->deploymentScript;
|
$script = $site->deploymentScript;
|
||||||
$script->content = $input['script'];
|
$script->content = $input['script'];
|
||||||
$script->save();
|
$script->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @return array<string, array<string>>
|
||||||
*/
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
class UpdateEnv
|
class UpdateEnv
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws SSHError
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
@ -15,7 +17,7 @@ public function update(Site $site, array $input): void
|
|||||||
$site->server->os()->editFileAs(
|
$site->server->os()->editFileAs(
|
||||||
$site->path.'/.env',
|
$site->path.'/.env',
|
||||||
$site->user,
|
$site->user,
|
||||||
trim($input['env']),
|
trim((string) $input['env']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
class UpdateLoadBalancer
|
class UpdateLoadBalancer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
$site->loadBalancerServers()->delete();
|
$site->loadBalancerServers()->delete();
|
||||||
@ -27,6 +30,9 @@ public function update(Site $site, array $input): void
|
|||||||
$site->webserver()->updateVHost($site);
|
$site->webserver()->updateVHost($site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(Site $site): array
|
public static function rules(Site $site): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
class UpdatePHPVersion
|
class UpdatePHPVersion
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(Site $site): array
|
public static function rules(Site $site): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -21,6 +24,8 @@ public static function rules(Site $site): array
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws SSHError
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
|
@ -11,12 +11,17 @@
|
|||||||
|
|
||||||
class UpdateSourceControl
|
class UpdateSourceControl
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
$site->source_control_id = $input['source_control'];
|
$site->source_control_id = $input['source_control'];
|
||||||
try {
|
try {
|
||||||
if ($site->sourceControl) {
|
if ($site->sourceControl) {
|
||||||
$site->sourceControl?->getRepo($site->repository);
|
$site->sourceControl->getRepo($site->repository);
|
||||||
}
|
}
|
||||||
} catch (SourceControlIsNotConnected) {
|
} catch (SourceControlIsNotConnected) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
@ -34,6 +39,9 @@ public function update(Site $site, array $input): void
|
|||||||
$site->save();
|
$site->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -4,14 +4,18 @@
|
|||||||
|
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\SourceControl;
|
use App\Models\SourceControl;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ConnectSourceControl
|
class ConnectSourceControl
|
||||||
{
|
{
|
||||||
public function connect(User $user, Project $project, array $input): SourceControl
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
public function connect(Project $project, array $input): SourceControl
|
||||||
{
|
{
|
||||||
$sourceControl = new SourceControl([
|
$sourceControl = new SourceControl([
|
||||||
'provider' => $input['provider'],
|
'provider' => $input['provider'],
|
||||||
@ -34,6 +38,10 @@ public function connect(User $user, Project $project, array $input): SourceContr
|
|||||||
return $sourceControl;
|
return $sourceControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
@ -46,10 +54,13 @@ public static function rules(array $input): array
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
return array_merge($rules, static::providerRules($input));
|
return array_merge($rules, self::providerRules($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private static function providerRules(array $input): array
|
private static function providerRules(array $input): array
|
||||||
|
@ -8,6 +8,11 @@
|
|||||||
|
|
||||||
class EditSourceControl
|
class EditSourceControl
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function edit(SourceControl $sourceControl, Project $project, array $input): SourceControl
|
public function edit(SourceControl $sourceControl, Project $project, array $input): SourceControl
|
||||||
{
|
{
|
||||||
$sourceControl->profile = $input['name'];
|
$sourceControl->profile = $input['name'];
|
||||||
@ -27,6 +32,10 @@ public function edit(SourceControl $sourceControl, Project $project, array $inpu
|
|||||||
return $sourceControl;
|
return $sourceControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*/
|
||||||
public static function rules(SourceControl $sourceControl, array $input): array
|
public static function rules(SourceControl $sourceControl, array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
@ -35,10 +44,13 @@ public static function rules(SourceControl $sourceControl, array $input): array
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
return array_merge($rules, static::providerRules($sourceControl, $input));
|
return array_merge($rules, self::providerRules($sourceControl, $input));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, array<int, mixed>>
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private static function providerRules(SourceControl $sourceControl, array $input): array
|
private static function providerRules(SourceControl $sourceControl, array $input): array
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
class CreateSshKey
|
class CreateSshKey
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function create(User $user, array $input): SshKey
|
public function create(User $user, array $input): SshKey
|
||||||
@ -25,7 +27,7 @@ public function create(User $user, array $input): SshKey
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
|
@ -3,11 +3,15 @@
|
|||||||
namespace App\Actions\SshKey;
|
namespace App\Actions\SshKey;
|
||||||
|
|
||||||
use App\Enums\SshKeyStatus;
|
use App\Enums\SshKeyStatus;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\SshKey;
|
use App\Models\SshKey;
|
||||||
|
|
||||||
class DeleteKeyFromServer
|
class DeleteKeyFromServer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function delete(Server $server, SshKey $sshKey): void
|
public function delete(Server $server, SshKey $sshKey): void
|
||||||
{
|
{
|
||||||
$sshKey->servers()->updateExistingPivot($server->id, [
|
$sshKey->servers()->updateExistingPivot($server->id, [
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Actions\SshKey;
|
namespace App\Actions\SshKey;
|
||||||
|
|
||||||
use App\Enums\SshKeyStatus;
|
use App\Enums\SshKeyStatus;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\SshKey;
|
use App\Models\SshKey;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -10,6 +11,11 @@
|
|||||||
|
|
||||||
class DeployKeyToServer
|
class DeployKeyToServer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function deploy(Server $server, array $input): void
|
public function deploy(Server $server, array $input): void
|
||||||
{
|
{
|
||||||
/** @var SshKey $sshKey */
|
/** @var SshKey $sshKey */
|
||||||
@ -23,6 +29,9 @@ public function deploy(Server $server, array $input): void
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(User $user, Server $server): array
|
public static function rules(User $user, Server $server): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
class CreateStorageProvider
|
class CreateStorageProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function create(User $user, Project $project, array $input): StorageProvider
|
public function create(User $user, Project $project, array $input): StorageProvider
|
||||||
@ -41,6 +43,10 @@ public function create(User $user, Project $project, array $input): StorageProvi
|
|||||||
return $storageProvider;
|
return $storageProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(array $input): array
|
public static function rules(array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\StorageProvider;
|
use App\Models\StorageProvider;
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class EditStorageProvider
|
class EditStorageProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function edit(StorageProvider $storageProvider, Project $project, array $input): StorageProvider
|
public function edit(StorageProvider $storageProvider, Project $project, array $input): StorageProvider
|
||||||
{
|
{
|
||||||
$storageProvider->profile = $input['name'];
|
$storageProvider->profile = $input['name'];
|
||||||
@ -19,7 +21,7 @@ public function edit(StorageProvider $storageProvider, Project $project, array $
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
class CreateTag
|
class CreateTag
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function create(User $user, array $input): Tag
|
public function create(User $user, array $input): Tag
|
||||||
{
|
{
|
||||||
$tag = Tag::query()
|
$tag = Tag::query()
|
||||||
@ -22,7 +27,7 @@ public function create(User $user, array $input): Tag
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tag = new Tag([
|
$tag = new Tag([
|
||||||
'project_id' => $user->currentProject->id,
|
'project_id' => $user->currentProject?->id,
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'color' => $input['color'],
|
'color' => $input['color'],
|
||||||
]);
|
]);
|
||||||
@ -31,6 +36,9 @@ public function create(User $user, array $input): Tag
|
|||||||
return $tag;
|
return $tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
class EditTag
|
class EditTag
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function edit(Tag $tag, array $input): void
|
public function edit(Tag $tag, array $input): void
|
||||||
{
|
{
|
||||||
$tag->name = $input['name'];
|
$tag->name = $input['name'];
|
||||||
@ -15,6 +18,9 @@ public function edit(Tag $tag, array $input): void
|
|||||||
$tag->save();
|
$tag->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Models\Tag;
|
use App\Models\Tag;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class SyncTags
|
class SyncTags
|
||||||
{
|
{
|
||||||
public function sync(User $user, array $input): void
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
|
public function sync(array $input): void
|
||||||
{
|
{
|
||||||
/** @var Server|Site $taggable */
|
/** @var Server|Site $taggable */
|
||||||
$taggable = $input['taggable_type']::findOrFail($input['taggable_id']);
|
$taggable = $input['taggable_type']::findOrFail($input['taggable_id']);
|
||||||
@ -20,6 +22,9 @@ public function sync(User $user, array $input): void
|
|||||||
$taggable->tags()->sync($tags->pluck('id'));
|
$taggable->tags()->sync($tags->pluck('id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(int $projectId): array
|
public static function rules(int $projectId): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
class CreateUser
|
class CreateUser
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function create(array $input): User
|
public function create(array $input): User
|
||||||
{
|
{
|
||||||
$this->validate($input);
|
$this->validate($input);
|
||||||
@ -25,11 +28,17 @@ public function create(array $input): User
|
|||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
private function validate(array $input): void
|
private function validate(array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, self::rules())->validate();
|
Validator::make($input, self::rules())->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -7,9 +7,7 @@
|
|||||||
trait PasswordValidationRules
|
trait PasswordValidationRules
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get the validation rules used to validate passwords.
|
* @return array<int, mixed>
|
||||||
*
|
|
||||||
* @return array<int, \Illuminate\Contracts\Validation\Rule|array|string>
|
|
||||||
*/
|
*/
|
||||||
protected function passwordRules(): array
|
protected function passwordRules(): array
|
||||||
{
|
{
|
||||||
|
@ -5,9 +5,15 @@
|
|||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class UpdateProjects
|
class UpdateProjects
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function update(User $user, array $input): void
|
public function update(User $user, array $input): void
|
||||||
{
|
{
|
||||||
$this->validate($input);
|
$this->validate($input);
|
||||||
@ -20,7 +26,7 @@ public function update(User $user, array $input): void
|
|||||||
|
|
||||||
$user->refresh();
|
$user->refresh();
|
||||||
|
|
||||||
/** @var Project $firstProject */
|
/** @var ?Project $firstProject */
|
||||||
$firstProject = $user->projects->first();
|
$firstProject = $user->projects->first();
|
||||||
if (! $user->currentProject && $firstProject) {
|
if (! $user->currentProject && $firstProject) {
|
||||||
$user->current_project_id = $firstProject->id;
|
$user->current_project_id = $firstProject->id;
|
||||||
@ -28,11 +34,19 @@ public function update(User $user, array $input): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
private function validate(array $input): void
|
private function validate(array $input): void
|
||||||
{
|
{
|
||||||
validator($input, self::rules())->validate();
|
validator($input, self::rules())->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
class UpdateUser
|
class UpdateUser
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function update(User $user, array $input): User
|
public function update(User $user, array $input): User
|
||||||
{
|
{
|
||||||
$this->validate($user, $input);
|
$this->validate($user, $input);
|
||||||
@ -27,11 +30,17 @@ public function update(User $user, array $input): User
|
|||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
private function validate(User $user, array $input): void
|
private function validate(User $user, array $input): void
|
||||||
{
|
{
|
||||||
Validator::make($input, self::rules($user))->validate();
|
Validator::make($input, self::rules($user))->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
public static function rules(User $user): array
|
public static function rules(User $user): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
class UpdateUserPassword
|
class UpdateUserPassword
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param mixed $user
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
public function update($user, array $input): void
|
public function update($user, array $input): void
|
||||||
{
|
{
|
||||||
$user->forceFill([
|
$user->forceFill([
|
||||||
@ -13,6 +17,9 @@ public function update($user, array $input): void
|
|||||||
])->save();
|
])->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -4,9 +4,15 @@
|
|||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class UpdateUserProfileInformation
|
class UpdateUserProfileInformation
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function update(User $user, array $input): void
|
public function update(User $user, array $input): void
|
||||||
{
|
{
|
||||||
if ($input['email'] !== $user->email) {
|
if ($input['email'] !== $user->email) {
|
||||||
@ -20,6 +26,9 @@ public function update(User $user, array $input): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string>>
|
||||||
|
*/
|
||||||
public static function rules(User $user): array
|
public static function rules(User $user): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -33,7 +42,7 @@ public static function rules(User $user): array
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the given verified user's profile information.
|
* @param array<string, mixed> $input
|
||||||
*/
|
*/
|
||||||
protected function updateVerifiedUser(User $user, array $input): void
|
protected function updateVerifiedUser(User $user, array $input): void
|
||||||
{
|
{
|
||||||
|
@ -11,10 +11,10 @@ class DeleteOlderMetricsCommand extends Command
|
|||||||
|
|
||||||
protected $description = 'Delete older metrics from database';
|
protected $description = 'Delete older metrics from database';
|
||||||
|
|
||||||
public function handle()
|
public function handle(): void
|
||||||
{
|
{
|
||||||
Service::query()->where('type', 'monitoring')->chunk(100, function ($services) {
|
Service::query()->where('type', 'monitoring')->chunk(100, function ($services): void {
|
||||||
$services->each(function ($service) {
|
$services->each(function ($service): void {
|
||||||
$this->info("Deleting older metrics for service {$service->server->name}");
|
$this->info("Deleting older metrics for service {$service->server->name}");
|
||||||
$service
|
$service
|
||||||
->server
|
->server
|
||||||
|
@ -15,10 +15,10 @@ class GetMetricsCommand extends Command
|
|||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$checkedMetrics = 0;
|
$checkedMetrics = 0;
|
||||||
Server::query()->whereHas('services', function (Builder $query) {
|
Server::query()->whereHas('services', function (Builder $query): void {
|
||||||
$query->where('type', 'monitoring')
|
$query->where('type', 'monitoring')
|
||||||
->where('name', 'remote-monitor');
|
->where('name', 'remote-monitor');
|
||||||
})->chunk(10, function ($servers) use (&$checkedMetrics) {
|
})->chunk(10, function ($servers) use (&$checkedMetrics): void {
|
||||||
/** @var Server $server */
|
/** @var Server $server */
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$info = $server->os()->resourceInfo();
|
$info = $server->os()->resourceInfo();
|
||||||
|
@ -16,9 +16,9 @@ public function handle(): void
|
|||||||
{
|
{
|
||||||
$this->info('Migrating from Mysql to SQLite...');
|
$this->info('Migrating from Mysql to SQLite...');
|
||||||
|
|
||||||
File::exists(storage_path('database.sqlite'))
|
if (File::exists(storage_path('database.sqlite'))) {
|
||||||
? File::delete(storage_path('database.sqlite'))
|
File::delete(storage_path('database.sqlite'));
|
||||||
: null;
|
}
|
||||||
|
|
||||||
File::put(storage_path('database.sqlite'), '');
|
File::put(storage_path('database.sqlite'), '');
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public function handle(): void
|
|||||||
Backup::query()
|
Backup::query()
|
||||||
->where('interval', $this->argument('interval'))
|
->where('interval', $this->argument('interval'))
|
||||||
->where('status', BackupStatus::RUNNING)
|
->where('status', BackupStatus::RUNNING)
|
||||||
->chunk(100, function ($backups) use (&$total) {
|
->chunk(100, function ($backups) use (&$total): void {
|
||||||
/** @var Backup $backup */
|
/** @var Backup $backup */
|
||||||
foreach ($backups as $backup) {
|
foreach ($backups as $backup) {
|
||||||
app(RunBackup::class)->run($backup);
|
app(RunBackup::class)->run($backup);
|
||||||
|
@ -43,7 +43,7 @@ class Handler extends ExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->reportable(function (Throwable $e) {
|
$this->reportable(function (Throwable $e): void {
|
||||||
//
|
//
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,8 @@
|
|||||||
|
|
||||||
class SSHError extends Exception
|
class SSHError extends Exception
|
||||||
{
|
{
|
||||||
protected ?ServerLog $log;
|
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null, protected ?ServerLog $log = null)
|
||||||
|
|
||||||
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null, ?ServerLog $log = null)
|
|
||||||
{
|
{
|
||||||
$this->log = $log;
|
|
||||||
|
|
||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method static bool|Connection connect(string $host, string $port, bool $ssl = false)
|
* @method static bool|Connection connect(string $host, int $port, bool $ssl = false)
|
||||||
* @method static bool login(string $username, string $password, bool|Connection $connection)
|
* @method static bool login(string $username, string $password, bool|Connection $connection)
|
||||||
* @method static void close(bool|Connection $connection)
|
* @method static void close(bool|Connection $connection)
|
||||||
* @method static bool passive(bool|Connection $connection, bool $passive)
|
* @method static bool passive(bool|Connection $connection, bool $passive)
|
||||||
|
@ -2,22 +2,20 @@
|
|||||||
|
|
||||||
namespace App\Facades;
|
namespace App\Facades;
|
||||||
|
|
||||||
use App\Models\Server;
|
|
||||||
use App\Models\ServerLog;
|
|
||||||
use App\Support\Testing\SSHFake;
|
use App\Support\Testing\SSHFake;
|
||||||
use Illuminate\Support\Facades\Facade as FacadeAlias;
|
use Illuminate\Support\Facades\Facade as FacadeAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SSH
|
* Class SSH
|
||||||
*
|
*
|
||||||
* @method static init(Server $server, string $asUser = null)
|
* @method static \App\Helpers\SSH|SSHFake init(\App\Models\Server $server, string $asUser = null)
|
||||||
* @method static setLog(?ServerLog $log)
|
* @method static setLog(?\App\Models\ServerLog $log)
|
||||||
* @method static connect()
|
* @method static connect()
|
||||||
* @method static string exec(string $command, string $log = '', int $siteId = null, ?bool $stream = false, callable $streamCallback = null)
|
* @method static string exec(string $command, string $log = '', int $siteId = null, ?bool $stream = false, callable $streamCallback = null)
|
||||||
* @method static string upload(string $local, string $remote, ?string $owner = null)
|
* @method static string upload(string $local, string $remote, ?string $owner = null)
|
||||||
* @method static string download(string $local, string $remote)
|
* @method static string download(string $local, string $remote)
|
||||||
* @method static string write(string $path, string $content, string $owner = null)
|
* @method static string write(string $path, string $content, string $owner = null)
|
||||||
* @method static string assertExecuted(array|string $commands)
|
* @method static string assertExecuted(array<int, string>|string $commands)
|
||||||
* @method static string assertExecutedContains(string $command)
|
* @method static string assertExecutedContains(string $command)
|
||||||
* @method static string assertFileUploaded(string $toPath, ?string $content = null)
|
* @method static string assertFileUploaded(string $toPath, ?string $content = null)
|
||||||
* @method static string getUploadedLocalPath()
|
* @method static string getUploadedLocalPath()
|
||||||
|
@ -59,11 +59,9 @@ class Agent extends MobileDetect
|
|||||||
*/
|
*/
|
||||||
public function platform()
|
public function platform()
|
||||||
{
|
{
|
||||||
return $this->retrieveUsingCacheOrResolve('paymently.platform', function () {
|
return $this->retrieveUsingCacheOrResolve('paymently.platform', fn () => $this->findDetectionRulesAgainstUserAgent(
|
||||||
return $this->findDetectionRulesAgainstUserAgent(
|
|
||||||
$this->mergeRules(MobileDetect::getOperatingSystems(), static::$additionalOperatingSystems)
|
$this->mergeRules(MobileDetect::getOperatingSystems(), static::$additionalOperatingSystems)
|
||||||
);
|
));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,11 +71,9 @@ public function platform()
|
|||||||
*/
|
*/
|
||||||
public function browser()
|
public function browser()
|
||||||
{
|
{
|
||||||
return $this->retrieveUsingCacheOrResolve('paymently.browser', function () {
|
return $this->retrieveUsingCacheOrResolve('paymently.browser', fn () => $this->findDetectionRulesAgainstUserAgent(
|
||||||
return $this->findDetectionRulesAgainstUserAgent(
|
|
||||||
$this->mergeRules(static::$additionalBrowsers, MobileDetect::getBrowsers())
|
$this->mergeRules(static::$additionalBrowsers, MobileDetect::getBrowsers())
|
||||||
);
|
));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +83,7 @@ public function browser()
|
|||||||
*/
|
*/
|
||||||
public function isDesktop()
|
public function isDesktop()
|
||||||
{
|
{
|
||||||
return $this->retrieveUsingCacheOrResolve('paymently.desktop', function () {
|
return $this->retrieveUsingCacheOrResolve('paymently.desktop', function (): bool {
|
||||||
// Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
|
// Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
|
||||||
if (
|
if (
|
||||||
$this->getUserAgent() === static::$cloudFrontUA
|
$this->getUserAgent() === static::$cloudFrontUA
|
||||||
@ -103,19 +99,24 @@ public function isDesktop()
|
|||||||
/**
|
/**
|
||||||
* Match a detection rule and return the matched key.
|
* Match a detection rule and return the matched key.
|
||||||
*
|
*
|
||||||
|
* @param array<mixed, string> $rules
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
protected function findDetectionRulesAgainstUserAgent(array $rules)
|
protected function findDetectionRulesAgainstUserAgent(array $rules)
|
||||||
{
|
{
|
||||||
$userAgent = $this->getUserAgent();
|
$userAgent = $this->getUserAgent();
|
||||||
|
|
||||||
|
if ($userAgent === null || $userAgent === '' || $userAgent === '0') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($rules as $key => $regex) {
|
foreach ($rules as $key => $regex) {
|
||||||
if (empty($regex)) {
|
if (empty($regex)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->match($regex, $userAgent)) {
|
if ($this->match($regex, $userAgent)) {
|
||||||
return $key ?: reset($this->matchesArray);
|
return $key !== 0 && ($key !== '' && $key !== '0') ? $key : reset($this->matchesArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ protected function retrieveUsingCacheOrResolve(string $key, Closure $callback)
|
|||||||
return $cacheItem;
|
return $cacheItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tap(call_user_func($callback), function ($result) use ($cacheKey) {
|
return tap(call_user_func($callback), function ($result) use ($cacheKey): void {
|
||||||
$this->store[$cacheKey] = $result;
|
$this->store[$cacheKey] = $result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -144,10 +145,10 @@ protected function retrieveUsingCacheOrResolve(string $key, Closure $callback)
|
|||||||
/**
|
/**
|
||||||
* Merge multiple rules into one array.
|
* Merge multiple rules into one array.
|
||||||
*
|
*
|
||||||
* @param array $all
|
* @param array<mixed> $all
|
||||||
* @return array<string, string>
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
protected function mergeRules(...$all)
|
protected function mergeRules(...$all): array
|
||||||
{
|
{
|
||||||
$merged = [];
|
$merged = [];
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class FTP
|
class FTP
|
||||||
{
|
{
|
||||||
public function connect(string $host, string $port, bool $ssl = false): bool|Connection
|
public function connect(string $host, int $port, bool $ssl = false): bool|Connection
|
||||||
{
|
{
|
||||||
if ($ssl) {
|
if ($ssl) {
|
||||||
return ftp_ssl_connect($host, $port, 5);
|
return ftp_ssl_connect($host, $port, 5);
|
||||||
@ -15,22 +15,22 @@ public function connect(string $host, string $port, bool $ssl = false): bool|Con
|
|||||||
return ftp_connect($host, $port, 5);
|
return ftp_connect($host, $port, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login(string $username, string $password, bool|Connection $connection): bool
|
public function login(string $username, string $password, Connection $connection): bool
|
||||||
{
|
{
|
||||||
return ftp_login($connection, $username, $password);
|
return ftp_login($connection, $username, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(bool|Connection $connection): void
|
public function close(Connection $connection): void
|
||||||
{
|
{
|
||||||
ftp_close($connection);
|
ftp_close($connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function passive(bool|Connection $connection, bool $passive): bool
|
public function passive(Connection $connection, bool $passive): bool
|
||||||
{
|
{
|
||||||
return ftp_pasv($connection, $passive);
|
return ftp_pasv($connection, $passive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(bool|Connection $connection, string $path): bool
|
public function delete(Connection $connection, string $path): bool
|
||||||
{
|
{
|
||||||
return ftp_delete($connection, $path);
|
return ftp_delete($connection, $path);
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,13 @@ class SSH
|
|||||||
{
|
{
|
||||||
public Server $server;
|
public Server $server;
|
||||||
|
|
||||||
public ?ServerLog $log;
|
public ?ServerLog $log = null;
|
||||||
|
|
||||||
protected SSH2|SFTP|null $connection = null;
|
protected SSH2|SFTP|null $connection = null;
|
||||||
|
|
||||||
protected ?string $user;
|
protected string $user = '';
|
||||||
|
|
||||||
protected ?string $asUser;
|
protected ?string $asUser = null;
|
||||||
|
|
||||||
protected string $publicKey;
|
protected string $publicKey;
|
||||||
|
|
||||||
@ -42,11 +42,11 @@ public function init(Server $server, ?string $asUser = null): self
|
|||||||
$this->asUser = null;
|
$this->asUser = null;
|
||||||
$this->server = $server->refresh();
|
$this->server = $server->refresh();
|
||||||
$this->user = $server->getSshUser();
|
$this->user = $server->getSshUser();
|
||||||
if ($asUser && $asUser != $server->getSshUser()) {
|
if ($asUser && $asUser !== $server->getSshUser()) {
|
||||||
$this->asUser = $asUser;
|
$this->asUser = $asUser;
|
||||||
}
|
}
|
||||||
$this->privateKey = PublicKeyLoader::loadPrivateKey(
|
$this->privateKey = PublicKeyLoader::loadPrivateKey(
|
||||||
file_get_contents($this->server->sshKey()['private_key_path'])
|
(string) file_get_contents($this->server->sshKey()['private_key_path'])
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -94,9 +94,9 @@ public function connect(bool $sftp = false): void
|
|||||||
*/
|
*/
|
||||||
public function exec(string $command, string $log = '', ?int $siteId = null, ?bool $stream = false, ?callable $streamCallback = null): string
|
public function exec(string $command, string $log = '', ?int $siteId = null, ?bool $stream = false, ?callable $streamCallback = null): string
|
||||||
{
|
{
|
||||||
if (! $this->log && $log) {
|
if (! $this->log instanceof ServerLog && $log) {
|
||||||
$this->log = ServerLog::make($this->server, $log);
|
$this->log = ServerLog::newLog($this->server, $log);
|
||||||
if ($siteId) {
|
if ($siteId !== null && $siteId !== 0) {
|
||||||
$this->log->forSite($siteId);
|
$this->log->forSite($siteId);
|
||||||
}
|
}
|
||||||
$this->log->save();
|
$this->log->save();
|
||||||
@ -111,14 +111,15 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->asUser) {
|
if ($this->asUser !== null && $this->asUser !== '' && $this->asUser !== '0') {
|
||||||
$command = addslashes($command);
|
$command = addslashes($command);
|
||||||
$command = str_replace('\\\'', '\'', $command);
|
$command = str_replace('\\\'', '\'', $command);
|
||||||
$command = 'sudo su - '.$this->asUser.' -c '.'"'.trim($command).'"';
|
$command = 'sudo su - '.$this->asUser.' -c '.'"'.trim($command).'"';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->connection->setTimeout(0);
|
$this->connection->setTimeout(0);
|
||||||
if ($stream) {
|
if ($stream === true) {
|
||||||
|
/** @var callable $streamCallback */
|
||||||
$this->connection->exec($command, function ($output) use ($streamCallback) {
|
$this->connection->exec($command, function ($output) use ($streamCallback) {
|
||||||
$this->log?->write($output);
|
$this->log?->write($output);
|
||||||
|
|
||||||
@ -126,13 +127,12 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
|||||||
});
|
});
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
} else {
|
}
|
||||||
$output = '';
|
$output = '';
|
||||||
$this->connection->exec($command, function ($out) use (&$output) {
|
$this->connection->exec($command, function (string $out) use (&$output): void {
|
||||||
$this->log?->write($out);
|
$this->log?->write($out);
|
||||||
$output .= $out;
|
$output .= $out;
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($this->connection->getExitStatus() !== 0 || Str::contains($output, 'VITO_SSH_ERROR')) {
|
if ($this->connection->getExitStatus() !== 0 || Str::contains($output, 'VITO_SSH_ERROR')) {
|
||||||
throw new SSHCommandError(
|
throw new SSHCommandError(
|
||||||
message: 'SSH command failed with an error',
|
message: 'SSH command failed with an error',
|
||||||
@ -141,7 +141,6 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
Log::error('Error executing command', [
|
Log::error('Error executing command', [
|
||||||
'msg' => $e->getMessage(),
|
'msg' => $e->getMessage(),
|
||||||
@ -168,10 +167,11 @@ public function upload(string $local, string $remote, ?string $owner = null): vo
|
|||||||
$tmpName = Str::random(10).strtotime('now');
|
$tmpName = Str::random(10).strtotime('now');
|
||||||
$tempPath = home_path($this->user).'/'.$tmpName;
|
$tempPath = home_path($this->user).'/'.$tmpName;
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
$this->connection->put($tempPath, $local, SFTP::SOURCE_LOCAL_FILE);
|
$this->connection->put($tempPath, $local, SFTP::SOURCE_LOCAL_FILE);
|
||||||
|
|
||||||
$this->exec(sprintf('sudo mv %s %s', $tempPath, $remote));
|
$this->exec(sprintf('sudo mv %s %s', $tempPath, $remote));
|
||||||
if (! $owner) {
|
if ($owner === null || $owner === '' || $owner === '0') {
|
||||||
$owner = $this->user;
|
$owner = $this->user;
|
||||||
}
|
}
|
||||||
$this->exec(sprintf('sudo chown %s:%s %s', $owner, $owner, $remote));
|
$this->exec(sprintf('sudo chown %s:%s %s', $owner, $owner, $remote));
|
||||||
@ -189,6 +189,7 @@ public function download(string $local, string $remote): void
|
|||||||
$this->connect(true);
|
$this->connect(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
$this->connection->get($remote, $local);
|
$this->connection->get($remote, $local);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +221,7 @@ public function write(string $remotePath, string $content, ?string $owner = null
|
|||||||
*/
|
*/
|
||||||
public function disconnect(): void
|
public function disconnect(): void
|
||||||
{
|
{
|
||||||
if ($this->connection) {
|
if ($this->connection instanceof SSH2) {
|
||||||
$this->connection->disconnect();
|
$this->connection->disconnect();
|
||||||
$this->connection = null;
|
$this->connection = null;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public function show(Project $project, Server $server, CronJob $cronJob): CronJo
|
|||||||
#[Delete('{cronJob}', name: 'api.projects.servers.cron-jobs.delete', middleware: 'ability:write')]
|
#[Delete('{cronJob}', name: 'api.projects.servers.cron-jobs.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete cron job.')]
|
#[Endpoint(title: 'delete', description: 'Delete cron job.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, Server $server, CronJob $cronJob)
|
public function delete(Project $project, Server $server, CronJob $cronJob): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', [$cronJob, $server]);
|
$this->authorize('delete', [$cronJob, $server]);
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public function show(Project $project, Server $server, Database $database): Data
|
|||||||
#[Delete('{database}', name: 'api.projects.servers.databases.delete', middleware: 'ability:write')]
|
#[Delete('{database}', name: 'api.projects.servers.databases.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete database.')]
|
#[Endpoint(title: 'delete', description: 'Delete database.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, Server $server, Database $database)
|
public function delete(Project $project, Server $server, Database $database): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', [$database, $server]);
|
$this->authorize('delete', [$database, $server]);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public function link(Request $request, Project $project, Server $server, Databas
|
|||||||
#[Delete('{databaseUser}', name: 'api.projects.servers.database-users.delete', middleware: 'ability:write')]
|
#[Delete('{databaseUser}', name: 'api.projects.servers.database-users.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete database user.')]
|
#[Endpoint(title: 'delete', description: 'Delete database user.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, Server $server, DatabaseUser $databaseUser)
|
public function delete(Project $project, Server $server, DatabaseUser $databaseUser): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', [$databaseUser, $server]);
|
$this->authorize('delete', [$databaseUser, $server]);
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public function show(Project $project, Server $server, FirewallRule $firewallRul
|
|||||||
#[Delete('{firewallRule}', name: 'api.projects.servers.firewall-rules.delete', middleware: 'ability:write')]
|
#[Delete('{firewallRule}', name: 'api.projects.servers.firewall-rules.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete firewall rule.')]
|
#[Endpoint(title: 'delete', description: 'Delete firewall rule.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, Server $server, FirewallRule $firewallRule)
|
public function delete(Project $project, Server $server, FirewallRule $firewallRule): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', [$firewallRule, $server]);
|
$this->authorize('delete', [$firewallRule, $server]);
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\GitHook;
|
use App\Models\GitHook;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
|
use App\Models\SourceControl;
|
||||||
use App\Notifications\SourceControlDisconnected;
|
use App\Notifications\SourceControlDisconnected;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Spatie\RouteAttributes\Attributes\Any;
|
use Spatie\RouteAttributes\Attributes\Any;
|
||||||
@ -17,7 +19,7 @@
|
|||||||
class GitHookController extends Controller
|
class GitHookController extends Controller
|
||||||
{
|
{
|
||||||
#[Any('api/git-hooks', name: 'api.git-hooks')]
|
#[Any('api/git-hooks', name: 'api.git-hooks')]
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
if (! $request->input('secret')) {
|
if (! $request->input('secret')) {
|
||||||
abort(404);
|
abort(404);
|
||||||
@ -29,7 +31,9 @@ public function __invoke(Request $request)
|
|||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
foreach ($gitHook->actions as $action) {
|
foreach ($gitHook->actions as $action) {
|
||||||
$webhookBranch = $gitHook->site->sourceControl->provider()->getWebhookBranch($request->array());
|
/** @var SourceControl $sourceControl */
|
||||||
|
$sourceControl = $gitHook->site->sourceControl;
|
||||||
|
$webhookBranch = $sourceControl->provider()->getWebhookBranch($request->array());
|
||||||
if ($action == 'deploy' && $gitHook->site->branch === $webhookBranch) {
|
if ($action == 'deploy' && $gitHook->site->branch === $webhookBranch) {
|
||||||
try {
|
try {
|
||||||
app(Deploy::class)->run($gitHook->site);
|
app(Deploy::class)->run($gitHook->site);
|
||||||
|
@ -14,7 +14,7 @@ class HealthController extends Controller
|
|||||||
#[Get('api/health', name: 'api.health')]
|
#[Get('api/health', name: 'api.health')]
|
||||||
#[Unauthenticated]
|
#[Unauthenticated]
|
||||||
#[Endpoint(title: 'health-check')]
|
#[Endpoint(title: 'health-check')]
|
||||||
public function __invoke()
|
public function __invoke(): \Illuminate\Http\JsonResponse
|
||||||
{
|
{
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
|
@ -45,7 +45,9 @@ public function create(Request $request): ProjectResource
|
|||||||
|
|
||||||
$this->validate($request, CreateProject::rules());
|
$this->validate($request, CreateProject::rules());
|
||||||
|
|
||||||
$project = app(CreateProject::class)->create(auth()->user(), $request->all());
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$project = app(CreateProject::class)->create($user, $request->all());
|
||||||
|
|
||||||
return new ProjectResource($project);
|
return new ProjectResource($project);
|
||||||
}
|
}
|
||||||
@ -82,7 +84,9 @@ public function delete(Project $project): Response
|
|||||||
{
|
{
|
||||||
$this->authorize('delete', $project);
|
$this->authorize('delete', $project);
|
||||||
|
|
||||||
app(DeleteProject::class)->delete(auth()->user(), $project);
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
app(DeleteProject::class)->delete($user, $project);
|
||||||
|
|
||||||
return response()->noContent();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,9 @@ public function create(Request $request, Project $project): ServerResource
|
|||||||
|
|
||||||
$this->validate($request, CreateServer::rules($project, $request->input()));
|
$this->validate($request, CreateServer::rules($project, $request->input()));
|
||||||
|
|
||||||
$server = app(CreateServer::class)->create(auth()->user(), $project, $request->all());
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$server = app(CreateServer::class)->create($user, $project, $request->all());
|
||||||
|
|
||||||
return new ServerResource($server);
|
return new ServerResource($server);
|
||||||
}
|
}
|
||||||
@ -81,7 +83,7 @@ public function show(Project $project, Server $server): ServerResource
|
|||||||
#[Post('{server}/reboot', name: 'api.projects.servers.reboot', middleware: 'ability:write')]
|
#[Post('{server}/reboot', name: 'api.projects.servers.reboot', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'reboot', description: 'Reboot a server.')]
|
#[Endpoint(title: 'reboot', description: 'Reboot a server.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function reboot(Project $project, Server $server)
|
public function reboot(Project $project, Server $server): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('update', [$server, $project]);
|
$this->authorize('update', [$server, $project]);
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ public function reboot(Project $project, Server $server)
|
|||||||
#[Post('{server}/upgrade', name: 'api.projects.servers.upgrade', middleware: 'ability:write')]
|
#[Post('{server}/upgrade', name: 'api.projects.servers.upgrade', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'upgrade', description: 'Upgrade server.')]
|
#[Endpoint(title: 'upgrade', description: 'Upgrade server.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function upgrade(Project $project, Server $server)
|
public function upgrade(Project $project, Server $server): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('update', [$server, $project]);
|
$this->authorize('update', [$server, $project]);
|
||||||
|
|
||||||
@ -109,7 +111,7 @@ public function upgrade(Project $project, Server $server)
|
|||||||
#[Delete('{server}', name: 'api.projects.servers.delete', middleware: 'ability:write')]
|
#[Delete('{server}', name: 'api.projects.servers.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete server.')]
|
#[Endpoint(title: 'delete', description: 'Delete server.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, Server $server)
|
public function delete(Project $project, Server $server): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', [$server, $project]);
|
$this->authorize('delete', [$server, $project]);
|
||||||
|
|
||||||
|
@ -54,7 +54,9 @@ public function create(Request $request, Project $project): ServerProviderResour
|
|||||||
|
|
||||||
$this->validate($request, CreateServerProvider::rules($request->all()));
|
$this->validate($request, CreateServerProvider::rules($request->all()));
|
||||||
|
|
||||||
$serverProvider = app(CreateServerProvider::class)->create(auth()->user(), $project, $request->all());
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$serverProvider = app(CreateServerProvider::class)->create($user, $project, $request->all());
|
||||||
|
|
||||||
return new ServerProviderResource($serverProvider);
|
return new ServerProviderResource($serverProvider);
|
||||||
}
|
}
|
||||||
@ -62,7 +64,7 @@ public function create(Request $request, Project $project): ServerProviderResour
|
|||||||
#[Get('{serverProvider}', name: 'api.projects.server-providers.show', middleware: 'ability:read')]
|
#[Get('{serverProvider}', name: 'api.projects.server-providers.show', middleware: 'ability:read')]
|
||||||
#[Endpoint(title: 'show')]
|
#[Endpoint(title: 'show')]
|
||||||
#[ResponseFromApiResource(ServerProviderResource::class, ServerProvider::class)]
|
#[ResponseFromApiResource(ServerProviderResource::class, ServerProvider::class)]
|
||||||
public function show(Project $project, ServerProvider $serverProvider)
|
public function show(Project $project, ServerProvider $serverProvider): \App\Http\Resources\ServerProviderResource
|
||||||
{
|
{
|
||||||
$this->authorize('view', $serverProvider);
|
$this->authorize('view', $serverProvider);
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ public function show(Project $project, ServerProvider $serverProvider)
|
|||||||
#[BodyParam(name: 'name', description: 'The name of the server provider.', required: true)]
|
#[BodyParam(name: 'name', description: 'The name of the server provider.', required: true)]
|
||||||
#[BodyParam(name: 'global', description: 'Accessible in all projects', enum: [true, false])]
|
#[BodyParam(name: 'global', description: 'Accessible in all projects', enum: [true, false])]
|
||||||
#[ResponseFromApiResource(ServerProviderResource::class, ServerProvider::class)]
|
#[ResponseFromApiResource(ServerProviderResource::class, ServerProvider::class)]
|
||||||
public function update(Request $request, Project $project, ServerProvider $serverProvider)
|
public function update(Request $request, Project $project, ServerProvider $serverProvider): \App\Http\Resources\ServerProviderResource
|
||||||
{
|
{
|
||||||
$this->authorize('update', $serverProvider);
|
$this->authorize('update', $serverProvider);
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ public function update(Request $request, Project $project, ServerProvider $serve
|
|||||||
#[Delete('{serverProvider}', name: 'api.projects.server-providers.delete', middleware: 'ability:write')]
|
#[Delete('{serverProvider}', name: 'api.projects.server-providers.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete')]
|
#[Endpoint(title: 'delete')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, ServerProvider $serverProvider)
|
public function delete(Project $project, ServerProvider $serverProvider): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', $serverProvider);
|
$this->authorize('delete', $serverProvider);
|
||||||
|
|
||||||
|
@ -52,16 +52,21 @@ public function create(Request $request, Project $project, Server $server): SshK
|
|||||||
|
|
||||||
$this->validateRoute($project, $server);
|
$this->validateRoute($project, $server);
|
||||||
|
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
$sshKey = null;
|
$sshKey = null;
|
||||||
if ($request->has('key_id')) {
|
if ($request->has('key_id')) {
|
||||||
$this->validate($request, DeployKeyToServer::rules($request->user(), $server));
|
$this->validate($request, DeployKeyToServer::rules($user, $server));
|
||||||
|
|
||||||
$sshKey = $request->user()->sshKeys()->findOrFail($request->key_id);
|
/** @var ?SshKey $sshKey */
|
||||||
|
$sshKey = $user->sshKeys()->findOrFail($request->key_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $sshKey) {
|
if (! $sshKey) {
|
||||||
$this->validate($request, CreateSshKey::rules());
|
$this->validate($request, CreateSshKey::rules());
|
||||||
$sshKey = app(CreateSshKey::class)->create($request->user(), $request->all());
|
/** @var SshKey $sshKey */
|
||||||
|
$sshKey = app(CreateSshKey::class)->create($user, $request->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
app(DeployKeyToServer::class)->deploy($server, ['key_id' => $sshKey->id]);
|
app(DeployKeyToServer::class)->deploy($server, ['key_id' => $sshKey->id]);
|
||||||
@ -72,7 +77,7 @@ public function create(Request $request, Project $project, Server $server): SshK
|
|||||||
#[Delete('{sshKey}', name: 'api.projects.servers.ssh-keys.delete', middleware: 'ability:write')]
|
#[Delete('{sshKey}', name: 'api.projects.servers.ssh-keys.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete ssh key from server.')]
|
#[Endpoint(title: 'delete', description: 'Delete ssh key from server.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, Server $server, SshKey $sshKey)
|
public function delete(Project $project, Server $server, SshKey $sshKey): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', [$sshKey, $server]);
|
$this->authorize('delete', [$sshKey, $server]);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public function show(Project $project, Server $server, Site $site): SiteResource
|
|||||||
#[Delete('{site}', name: 'api.projects.servers.sites.delete', middleware: 'ability:write')]
|
#[Delete('{site}', name: 'api.projects.servers.sites.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete', description: 'Delete site.')]
|
#[Endpoint(title: 'delete', description: 'Delete site.')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, Server $server, Site $site)
|
public function delete(Project $project, Server $server, Site $site): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', [$site, $server]);
|
$this->authorize('delete', [$site, $server]);
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public function create(Request $request, Project $project): SourceControlResourc
|
|||||||
|
|
||||||
$this->validate($request, ConnectSourceControl::rules($request->all()));
|
$this->validate($request, ConnectSourceControl::rules($request->all()));
|
||||||
|
|
||||||
$sourceControl = app(ConnectSourceControl::class)->connect(auth()->user(), $project, $request->all());
|
$sourceControl = app(ConnectSourceControl::class)->connect($project, $request->all());
|
||||||
|
|
||||||
return new SourceControlResource($sourceControl);
|
return new SourceControlResource($sourceControl);
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ public function create(Request $request, Project $project): SourceControlResourc
|
|||||||
#[Get('{sourceControl}', name: 'api.projects.source-controls.show', middleware: 'ability:read')]
|
#[Get('{sourceControl}', name: 'api.projects.source-controls.show', middleware: 'ability:read')]
|
||||||
#[Endpoint(title: 'show')]
|
#[Endpoint(title: 'show')]
|
||||||
#[ResponseFromApiResource(SourceControlResource::class, SourceControl::class)]
|
#[ResponseFromApiResource(SourceControlResource::class, SourceControl::class)]
|
||||||
public function show(Project $project, SourceControl $sourceControl)
|
public function show(Project $project, SourceControl $sourceControl): \App\Http\Resources\SourceControlResource
|
||||||
{
|
{
|
||||||
$this->authorize('view', $sourceControl);
|
$this->authorize('view', $sourceControl);
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ public function show(Project $project, SourceControl $sourceControl)
|
|||||||
#[BodyParam(name: 'password', description: 'The password if the provider is Bitbucket')]
|
#[BodyParam(name: 'password', description: 'The password if the provider is Bitbucket')]
|
||||||
#[BodyParam(name: 'global', description: 'Accessible in all projects', enum: [true, false])]
|
#[BodyParam(name: 'global', description: 'Accessible in all projects', enum: [true, false])]
|
||||||
#[ResponseFromApiResource(SourceControlResource::class, SourceControl::class)]
|
#[ResponseFromApiResource(SourceControlResource::class, SourceControl::class)]
|
||||||
public function update(Request $request, Project $project, SourceControl $sourceControl)
|
public function update(Request $request, Project $project, SourceControl $sourceControl): \App\Http\Resources\SourceControlResource
|
||||||
{
|
{
|
||||||
$this->authorize('update', $sourceControl);
|
$this->authorize('update', $sourceControl);
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ public function update(Request $request, Project $project, SourceControl $source
|
|||||||
#[Delete('{sourceControl}', name: 'api.projects.source-controls.delete', middleware: 'ability:write')]
|
#[Delete('{sourceControl}', name: 'api.projects.source-controls.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete')]
|
#[Endpoint(title: 'delete')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, SourceControl $sourceControl)
|
public function delete(Project $project, SourceControl $sourceControl): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', $sourceControl);
|
$this->authorize('delete', $sourceControl);
|
||||||
|
|
||||||
|
@ -54,7 +54,9 @@ public function create(Request $request, Project $project): StorageProviderResou
|
|||||||
|
|
||||||
$this->validate($request, CreateStorageProvider::rules($request->all()));
|
$this->validate($request, CreateStorageProvider::rules($request->all()));
|
||||||
|
|
||||||
$storageProvider = app(CreateStorageProvider::class)->create(auth()->user(), $project, $request->all());
|
/** @var \App\Models\User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$storageProvider = app(CreateStorageProvider::class)->create($user, $project, $request->all());
|
||||||
|
|
||||||
return new StorageProviderResource($storageProvider);
|
return new StorageProviderResource($storageProvider);
|
||||||
}
|
}
|
||||||
@ -62,7 +64,7 @@ public function create(Request $request, Project $project): StorageProviderResou
|
|||||||
#[Get('{storageProvider}', name: 'api.projects.storage-providers.show', middleware: 'ability:read')]
|
#[Get('{storageProvider}', name: 'api.projects.storage-providers.show', middleware: 'ability:read')]
|
||||||
#[Endpoint(title: 'show')]
|
#[Endpoint(title: 'show')]
|
||||||
#[ResponseFromApiResource(StorageProviderResource::class, StorageProvider::class)]
|
#[ResponseFromApiResource(StorageProviderResource::class, StorageProvider::class)]
|
||||||
public function show(Project $project, StorageProvider $storageProvider)
|
public function show(Project $project, StorageProvider $storageProvider): \App\Http\Resources\StorageProviderResource
|
||||||
{
|
{
|
||||||
$this->authorize('view', $storageProvider);
|
$this->authorize('view', $storageProvider);
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ public function show(Project $project, StorageProvider $storageProvider)
|
|||||||
#[BodyParam(name: 'name', description: 'The name of the storage provider.', required: true)]
|
#[BodyParam(name: 'name', description: 'The name of the storage provider.', required: true)]
|
||||||
#[BodyParam(name: 'global', description: 'Accessible in all projects', enum: [true, false])]
|
#[BodyParam(name: 'global', description: 'Accessible in all projects', enum: [true, false])]
|
||||||
#[ResponseFromApiResource(StorageProviderResource::class, StorageProvider::class)]
|
#[ResponseFromApiResource(StorageProviderResource::class, StorageProvider::class)]
|
||||||
public function update(Request $request, Project $project, StorageProvider $storageProvider)
|
public function update(Request $request, Project $project, StorageProvider $storageProvider): \App\Http\Resources\StorageProviderResource
|
||||||
{
|
{
|
||||||
$this->authorize('update', $storageProvider);
|
$this->authorize('update', $storageProvider);
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ public function update(Request $request, Project $project, StorageProvider $stor
|
|||||||
#[Delete('{storageProvider}', name: 'api.projects.storage-providers.delete', middleware: 'ability:write')]
|
#[Delete('{storageProvider}', name: 'api.projects.storage-providers.delete', middleware: 'ability:write')]
|
||||||
#[Endpoint(title: 'delete')]
|
#[Endpoint(title: 'delete')]
|
||||||
#[Response(status: 204)]
|
#[Response(status: 204)]
|
||||||
public function delete(Project $project, StorageProvider $storageProvider)
|
public function delete(Project $project, StorageProvider $storageProvider): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
$this->authorize('delete', $storageProvider);
|
$this->authorize('delete', $storageProvider);
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user