refactoring (#116)

- refactoring architecture
- fix incomplete ssh logs
- code editor for scripts in the app
- remove Jobs and SSHCommands
This commit is contained in:
Saeed Vaziry
2024-03-14 20:03:43 +01:00
committed by GitHub
parent cee4a70c3c
commit 428140b931
472 changed files with 24110 additions and 8159 deletions

View File

@ -2,9 +2,6 @@
namespace App\Models;
use App\Enums\SslStatus;
use App\Jobs\Ssl\Deploy;
use App\Jobs\Ssl\Remove;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -19,9 +16,6 @@
* @property Carbon $expires_at
* @property string $status
* @property Site $site
* @property string $certs_directory_path
* @property string $certificate_path
* @property string $pk_path
* @property string $ca_path
*/
class Ssl extends AbstractModel
@ -51,7 +45,7 @@ public function site(): BelongsTo
return $this->belongsTo(Site::class);
}
public function getCertsDirectoryPathAttribute(): ?string
public function getCertsDirectoryPath(): ?string
{
if ($this->type == 'letsencrypt') {
return '/etc/letsencrypt/live/'.$this->site->domain;
@ -64,57 +58,45 @@ public function getCertsDirectoryPathAttribute(): ?string
return '';
}
public function getCertificatePathAttribute(): ?string
public function getCertificatePath(): ?string
{
if ($this->type == 'letsencrypt') {
return $this->certificate;
}
if ($this->type == 'custom') {
return $this->certs_directory_path.'/cert.pem';
return $this->getCertsDirectoryPath().'/cert.pem';
}
return '';
}
public function getPkPathAttribute(): ?string
public function getPkPath(): ?string
{
if ($this->type == 'letsencrypt') {
return $this->pk;
}
if ($this->type == 'custom') {
return $this->certs_directory_path.'/privkey.pem';
return $this->getCertsDirectoryPath().'/privkey.pem';
}
return '';
}
public function getCaPathAttribute(): ?string
public function getCaPath(): ?string
{
if ($this->type == 'letsencrypt') {
return $this->ca;
}
if ($this->type == 'custom') {
return $this->certs_directory_path.'/fullchain.pem';
return $this->getCertsDirectoryPath().'/fullchain.pem';
}
return '';
}
public function deploy(): void
{
dispatch(new Deploy($this))->onConnection('ssh');
}
public function remove(): void
{
$this->status = SslStatus::DELETING;
$this->save();
dispatch(new Remove($this))->onConnection('ssh');
}
public function validateSetup(string $result): bool
{
if (! Str::contains($result, 'Successfully received certificate')) {
@ -122,8 +104,8 @@ public function validateSetup(string $result): bool
}
if ($this->type == 'letsencrypt') {
$this->certificate = $this->certs_directory_path.'/fullchain.pem';
$this->pk = $this->certs_directory_path.'/privkey.pem';
$this->certificate = $this->getCertsDirectoryPath().'/fullchain.pem';
$this->pk = $this->getCertsDirectoryPath().'/privkey.pem';
$this->save();
}