From 28de478801a35ebf26ce5073e2a3334386bee4db Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 13 Dec 2024 10:55:17 +0100 Subject: [PATCH 1/6] version++ --- config/constants.php | 2 +- other/nightly/versions.json | 4 ++-- versions.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/constants.php b/config/constants.php index a02d6616a..8c6c12da4 100644 --- a/config/constants.php +++ b/config/constants.php @@ -2,7 +2,7 @@ return [ 'coolify' => [ - 'version' => '4.0.0-beta.377', + 'version' => '4.0.0-beta.378', 'self_hosted' => env('SELF_HOSTED', true), 'autoupdate' => env('AUTOUPDATE'), 'base_config_path' => env('BASE_CONFIG_PATH', '/data/coolify'), diff --git a/other/nightly/versions.json b/other/nightly/versions.json index 2d1633ed6..2d96743f4 100644 --- a/other/nightly/versions.json +++ b/other/nightly/versions.json @@ -1,10 +1,10 @@ { "coolify": { "v4": { - "version": "4.0.0-beta.376" + "version": "4.0.0-beta.378" }, "nightly": { - "version": "4.0.0-beta.377" + "version": "4.0.0-beta.379" }, "helper": { "version": "1.0.4" diff --git a/versions.json b/versions.json index b6f301ebc..2d96743f4 100644 --- a/versions.json +++ b/versions.json @@ -1,10 +1,10 @@ { "coolify": { "v4": { - "version": "4.0.0-beta.377" + "version": "4.0.0-beta.378" }, "nightly": { - "version": "4.0.0-beta.378" + "version": "4.0.0-beta.379" }, "helper": { "version": "1.0.4" From 5087906b24eb3d4ac1fdb7204c2163198dacf38e Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:35:44 +0100 Subject: [PATCH 2/6] fix: encrypt resend API key in instance settings --- ...pt_resend_api_key_in_instance_settings.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php diff --git a/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php b/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php new file mode 100644 index 000000000..33e18e25a --- /dev/null +++ b/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php @@ -0,0 +1,56 @@ +exists()) { + Schema::table('instance_settings', function (Blueprint $table) { + $table->text('resend_api_key')->nullable()->change(); + }); + + $settings = DB::table('instance_settings')->get(); + foreach ($settings as $setting) { + try { + DB::table('instance_settings')->where('id', $setting->id)->update([ + 'resend_api_key' => $setting->resend_api_key ? Crypt::encryptString($setting->resend_api_key) : null, + ]); + } catch (Exception $e) { + \Log::error('Error encrypting resend_api_key: '.$e->getMessage()); + } + } + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('instance_settings', function (Blueprint $table) { + $table->text('resend_api_key')->nullable()->change(); + }); + + if (DB::table('instance_settings')->exists()) { + $settings = DB::table('instance_settings')->get(); + foreach ($settings as $setting) { + try { + DB::table('instance_settings')->where('id', $setting->id)->update([ + 'resend_api_key' => $setting->resend_api_key ? Crypt::decryptString($setting->resend_api_key) : null, + ]); + } catch (Exception $e) { + \Log::error('Error decrypting resend_api_key: '.$e->getMessage()); + } + } + } + } +}; From a16cbdf55762463455379292eaf97e2924ddc0a2 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:42:01 +0100 Subject: [PATCH 3/6] fix: resend api key is already a text column --- ...007_encrypt_resend_api_key_in_instance_settings.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php b/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php index 33e18e25a..ab9b3416a 100644 --- a/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php +++ b/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php @@ -1,10 +1,8 @@ exists()) { - Schema::table('instance_settings', function (Blueprint $table) { - $table->text('resend_api_key')->nullable()->change(); - }); - $settings = DB::table('instance_settings')->get(); foreach ($settings as $setting) { try { @@ -36,10 +30,6 @@ return new class extends Migration */ public function down(): void { - Schema::table('instance_settings', function (Blueprint $table) { - $table->text('resend_api_key')->nullable()->change(); - }); - if (DB::table('instance_settings')->exists()) { $settings = DB::table('instance_settings')->get(); foreach ($settings as $setting) { From 4901b1227939ba0d1fe104c64c122241a4ef3bbe Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 13 Dec 2024 12:03:05 +0100 Subject: [PATCH 4/6] fix: service status indicator + oauth saving --- app/Console/Kernel.php | 2 +- .../Controllers/Api/ResourcesController.php | 6 +----- .../Controllers/Api/ServersController.php | 12 ++--------- .../Controllers/Api/ServicesController.php | 4 ++-- app/Livewire/Project/Service/Navbar.php | 2 +- app/Livewire/SettingsOauth.php | 20 ++++++++++++++----- app/Models/OauthSetting.php | 14 +++++++++++++ app/Models/Service.php | 8 ++++---- app/View/Components/Status/Services.php | 2 +- .../livewire/project/service/navbar.blade.php | 9 ++++----- .../views/livewire/settings-oauth.blade.php | 4 ++-- 11 files changed, 47 insertions(+), 36 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 19d22ae21..2ed3ee454 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -218,7 +218,7 @@ class Kernel extends ConsoleKernel } } if ($service) { - if (str($service->status())->contains('running') === false) { + if (str($service->status)->contains('running') === false) { continue; } } diff --git a/app/Http/Controllers/Api/ResourcesController.php b/app/Http/Controllers/Api/ResourcesController.php index 4180cef9a..ad12c83ab 100644 --- a/app/Http/Controllers/Api/ResourcesController.php +++ b/app/Http/Controllers/Api/ResourcesController.php @@ -53,11 +53,7 @@ class ResourcesController extends Controller $resources = $resources->flatten(); $resources = $resources->map(function ($resource) { $payload = $resource->toArray(); - if ($resource->getMorphClass() === \App\Models\Service::class) { - $payload['status'] = $resource->status(); - } else { - $payload['status'] = $resource->status; - } + $payload['status'] = $resource->status; $payload['type'] = $resource->type(); return $payload; diff --git a/app/Http/Controllers/Api/ServersController.php b/app/Http/Controllers/Api/ServersController.php index f37040bdd..b1deb5321 100644 --- a/app/Http/Controllers/Api/ServersController.php +++ b/app/Http/Controllers/Api/ServersController.php @@ -154,11 +154,7 @@ class ServersController extends Controller 'created_at' => $resource->created_at, 'updated_at' => $resource->updated_at, ]; - if ($resource->type() === 'service') { - $payload['status'] = $resource->status(); - } else { - $payload['status'] = $resource->status; - } + $payload['status'] = $resource->status; return $payload; }); @@ -237,11 +233,7 @@ class ServersController extends Controller 'created_at' => $resource->created_at, 'updated_at' => $resource->updated_at, ]; - if ($resource->type() === 'service') { - $payload['status'] = $resource->status(); - } else { - $payload['status'] = $resource->status; - } + $payload['status'] = $resource->status; return $payload; }); diff --git a/app/Http/Controllers/Api/ServicesController.php b/app/Http/Controllers/Api/ServicesController.php index ed9af8c90..bcaba7107 100644 --- a/app/Http/Controllers/Api/ServicesController.php +++ b/app/Http/Controllers/Api/ServicesController.php @@ -1072,7 +1072,7 @@ class ServicesController extends Controller if (! $service) { return response()->json(['message' => 'Service not found.'], 404); } - if (str($service->status())->contains('running')) { + if (str($service->status)->contains('running')) { return response()->json(['message' => 'Service is already running.'], 400); } StartService::dispatch($service); @@ -1150,7 +1150,7 @@ class ServicesController extends Controller if (! $service) { return response()->json(['message' => 'Service not found.'], 404); } - if (str($service->status())->contains('stopped') || str($service->status())->contains('exited')) { + if (str($service->status)->contains('stopped') || str($service->status)->contains('exited')) { return response()->json(['message' => 'Service is already stopped.'], 400); } StopService::dispatch($service); diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php index ee43dc911..22fc1c0d6 100644 --- a/app/Livewire/Project/Service/Navbar.php +++ b/app/Livewire/Project/Service/Navbar.php @@ -27,7 +27,7 @@ class Navbar extends Component public function mount() { - if (str($this->service->status())->contains('running') && is_null($this->service->config_hash)) { + if (str($this->service->status)->contains('running') && is_null($this->service->config_hash)) { $this->service->isConfigurationChanged(true); $this->dispatch('configurationChanged'); } diff --git a/app/Livewire/SettingsOauth.php b/app/Livewire/SettingsOauth.php index d5f0be14a..857de1df8 100644 --- a/app/Livewire/SettingsOauth.php +++ b/app/Livewire/SettingsOauth.php @@ -35,16 +35,26 @@ class SettingsOauth extends Component }, []); } - private function updateOauthSettings() + private function updateOauthSettings(?string $provider = null) { - foreach (array_values($this->oauth_settings_map) as &$setting) { - $setting->save(); + if ($provider) { + $oauth = $this->oauth_settings_map[$provider]; + if (! $oauth->couldBeEnabled()) { + $oauth->update(['enabled' => false]); + throw new \Exception('OAuth settings are not complete for '.$oauth->provider.'.
Please fill in all required fields.'); + } + $oauth->save(); + $this->dispatch('success', 'OAuth settings for '.$oauth->provider.' updated successfully!'); } } - public function instantSave() + public function instantSave(string $provider) { - $this->updateOauthSettings(); + try { + $this->updateOauthSettings($provider); + } catch (\Exception $e) { + return handleError($e, $this); + } } public function submit() diff --git a/app/Models/OauthSetting.php b/app/Models/OauthSetting.php index c17c318f1..3d82e89f2 100644 --- a/app/Models/OauthSetting.php +++ b/app/Models/OauthSetting.php @@ -11,6 +11,8 @@ class OauthSetting extends Model { use HasFactory; + protected $fillable = ['provider', 'client_id', 'client_secret', 'redirect_uri', 'tenant', 'base_url', 'enabled']; + protected function clientSecret(): Attribute { return Attribute::make( @@ -18,4 +20,16 @@ class OauthSetting extends Model set: fn (?string $value) => empty($value) ? null : Crypt::encryptString($value), ); } + + public function couldBeEnabled(): bool + { + switch ($this->provider) { + case 'azure': + return filled($this->client_id) && filled($this->client_secret) && filled($this->redirect_uri) && filled($this->tenant); + case 'authentik': + return filled($this->client_id) && filled($this->client_secret) && filled($this->redirect_uri) && filled($this->base_url); + default: + return filled($this->client_id) && filled($this->client_secret) && filled($this->redirect_uri); + } + } } diff --git a/app/Models/Service.php b/app/Models/Service.php index 117677d53..5a2690490 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -46,7 +46,7 @@ class Service extends BaseModel protected $guarded = []; - protected $appends = ['server_status']; + protected $appends = ['server_status', 'status']; protected static function booted() { @@ -105,12 +105,12 @@ class Service extends BaseModel public function isRunning() { - return (bool) str($this->status())->contains('running'); + return (bool) str($this->status)->contains('running'); } public function isExited() { - return (bool) str($this->status())->contains('exited'); + return (bool) str($this->status)->contains('exited'); } public function type() @@ -213,7 +213,7 @@ class Service extends BaseModel instant_remote_process(["docker network rm {$uuid}"], $server, false); } - public function status() + public function getStatusAttribute() { $applications = $this->applications; $databases = $this->databases; diff --git a/app/View/Components/Status/Services.php b/app/View/Components/Status/Services.php index 70db62172..291841854 100644 --- a/app/View/Components/Status/Services.php +++ b/app/View/Components/Status/Services.php @@ -17,7 +17,7 @@ class Services extends Component public string $complexStatus = 'exited', public bool $showRefreshButton = true ) { - $this->complexStatus = $service->status(); + $this->complexStatus = $service->status; } /** diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php index 342c071d4..f268096f8 100644 --- a/resources/views/livewire/project/service/navbar.blade.php +++ b/resources/views/livewire/project/service/navbar.blade.php @@ -22,7 +22,7 @@ @if ($service->isDeployable)
- @if (str($service->status())->contains('running')) + @if (str($service->status)->contains('running')) Advanced @@ -70,7 +70,7 @@ Stop - @elseif (str($service->status())->contains('degraded')) + @elseif (str($service->status)->contains('degraded'))