mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
refactoring (#116)
- refactoring architecture - fix incomplete ssh logs - code editor for scripts in the app - remove Jobs and SSHCommands
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user