mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-17 17:01:37 +00:00
- refactoring architecture - fix incomplete ssh logs - code editor for scripts in the app - remove Jobs and SSHCommands
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\SSL;
|
|
|
|
use App\Enums\SslStatus;
|
|
use App\Enums\SslType;
|
|
use App\Models\Site;
|
|
use App\Models\Ssl;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class CreateSSL
|
|
{
|
|
/**
|
|
* @throws ValidationException
|
|
*/
|
|
public function create(Site $site, array $input): void
|
|
{
|
|
$this->validate($input);
|
|
|
|
$ssl = new Ssl([
|
|
'site_id' => $site->id,
|
|
'type' => $input['type'],
|
|
'certificate' => $input['certificate'] ?? null,
|
|
'pk' => $input['private'] ?? null,
|
|
'expires_at' => $input['type'] === SslType::LETSENCRYPT ? now()->addMonths(3) : null,
|
|
'status' => SslStatus::CREATING,
|
|
]);
|
|
$ssl->save();
|
|
|
|
dispatch(function () use ($site, $ssl) {
|
|
$site->server->webserver()->handler()->setupSSL($ssl);
|
|
$ssl->status = SslStatus::CREATED;
|
|
$ssl->save();
|
|
$site->type()->edit();
|
|
})->catch(function () use ($ssl) {
|
|
$ssl->delete();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @throws ValidationException
|
|
*/
|
|
protected function validate(array $input): void
|
|
{
|
|
$rules = [
|
|
'type' => [
|
|
'required',
|
|
Rule::in(SslType::getValues()),
|
|
],
|
|
];
|
|
if (isset($input['type']) && $input['type'] == SslType::CUSTOM) {
|
|
$rules['certificate'] = 'required';
|
|
$rules['private'] = 'required';
|
|
}
|
|
|
|
Validator::make($input, $rules)->validate();
|
|
}
|
|
}
|