From 50fcb2c3e77948c3c983c3818f55612a1b5e9184 Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Mon, 2 Sep 2024 10:20:31 +0000 Subject: [PATCH] Show error message when vaas cannot actually connect --- Vaas/ScanClient.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Vaas/ScanClient.php b/Vaas/ScanClient.php index c2fa6c7..15b920d 100644 --- a/Vaas/ScanClient.php +++ b/Vaas/ScanClient.php @@ -3,6 +3,7 @@ namespace Gdatacyberdefenseag\GdataAntivirus\Vaas; use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem\IGdataAntivirusFileSystem; +use Gdatacyberdefenseag\GdataAntivirus\PluginPage\AdminNotices; use Psr\Log\LoggerInterface; use VaasSdk\Vaas; use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator; @@ -16,14 +17,27 @@ class ScanClient { private LoggerInterface $logger; private VaasOptions $vaas_options; private IGdataAntivirusFileSystem $file_system; - - public function __construct( LoggerInterface $logger, VaasOptions $vaas_options, IGdataAntivirusFileSystem $file_system ) { + private AdminNotices $admin_notices; + + public function __construct( + LoggerInterface $logger, + VaasOptions $vaas_options, + IGdataAntivirusFileSystem $file_system, + AdminNotices $admin_notices + ) { $logger->info('ScanClient::__construct'); $this->logger = $logger; $this->vaas_options = $vaas_options; $this->file_system = $file_system; + $this->admin_notices = $admin_notices; - $this->Connect(); + try { + $this->Connect(); + } catch (\Exception $e) { + $this->admin_notices->add_notice($e->getMessage()); + $this->logger->error("VaaS connection failed. Please verify if the VaaS-Url is correct."); + return; + } $plugin_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false); $media_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', false); // We don't need to add the filters if both plugin and media upload scan are disabled.