chore: improve code quality suggested by code rabbit

This commit is contained in:
peaklabs-dev
2025-02-19 18:04:58 +01:00
parent 9557957f18
commit 225f24e650
27 changed files with 138 additions and 144 deletions

View File

@@ -36,9 +36,7 @@ class StartDragonfly
if (! $this->database->enable_ssl) { if (! $this->database->enable_ssl) {
$this->commands[] = "rm -rf $this->configuration_dir/ssl"; $this->commands[] = "rm -rf $this->configuration_dir/ssl";
SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->database->sslCertificates()->delete();
->where('resource_id', $this->database->id)
->delete();
$this->database->fileStorages() $this->database->fileStorages()
->where('resource_type', $this->database->getMorphClass()) ->where('resource_type', $this->database->getMorphClass())
->where('resource_id', $this->database->id) ->where('resource_id', $this->database->id)
@@ -59,9 +57,7 @@ class StartDragonfly
$server = $this->database->destination->server; $server = $this->database->destination->server;
$caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();
$this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->ssl_certificate = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if (! $this->ssl_certificate) { if (! $this->ssl_certificate) {
$this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'";

View File

@@ -37,9 +37,7 @@ class StartKeydb
if (! $this->database->enable_ssl) { if (! $this->database->enable_ssl) {
$this->commands[] = "rm -rf $this->configuration_dir/ssl"; $this->commands[] = "rm -rf $this->configuration_dir/ssl";
SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->database->sslCertificates()->delete();
->where('resource_id', $this->database->id)
->delete();
$this->database->fileStorages() $this->database->fileStorages()
->where('resource_type', $this->database->getMorphClass()) ->where('resource_type', $this->database->getMorphClass())
->where('resource_id', $this->database->id) ->where('resource_id', $this->database->id)
@@ -60,9 +58,7 @@ class StartKeydb
$server = $this->database->destination->server; $server = $this->database->destination->server;
$caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();
$this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->ssl_certificate = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if (! $this->ssl_certificate) { if (! $this->ssl_certificate) {
$this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'";

View File

@@ -37,9 +37,7 @@ class StartMariadb
if (! $this->database->enable_ssl) { if (! $this->database->enable_ssl) {
$this->commands[] = "rm -rf $this->configuration_dir/ssl"; $this->commands[] = "rm -rf $this->configuration_dir/ssl";
SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->database->sslCertificates()->delete();
->where('resource_id', $this->database->id)
->delete();
$this->database->fileStorages() $this->database->fileStorages()
->where('resource_type', $this->database->getMorphClass()) ->where('resource_type', $this->database->getMorphClass())
@@ -61,7 +59,7 @@ class StartMariadb
$server = $this->database->destination->server; $server = $this->database->destination->server;
$caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();
$this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); $this->ssl_certificate = $this->database->sslCertificates()->first();
if (! $this->ssl_certificate) { if (! $this->ssl_certificate) {
$this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'";

View File

@@ -42,9 +42,7 @@ class StartMongodb
if (! $this->database->enable_ssl) { if (! $this->database->enable_ssl) {
$this->commands[] = "rm -rf $this->configuration_dir/ssl"; $this->commands[] = "rm -rf $this->configuration_dir/ssl";
SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->database->sslCertificates()->delete();
->where('resource_id', $this->database->id)
->delete();
$this->database->fileStorages() $this->database->fileStorages()
->where('resource_type', $this->database->getMorphClass()) ->where('resource_type', $this->database->getMorphClass())
@@ -65,7 +63,7 @@ class StartMongodb
$server = $this->database->destination->server; $server = $this->database->destination->server;
$caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();
$this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); $this->ssl_certificate = $this->database->sslCertificates()->first();
if (! $this->ssl_certificate) { if (! $this->ssl_certificate) {
$this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'";

View File

@@ -37,9 +37,7 @@ class StartMysql
if (! $this->database->enable_ssl) { if (! $this->database->enable_ssl) {
$this->commands[] = "rm -rf $this->configuration_dir/ssl"; $this->commands[] = "rm -rf $this->configuration_dir/ssl";
SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->database->sslCertificates()->delete();
->where('resource_id', $this->database->id)
->delete();
$this->database->fileStorages() $this->database->fileStorages()
->where('resource_type', $this->database->getMorphClass()) ->where('resource_type', $this->database->getMorphClass())
@@ -61,7 +59,7 @@ class StartMysql
$server = $this->database->destination->server; $server = $this->database->destination->server;
$caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();
$this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); $this->ssl_certificate = $this->database->sslCertificates()->first();
if (! $this->ssl_certificate) { if (! $this->ssl_certificate) {
$this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'";

View File

@@ -42,9 +42,7 @@ class StartPostgresql
if (! $this->database->enable_ssl) { if (! $this->database->enable_ssl) {
$this->commands[] = "rm -rf $this->configuration_dir/ssl"; $this->commands[] = "rm -rf $this->configuration_dir/ssl";
SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->database->sslCertificates()->delete();
->where('resource_id', $this->database->id)
->delete();
$this->database->fileStorages() $this->database->fileStorages()
->where('resource_type', $this->database->getMorphClass()) ->where('resource_type', $this->database->getMorphClass())
@@ -66,7 +64,7 @@ class StartPostgresql
$server = $this->database->destination->server; $server = $this->database->destination->server;
$caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();
$this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); $this->ssl_certificate = $this->database->sslCertificates()->first();
if (! $this->ssl_certificate) { if (! $this->ssl_certificate) {
$this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'";

View File

@@ -37,9 +37,7 @@ class StartRedis
if (! $this->database->enable_ssl) { if (! $this->database->enable_ssl) {
$this->commands[] = "rm -rf $this->configuration_dir/ssl"; $this->commands[] = "rm -rf $this->configuration_dir/ssl";
SslCertificate::where('resource_type', $this->database->getMorphClass()) $this->database->sslCertificates()->delete();
->where('resource_id', $this->database->id)
->delete();
$this->database->fileStorages() $this->database->fileStorages()
->where('resource_type', $this->database->getMorphClass()) ->where('resource_type', $this->database->getMorphClass())
->where('resource_id', $this->database->id) ->where('resource_id', $this->database->id)
@@ -60,7 +58,7 @@ class StartRedis
$server = $this->database->destination->server; $server = $this->database->destination->server;
$caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();
$this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); $this->ssl_certificate = $this->database->sslCertificates()->first();
if (! $this->ssl_certificate) { if (! $this->ssl_certificate) {
$this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'";

View File

@@ -25,7 +25,7 @@ class InstallDocker
commonName: 'Coolify CA Certificate', commonName: 'Coolify CA Certificate',
serverId: $server->id, serverId: $server->id,
isCaCertificate: true, isCaCertificate: true,
validityDays: 15 * 365 validityDays: 10 * 365
); );
$caCertPath = config('constants.coolify.base_config_path').'/ssl/'; $caCertPath = config('constants.coolify.base_config_path').'/ssl/';

View File

@@ -17,6 +17,10 @@ class RegenerateSslCertJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 3;
public $backoff = 60;
public function __construct( public function __construct(
protected ?Team $team = null, protected ?Team $team = null,
protected ?int $server_id = null, protected ?int $server_id = null,
@@ -37,17 +41,13 @@ class RegenerateSslCertJob implements ShouldQueue
$query->where('is_ca_certificate', false); $query->where('is_ca_certificate', false);
$certificates = $query->get();
if ($certificates->isEmpty()) {
return;
}
$regenerated = collect(); $regenerated = collect();
foreach ($certificates as $certificate) { $query->cursor()->each(function ($certificate) use ($regenerated) {
try { try {
$caCert = SslCertificate::where('server_id', $certificate->server_id)->where('is_ca_certificate', true)->first(); $caCert = SslCertificate::where('server_id', $certificate->server_id)
->where('is_ca_certificate', true)
->first();
SSLHelper::generateSslCertificate( SSLHelper::generateSslCertificate(
commonName: $certificate->common_name, commonName: $certificate->common_name,
@@ -64,7 +64,7 @@ class RegenerateSslCertJob implements ShouldQueue
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Failed to regenerate SSL certificate: '.$e->getMessage()); Log::error('Failed to regenerate SSL certificate: '.$e->getMessage());
} }
} });
if ($regenerated->isNotEmpty()) { if ($regenerated->isNotEmpty()) {
$this->team?->notify(new SslExpirationNotification($regenerated)); $this->team?->notify(new SslExpirationNotification($regenerated));

View File

@@ -8,6 +8,7 @@ use App\Helpers\SslHelper;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use App\Models\StandaloneDragonfly; use App\Models\StandaloneDragonfly;
use Carbon\Carbon;
use Exception; use Exception;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
@@ -52,7 +53,7 @@ class General extends Component
#[Validate(['nullable', 'boolean'])] #[Validate(['nullable', 'boolean'])]
public bool $isLogDrainEnabled = false; public bool $isLogDrainEnabled = false;
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
#[Validate(['nullable', 'boolean'])] #[Validate(['nullable', 'boolean'])]
public bool $enable_ssl = false; public bool $enable_ssl = false;
@@ -72,9 +73,7 @@ class General extends Component
$this->syncData(); $this->syncData();
$this->server = data_get($this->database, 'destination.server'); $this->server = data_get($this->database, 'destination.server');
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if ($existingCert) { if ($existingCert) {
$this->certificateValidUntil = $existingCert->valid_until; $this->certificateValidUntil = $existingCert->valid_until;
@@ -205,10 +204,7 @@ class General extends Component
public function regenerateSslCertificate() public function regenerateSslCertificate()
{ {
try { try {
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->where('server_id', $this->server->id)
->first();
if (! $existingCert) { if (! $existingCert) {
$this->dispatch('error', 'No existing SSL certificate found for this database.'); $this->dispatch('error', 'No existing SSL certificate found for this database.');

View File

@@ -8,6 +8,7 @@ use App\Helpers\SslHelper;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use App\Models\StandaloneKeydb; use App\Models\StandaloneKeydb;
use Carbon\Carbon;
use Exception; use Exception;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
@@ -55,7 +56,7 @@ class General extends Component
#[Validate(['nullable', 'boolean'])] #[Validate(['nullable', 'boolean'])]
public bool $isLogDrainEnabled = false; public bool $isLogDrainEnabled = false;
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
#[Validate(['boolean'])] #[Validate(['boolean'])]
public bool $enable_ssl = false; public bool $enable_ssl = false;
@@ -75,9 +76,7 @@ class General extends Component
$this->syncData(); $this->syncData();
$this->server = data_get($this->database, 'destination.server'); $this->server = data_get($this->database, 'destination.server');
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if ($existingCert) { if ($existingCert) {
$this->certificateValidUntil = $existingCert->valid_until; $this->certificateValidUntil = $existingCert->valid_until;
@@ -210,10 +209,7 @@ class General extends Component
public function regenerateSslCertificate() public function regenerateSslCertificate()
{ {
try { try {
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->where('server_id', $this->server->id)
->first();
if (! $existingCert) { if (! $existingCert) {
$this->dispatch('error', 'No existing SSL certificate found for this database.'); $this->dispatch('error', 'No existing SSL certificate found for this database.');

View File

@@ -8,6 +8,7 @@ use App\Helpers\SslHelper;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use App\Models\StandaloneMariadb; use App\Models\StandaloneMariadb;
use Carbon\Carbon;
use Exception; use Exception;
use Livewire\Component; use Livewire\Component;
@@ -23,7 +24,7 @@ class General extends Component
public ?string $db_url_public = null; public ?string $db_url_public = null;
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
protected $rules = [ protected $rules = [
'database.name' => 'required', 'database.name' => 'required',
@@ -64,9 +65,7 @@ class General extends Component
$this->db_url_public = $this->database->external_db_url; $this->db_url_public = $this->database->external_db_url;
$this->server = data_get($this->database, 'destination.server'); $this->server = data_get($this->database, 'destination.server');
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if ($existingCert) { if ($existingCert) {
$this->certificateValidUntil = $existingCert->valid_until; $this->certificateValidUntil = $existingCert->valid_until;
@@ -155,10 +154,7 @@ class General extends Component
public function regenerateSslCertificate() public function regenerateSslCertificate()
{ {
try { try {
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->where('server_id', $this->server->id)
->first();
if (! $existingCert) { if (! $existingCert) {
$this->dispatch('error', 'No existing SSL certificate found for this database.'); $this->dispatch('error', 'No existing SSL certificate found for this database.');

View File

@@ -8,6 +8,7 @@ use App\Helpers\SslHelper;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use App\Models\StandaloneMongodb; use App\Models\StandaloneMongodb;
use Carbon\Carbon;
use Exception; use Exception;
use Livewire\Component; use Livewire\Component;
@@ -23,7 +24,7 @@ class General extends Component
public ?string $db_url_public = null; public ?string $db_url_public = null;
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
protected $rules = [ protected $rules = [
'database.name' => 'required', 'database.name' => 'required',
@@ -64,9 +65,7 @@ class General extends Component
$this->db_url_public = $this->database->external_db_url; $this->db_url_public = $this->database->external_db_url;
$this->server = data_get($this->database, 'destination.server'); $this->server = data_get($this->database, 'destination.server');
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if ($existingCert) { if ($existingCert) {
$this->certificateValidUntil = $existingCert->valid_until; $this->certificateValidUntil = $existingCert->valid_until;
@@ -159,10 +158,7 @@ class General extends Component
public function regenerateSslCertificate() public function regenerateSslCertificate()
{ {
try { try {
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->where('server_id', $this->server->id)
->first();
if (! $existingCert) { if (! $existingCert) {
$this->dispatch('error', 'No existing SSL certificate found for this database.'); $this->dispatch('error', 'No existing SSL certificate found for this database.');

View File

@@ -8,6 +8,7 @@ use App\Helpers\SslHelper;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use App\Models\StandaloneMysql; use App\Models\StandaloneMysql;
use Carbon\Carbon;
use Exception; use Exception;
use Livewire\Component; use Livewire\Component;
@@ -23,7 +24,7 @@ class General extends Component
public ?string $db_url_public = null; public ?string $db_url_public = null;
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
protected $rules = [ protected $rules = [
'database.name' => 'required', 'database.name' => 'required',
@@ -66,9 +67,7 @@ class General extends Component
$this->db_url_public = $this->database->external_db_url; $this->db_url_public = $this->database->external_db_url;
$this->server = data_get($this->database, 'destination.server'); $this->server = data_get($this->database, 'destination.server');
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if ($existingCert) { if ($existingCert) {
$this->certificateValidUntil = $existingCert->valid_until; $this->certificateValidUntil = $existingCert->valid_until;
@@ -158,10 +157,7 @@ class General extends Component
public function regenerateSslCertificate() public function regenerateSslCertificate()
{ {
try { try {
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->where('server_id', $this->server->id)
->first();
if (! $existingCert) { if (! $existingCert) {
$this->dispatch('error', 'No existing SSL certificate found for this database.'); $this->dispatch('error', 'No existing SSL certificate found for this database.');

View File

@@ -8,6 +8,7 @@ use App\Helpers\SslHelper;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use App\Models\StandalonePostgresql; use App\Models\StandalonePostgresql;
use Carbon\Carbon;
use Exception; use Exception;
use Livewire\Component; use Livewire\Component;
@@ -25,7 +26,7 @@ class General extends Component
public ?string $db_url_public = null; public ?string $db_url_public = null;
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
public function getListeners() public function getListeners()
{ {
@@ -81,9 +82,7 @@ class General extends Component
$this->db_url_public = $this->database->external_db_url; $this->db_url_public = $this->database->external_db_url;
$this->server = data_get($this->database, 'destination.server'); $this->server = data_get($this->database, 'destination.server');
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if ($existingCert) { if ($existingCert) {
$this->certificateValidUntil = $existingCert->valid_until; $this->certificateValidUntil = $existingCert->valid_until;
@@ -122,10 +121,7 @@ class General extends Component
public function regenerateSslCertificate() public function regenerateSslCertificate()
{ {
try { try {
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->where('server_id', $this->server->id)
->first();
if (! $existingCert) { if (! $existingCert) {
$this->dispatch('error', 'No existing SSL certificate found for this database.'); $this->dispatch('error', 'No existing SSL certificate found for this database.');

View File

@@ -8,6 +8,7 @@ use App\Helpers\SslHelper;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use App\Models\StandaloneRedis; use App\Models\StandaloneRedis;
use Carbon\Carbon;
use Exception; use Exception;
use Livewire\Component; use Livewire\Component;
@@ -32,7 +33,7 @@ class General extends Component
public ?string $db_url_public = null; public ?string $db_url_public = null;
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
protected $rules = [ protected $rules = [
'database.name' => 'required', 'database.name' => 'required',
@@ -67,9 +68,7 @@ class General extends Component
{ {
$this->server = data_get($this->database, 'destination.server'); $this->server = data_get($this->database, 'destination.server');
$this->refreshView(); $this->refreshView();
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->first();
if ($existingCert) { if ($existingCert) {
$this->certificateValidUntil = $existingCert->valid_until; $this->certificateValidUntil = $existingCert->valid_until;
@@ -163,10 +162,7 @@ class General extends Component
public function regenerateSslCertificate() public function regenerateSslCertificate()
{ {
try { try {
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass()) $existingCert = $this->database->sslCertificates()->first();
->where('resource_id', $this->database->id)
->where('server_id', $this->server->id)
->first();
if (! $existingCert) { if (! $existingCert) {
$this->dispatch('error', 'No existing SSL certificate found for this database.'); $this->dispatch('error', 'No existing SSL certificate found for this database.');

View File

@@ -6,6 +6,7 @@ use App\Helpers\SslHelper;
use App\Jobs\RegenerateSslCertJob; use App\Jobs\RegenerateSslCertJob;
use App\Models\Server; use App\Models\Server;
use App\Models\SslCertificate; use App\Models\SslCertificate;
use Carbon\Carbon;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
use Livewire\Component; use Livewire\Component;
@@ -19,7 +20,7 @@ class Advanced extends Component
public $certificateContent = ''; public $certificateContent = '';
public $certificateValidUntil = null; public ?Carbon $certificateValidUntil = null;
public array $parameters = []; public array $parameters = [];
@@ -99,7 +100,7 @@ class Advanced extends Component
commonName: 'Coolify CA Certificate', commonName: 'Coolify CA Certificate',
serverId: $this->server->id, serverId: $this->server->id,
isCaCertificate: true, isCaCertificate: true,
validityDays: 15 * 365 validityDays: 10 * 365
); );
$this->loadCaCertificate(); $this->loadCaCertificate();

View File

@@ -223,7 +223,12 @@ class StandaloneClickhouse extends BaseModel
protected function internalDbUrl(): Attribute protected function internalDbUrl(): Attribute
{ {
return new Attribute( return new Attribute(
get: fn () => "clickhouse://{$this->clickhouse_admin_user}:{$this->clickhouse_admin_password}@{$this->uuid}:9000/{$this->clickhouse_db}", get: function () {
$encodedUser = rawurlencode($this->clickhouse_admin_user);
$encodedPass = rawurlencode($this->clickhouse_admin_password);
return "clickhouse://{$encodedUser}:{$encodedPass}@{$this->uuid}:9000/{$this->clickhouse_db}";
},
); );
} }
@@ -232,7 +237,10 @@ class StandaloneClickhouse extends BaseModel
return new Attribute( return new Attribute(
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
return "clickhouse://{$this->clickhouse_admin_user}:{$this->clickhouse_admin_password}@{$this->destination->server->getIp}:{$this->public_port}/{$this->clickhouse_db}"; $encodedUser = rawurlencode($this->clickhouse_admin_user);
$encodedPass = rawurlencode($this->clickhouse_admin_password);
return "clickhouse://{$encodedUser}:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/{$this->clickhouse_db}";
} }
return null; return null;

View File

@@ -226,7 +226,8 @@ class StandaloneDragonfly extends BaseModel
get: function () { get: function () {
$scheme = $this->enable_ssl ? 'rediss' : 'redis'; $scheme = $this->enable_ssl ? 'rediss' : 'redis';
$port = $this->enable_ssl ? 6380 : 6379; $port = $this->enable_ssl ? 6380 : 6379;
$url = "{$scheme}://:{$this->dragonfly_password}@{$this->uuid}:{$port}/0"; $encodedPass = rawurlencode($this->dragonfly_password);
$url = "{$scheme}://:{$encodedPass}@{$this->uuid}:{$port}/0";
if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') { if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') {
$url .= '?cacert=/etc/ssl/certs/coolify-ca.crt'; $url .= '?cacert=/etc/ssl/certs/coolify-ca.crt';
@@ -243,7 +244,8 @@ class StandaloneDragonfly extends BaseModel
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
$scheme = $this->enable_ssl ? 'rediss' : 'redis'; $scheme = $this->enable_ssl ? 'rediss' : 'redis';
$url = "{$scheme}://:{$this->dragonfly_password}@{$this->destination->server->getIp}:{$this->public_port}/0"; $encodedPass = rawurlencode($this->dragonfly_password);
$url = "{$scheme}://:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/0";
if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') { if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') {
$url .= '?cacert=/etc/ssl/certs/coolify-ca.crt'; $url .= '?cacert=/etc/ssl/certs/coolify-ca.crt';

View File

@@ -226,7 +226,8 @@ class StandaloneKeydb extends BaseModel
get: function () { get: function () {
$scheme = $this->enable_ssl ? 'rediss' : 'redis'; $scheme = $this->enable_ssl ? 'rediss' : 'redis';
$port = $this->enable_ssl ? 6380 : 6379; $port = $this->enable_ssl ? 6380 : 6379;
$url = "{$scheme}://:{$this->keydb_password}@{$this->uuid}:{$port}/0"; $encodedPass = rawurlencode($this->keydb_password);
$url = "{$scheme}://:{$encodedPass}@{$this->uuid}:{$port}/0";
if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') { if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') {
$url .= '?cacert=/etc/ssl/certs/coolify-ca.crt'; $url .= '?cacert=/etc/ssl/certs/coolify-ca.crt';
@@ -243,7 +244,8 @@ class StandaloneKeydb extends BaseModel
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
$scheme = $this->enable_ssl ? 'rediss' : 'redis'; $scheme = $this->enable_ssl ? 'rediss' : 'redis';
$url = "{$scheme}://:{$this->keydb_password}@{$this->destination->server->getIp}:{$this->public_port}/0"; $encodedPass = rawurlencode($this->keydb_password);
$url = "{$scheme}://:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/0";
if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') { if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') {
$url .= '?cacert=/etc/ssl/certs/coolify-ca.crt'; $url .= '?cacert=/etc/ssl/certs/coolify-ca.crt';

View File

@@ -218,7 +218,12 @@ class StandaloneMariadb extends BaseModel
protected function internalDbUrl(): Attribute protected function internalDbUrl(): Attribute
{ {
return new Attribute( return new Attribute(
get: fn () => "mysql://{$this->mariadb_user}:{$this->mariadb_password}@{$this->uuid}:3306/{$this->mariadb_database}", get: function () {
$encodedUser = rawurlencode($this->mariadb_user);
$encodedPass = rawurlencode($this->mariadb_password);
return "mysql://{$encodedUser}:{$encodedPass}@{$this->uuid}:3306/{$this->mariadb_database}";
},
); );
} }
@@ -227,7 +232,10 @@ class StandaloneMariadb extends BaseModel
return new Attribute( return new Attribute(
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
return "mysql://{$this->mariadb_user}:{$this->mariadb_password}@{$this->destination->server->getIp}:{$this->public_port}/{$this->mariadb_database}"; $encodedUser = rawurlencode($this->mariadb_user);
$encodedPass = rawurlencode($this->mariadb_password);
return "mysql://{$encodedUser}:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/{$this->mariadb_database}";
} }
return null; return null;

View File

@@ -244,13 +244,14 @@ class StandaloneMongodb extends BaseModel
{ {
return new Attribute( return new Attribute(
get: function () { get: function () {
$url = "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->uuid}:27017/?directConnection=true"; $encodedUser = rawurlencode($this->mongo_initdb_root_username);
$encodedPass = rawurlencode($this->mongo_initdb_root_password);
$url = "mongodb://{$encodedUser}:{$encodedPass}@{$this->uuid}:27017/?directConnection=true";
if ($this->enable_ssl) { if ($this->enable_ssl) {
$url .= '&tls=true'; $url .= '&tls=true';
if (in_array($this->ssl_mode, ['verify-full'])) { if (in_array($this->ssl_mode, ['verify-full'])) {
$url .= '&tlsCAFile=/etc/ssl/certs/coolify-ca.crt'; $url .= '&tlsCAFile=/etc/ssl/certs/coolify-ca.crt';
} }
} }
return $url; return $url;
@@ -263,7 +264,9 @@ class StandaloneMongodb extends BaseModel
return new Attribute( return new Attribute(
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
$url = "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true"; $encodedUser = rawurlencode($this->mongo_initdb_root_username);
$encodedPass = rawurlencode($this->mongo_initdb_root_password);
$url = "mongodb://{$encodedUser}:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true";
if ($this->enable_ssl) { if ($this->enable_ssl) {
$url .= '&tls=true'; $url .= '&tls=true';
if (in_array($this->ssl_mode, ['verify-full'])) { if (in_array($this->ssl_mode, ['verify-full'])) {

View File

@@ -225,7 +225,9 @@ class StandaloneMysql extends BaseModel
{ {
return new Attribute( return new Attribute(
get: function () { get: function () {
$url = "mysql://{$this->mysql_user}:{$this->mysql_password}@{$this->uuid}:3306/{$this->mysql_database}"; $encodedUser = rawurlencode($this->mysql_user);
$encodedPass = rawurlencode($this->mysql_password);
$url = "mysql://{$encodedUser}:{$encodedPass}@{$this->uuid}:3306/{$this->mysql_database}";
if ($this->enable_ssl) { if ($this->enable_ssl) {
$url .= "?ssl-mode={$this->ssl_mode}"; $url .= "?ssl-mode={$this->ssl_mode}";
if (in_array($this->ssl_mode, ['VERIFY_CA', 'VERIFY_IDENTITY'])) { if (in_array($this->ssl_mode, ['VERIFY_CA', 'VERIFY_IDENTITY'])) {
@@ -243,7 +245,9 @@ class StandaloneMysql extends BaseModel
return new Attribute( return new Attribute(
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
$url = "mysql://{$this->mysql_user}:{$this->mysql_password}@{$this->destination->server->getIp}:{$this->public_port}/{$this->mysql_database}"; $encodedUser = rawurlencode($this->mysql_user);
$encodedPass = rawurlencode($this->mysql_password);
$url = "mysql://{$encodedUser}:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/{$this->mysql_database}";
if ($this->enable_ssl) { if ($this->enable_ssl) {
$url .= "?ssl-mode={$this->ssl_mode}"; $url .= "?ssl-mode={$this->ssl_mode}";
if (in_array($this->ssl_mode, ['VERIFY_CA', 'VERIFY_IDENTITY'])) { if (in_array($this->ssl_mode, ['VERIFY_CA', 'VERIFY_IDENTITY'])) {

View File

@@ -220,7 +220,9 @@ class StandalonePostgresql extends BaseModel
{ {
return new Attribute( return new Attribute(
get: function () { get: function () {
$url = "postgres://{$this->postgres_user}:{$this->postgres_password}@{$this->uuid}:5432/{$this->postgres_db}"; $encodedUser = rawurlencode($this->postgres_user);
$encodedPass = rawurlencode($this->postgres_password);
$url = "postgres://{$encodedUser}:{$encodedPass}@{$this->uuid}:5432/{$this->postgres_db}";
if ($this->enable_ssl) { if ($this->enable_ssl) {
$url .= "?sslmode={$this->ssl_mode}"; $url .= "?sslmode={$this->ssl_mode}";
if (in_array($this->ssl_mode, ['verify-ca', 'verify-full'])) { if (in_array($this->ssl_mode, ['verify-ca', 'verify-full'])) {
@@ -238,7 +240,9 @@ class StandalonePostgresql extends BaseModel
return new Attribute( return new Attribute(
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
$url = "postgres://{$this->postgres_user}:{$this->postgres_password}@{$this->destination->server->getIp}:{$this->public_port}/{$this->postgres_db}"; $encodedUser = rawurlencode($this->postgres_user);
$encodedPass = rawurlencode($this->postgres_password);
$url = "postgres://{$encodedUser}:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/{$this->postgres_db}";
if ($this->enable_ssl) { if ($this->enable_ssl) {
$url .= "?sslmode={$this->ssl_mode}"; $url .= "?sslmode={$this->ssl_mode}";
if (in_array($this->ssl_mode, ['verify-ca', 'verify-full'])) { if (in_array($this->ssl_mode, ['verify-ca', 'verify-full'])) {

View File

@@ -221,10 +221,11 @@ class StandaloneRedis extends BaseModel
return new Attribute( return new Attribute(
get: function () { get: function () {
$redis_version = $this->getRedisVersion(); $redis_version = $this->getRedisVersion();
$username_part = version_compare($redis_version, '6.0', '>=') ? "{$this->redis_username}:" : ''; $username_part = version_compare($redis_version, '6.0', '>=') ? rawurlencode($this->redis_username).':' : '';
$encodedPass = rawurlencode($this->redis_password);
$scheme = $this->enable_ssl ? 'rediss' : 'redis'; $scheme = $this->enable_ssl ? 'rediss' : 'redis';
$port = $this->enable_ssl ? 6380 : 6379; $port = $this->enable_ssl ? 6380 : 6379;
$url = "{$scheme}://{$username_part}{$this->redis_password}@{$this->uuid}:{$port}/0"; $url = "{$scheme}://{$username_part}{$encodedPass}@{$this->uuid}:{$port}/0";
if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') { if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') {
$url .= '?cacert=/etc/ssl/certs/coolify-ca.crt'; $url .= '?cacert=/etc/ssl/certs/coolify-ca.crt';
@@ -241,9 +242,10 @@ class StandaloneRedis extends BaseModel
get: function () { get: function () {
if ($this->is_public && $this->public_port) { if ($this->is_public && $this->public_port) {
$redis_version = $this->getRedisVersion(); $redis_version = $this->getRedisVersion();
$username_part = version_compare($redis_version, '6.0', '>=') ? "{$this->redis_username}:" : ''; $username_part = version_compare($redis_version, '6.0', '>=') ? rawurlencode($this->redis_username).':' : '';
$encodedPass = rawurlencode($this->redis_password);
$scheme = $this->enable_ssl ? 'rediss' : 'redis'; $scheme = $this->enable_ssl ? 'rediss' : 'redis';
$url = "{$scheme}://{$username_part}{$this->redis_password}@{$this->destination->server->getIp}:{$this->public_port}/0"; $url = "{$scheme}://{$username_part}{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/0";
if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') { if ($this->enable_ssl && $this->ssl_mode === 'verify-ca') {
$url .= '?cacert=/etc/ssl/certs/coolify-ca.crt'; $url .= '?cacert=/etc/ssl/certs/coolify-ca.crt';

View File

@@ -19,18 +19,21 @@ return new class extends Migration
}); });
if (DB::table('local_file_volumes')->exists()) { if (DB::table('local_file_volumes')->exists()) {
$volumes = DB::table('local_file_volumes')->get(); DB::table('local_file_volumes')
foreach ($volumes as $volume) { ->orderBy('id')
try { ->chunk(100, function ($volumes) {
DB::table('local_file_volumes')->where('id', $volume->id)->update([ foreach ($volumes as $volume) {
'fs_path' => $volume->fs_path ? Crypt::encryptString($volume->fs_path) : null, try {
'mount_path' => $volume->mount_path ? Crypt::encryptString($volume->mount_path) : null, DB::table('local_file_volumes')->where('id', $volume->id)->update([
'content' => $volume->content ? Crypt::encryptString($volume->content) : null, 'fs_path' => $volume->fs_path ? Crypt::encryptString($volume->fs_path) : null,
]); 'mount_path' => $volume->mount_path ? Crypt::encryptString($volume->mount_path) : null,
} catch (\Exception $e) { 'content' => $volume->content ? Crypt::encryptString($volume->content) : null,
Log::error('Error encrypting local file volume fields: '.$e->getMessage()); ]);
} } catch (\Exception $e) {
} Log::error('Error encrypting local file volume fields: '.$e->getMessage());
}
}
});
} }
} }
@@ -46,18 +49,21 @@ return new class extends Migration
}); });
if (DB::table('local_file_volumes')->exists()) { if (DB::table('local_file_volumes')->exists()) {
$volumes = DB::table('local_file_volumes')->get(); DB::table('local_file_volumes')
foreach ($volumes as $volume) { ->orderBy('id')
try { ->chunk(100, function ($volumes) {
DB::table('local_file_volumes')->where('id', $volume->id)->update([ foreach ($volumes as $volume) {
'fs_path' => $volume->fs_path ? Crypt::decryptString($volume->fs_path) : null, try {
'mount_path' => $volume->mount_path ? Crypt::decryptString($volume->mount_path) : null, DB::table('local_file_volumes')->where('id', $volume->id)->update([
'content' => $volume->content ? Crypt::decryptString($volume->content) : null, 'fs_path' => $volume->fs_path ? Crypt::decryptString($volume->fs_path) : null,
]); 'mount_path' => $volume->mount_path ? Crypt::decryptString($volume->mount_path) : null,
} catch (\Exception $e) { 'content' => $volume->content ? Crypt::decryptString($volume->content) : null,
Log::error('Error decrypting local file volume fields: '.$e->getMessage()); ]);
} } catch (\Exception $e) {
} Log::error('Error decrypting local file volume fields: '.$e->getMessage());
}
}
});
} }
} }
}; };

View File

@@ -20,7 +20,7 @@ class CaSslCertSeeder extends Seeder
commonName: 'Coolify CA Certificate', commonName: 'Coolify CA Certificate',
serverId: $server->id, serverId: $server->id,
isCaCertificate: true, isCaCertificate: true,
validityDays: 15 * 365 validityDays: 10 * 365
); );
} else { } else {
$caCert = $existingCaCert; $caCert = $existingCaCert;