From 165d35959e6c6c8f96ec5dbc947a971d6ed8ec02 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 4 Nov 2024 12:53:01 +0100 Subject: [PATCH] fix: logdrains validation --- app/Livewire/Server/LogDrains.php | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Server/LogDrains.php b/app/Livewire/Server/LogDrains.php index fb8ef329f..67a6962dc 100644 --- a/app/Livewire/Server/LogDrains.php +++ b/app/Livewire/Server/LogDrains.php @@ -52,7 +52,7 @@ class LogDrains extends Component public function syncData(bool $toModel = false) { if ($toModel) { - $this->validate(); + $this->customValidation(); $this->server->settings->is_logdrain_newrelic_enabled = $this->isLogDrainNewRelicEnabled; $this->server->settings->is_logdrain_axiom_enabled = $this->isLogDrainAxiomEnabled; $this->server->settings->is_logdrain_custom_enabled = $this->isLogDrainCustomEnabled; @@ -79,6 +79,44 @@ class LogDrains extends Component } } + public function customValidation() + { + if ($this->isLogDrainNewRelicEnabled) { + try { + $this->validate([ + 'logDrainNewRelicLicenseKey' => ['required'], + 'logDrainNewRelicBaseUri' => ['required', 'url'], + ]); + } catch (\Throwable $e) { + $this->isLogDrainNewRelicEnabled = false; + + throw $e; + } + } elseif ($this->isLogDrainAxiomEnabled) { + try { + $this->validate([ + 'logDrainAxiomDatasetName' => ['required'], + 'logDrainAxiomApiKey' => ['required'], + ]); + } catch (\Throwable $e) { + $this->isLogDrainAxiomEnabled = false; + + throw $e; + } + } elseif ($this->isLogDrainCustomEnabled) { + try { + $this->validate([ + 'logDrainCustomConfig' => ['required'], + 'logDrainCustomConfigParser' => ['string', 'nullable'], + ]); + } catch (\Throwable $e) { + $this->isLogDrainCustomEnabled = false; + + throw $e; + } + } + } + public function instantSave() { try {