mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
refactoring
This commit is contained in:
@ -13,7 +13,7 @@ class CreateDatabaseUser
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function create(Server $server, array $input): DatabaseUser
|
||||
public function create(Server $server, array $input, array $links = []): DatabaseUser
|
||||
{
|
||||
$this->validate($server, $input);
|
||||
|
||||
@ -22,6 +22,7 @@ public function create(Server $server, array $input): DatabaseUser
|
||||
'username' => $input['username'],
|
||||
'password' => $input['password'],
|
||||
'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost',
|
||||
'databases' => $links,
|
||||
]);
|
||||
$databaseUser->save();
|
||||
$databaseUser->createOnServer();
|
||||
|
@ -21,7 +21,7 @@ public function create(Server $server, array $input): FirewallRule
|
||||
'protocol' => $input['protocol'],
|
||||
'port' => $input['port'],
|
||||
'source' => $input['source'],
|
||||
'mask' => $input['mask'],
|
||||
'mask' => $input['mask'] ?? null,
|
||||
'status' => FirewallRuleStatus::CREATING,
|
||||
]);
|
||||
$rule->save();
|
||||
@ -49,14 +49,12 @@ private function validate(Server $server, array $input): void
|
||||
'numeric',
|
||||
'min:1',
|
||||
'max:65535',
|
||||
Rule::unique('firewall_rules', 'port')->where('server_id', $server->id),
|
||||
],
|
||||
'source' => [
|
||||
'required',
|
||||
'ip',
|
||||
],
|
||||
'mask' => [
|
||||
'required',
|
||||
'numeric',
|
||||
],
|
||||
])->validateWithBag('createRule');
|
||||
|
@ -29,6 +29,8 @@ public function update(Service $service, string $ini): void
|
||||
'ini' => __("Couldn't update php.ini file!"),
|
||||
]);
|
||||
}
|
||||
|
||||
$service->restart();
|
||||
}
|
||||
|
||||
private function deleteTempFile(string $name): void
|
||||
|
@ -36,8 +36,8 @@ public function create(User $creator, array $input): Server
|
||||
'provider' => $input['provider'],
|
||||
'authentication' => [
|
||||
'user' => config('core.ssh_user'),
|
||||
'pass' => Str::random(10),
|
||||
'root_pass' => Str::random(10),
|
||||
'pass' => Str::random(15),
|
||||
'root_pass' => Str::random(15),
|
||||
],
|
||||
'progress' => 0,
|
||||
'progress_step' => 'Initializing',
|
||||
@ -77,8 +77,7 @@ public function create(User $creator, array $input): Server
|
||||
$server->progress_step = __('Installation will begin in 3 minutes!');
|
||||
$server->save();
|
||||
dispatch(new ContinueInstallation($server))
|
||||
->delay(now()->addMinutes(3))
|
||||
->onQueue('default');
|
||||
->delay(now()->addMinutes(2));
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
|
@ -3,33 +3,48 @@
|
||||
namespace App\Actions\SourceControl;
|
||||
|
||||
use App\Models\SourceControl;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class ConnectSourceControl
|
||||
{
|
||||
public function connect(string $provider, array $input): void
|
||||
public function connect(array $input): void
|
||||
{
|
||||
$sourceControl = SourceControl::query()
|
||||
->where('provider', $provider)
|
||||
->first();
|
||||
if (! $sourceControl) {
|
||||
$sourceControl = new SourceControl([
|
||||
'provider' => $provider,
|
||||
]);
|
||||
}
|
||||
$this->validate($input);
|
||||
$sourceControl = new SourceControl([
|
||||
'provider' => $input['provider'],
|
||||
'profile' => $input['name'],
|
||||
'access_token' => $input['token']
|
||||
]);
|
||||
|
||||
if (! $input['token']) {
|
||||
$sourceControl->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$sourceControl->access_token = $input['token'];
|
||||
if (! $sourceControl->provider()->connect()) {
|
||||
throw ValidationException::withMessages([
|
||||
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $provider]),
|
||||
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $sourceControl->provider]
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
$sourceControl->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validate(array $input): void
|
||||
{
|
||||
$rules = [
|
||||
'provider' => [
|
||||
'required',
|
||||
Rule::in(\App\Enums\SourceControl::getValues())
|
||||
],
|
||||
'name' => [
|
||||
'required',
|
||||
],
|
||||
'token' => [
|
||||
'required'
|
||||
]
|
||||
];
|
||||
Validator::make($input, $rules)->validate();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user