From d231b97065075c1e31657bcd0a5fe2722e64d485 Mon Sep 17 00:00:00 2001 From: "Simonis, Matthias" Date: Wed, 12 Jun 2024 08:26:57 +0000 Subject: [PATCH] don't redefine the APP_ID in all files you can just import appinfo/application and use the static field there --- lib/Service/FileService.php | 6 +++--- lib/Service/VerdictService.php | 20 ++++++++++---------- lib/Settings/VaasAdmin.php | 34 +++++++++++++++++----------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 71a778da..2e002b7c 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -2,6 +2,7 @@ namespace OCA\GDataVaas\Service; +use OCA\GDataVaas\AppInfo\Application; use OCP\Files\Config\IUserMountCache; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; @@ -13,7 +14,6 @@ use Psr\Log\LoggerInterface; class FileService { - private const APP_ID = "gdatavaas"; private IUserMountCache $userMountCache; private IRootFolder $rootFolder; @@ -37,7 +37,7 @@ public function __construct(LoggerInterface $logger, IUserMountCache $userMountC * @throws LockedException */ public function setMaliciousPrefixIfActivated(int $fileId): void { - if ($this->appConfig->getAppValue(self::APP_ID, 'prefixMalicious')) { + if ($this->appConfig->getAppValue(Application::APP_ID, 'prefixMalicious')) { $file = $this->getNodeFromFileId($fileId); if (!str_starts_with($file->getName(), '[MALICIOUS] ')) { $newFileName = "[MALICIOUS] " . $file->getName(); @@ -85,7 +85,7 @@ private function findNodeInMount(\OCP\Files\Config\ICachedMountFileInfo $mount, * @throws NotPermittedException */ public function moveFileToQuarantineFolderIfDefined(int $fileId): void { - $quarantineFolderPath = $this->appConfig->getAppValue(self::APP_ID, 'quarantineFolder'); + $quarantineFolderPath = $this->appConfig->getAppValue(Application::APP_ID, 'quarantineFolder'); if (empty($quarantineFolderPath)) { throw new InvalidPathException('Quarantine folder path is not defined'); } diff --git a/lib/Service/VerdictService.php b/lib/Service/VerdictService.php index 874c33c7..fc87441a 100644 --- a/lib/Service/VerdictService.php +++ b/lib/Service/VerdictService.php @@ -3,6 +3,7 @@ namespace OCA\GDataVaas\Service; use Exception; +use OCA\GDataVaas\AppInfo\Application; use OCP\Files\EntityTooLargeException; use OCP\Files\InvalidPathException; use OCP\Files\NotFoundException; @@ -22,7 +23,6 @@ class VerdictService { public const MAX_FILE_SIZE = 268435456; - private const APP_ID = "gdatavaas"; private string $username; private string $password; @@ -44,13 +44,13 @@ public function __construct(LoggerInterface $logger, IConfig $appConfig, FileSer $this->fileService = $fileService; $this->tagService = $tagService; - $this->authMethod = $this->appConfig->getAppValue(self::APP_ID, 'authMethod', 'ClientCredentials'); - $this->tokenEndpoint = $this->appConfig->getAppValue(self::APP_ID, 'tokenEndpoint', 'https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token'); - $this->vaasUrl = $this->appConfig->getAppValue(self::APP_ID, 'vaasUrl', 'wss://gateway.staging.vaas.gdatasecurity.de'); - $this->clientId = $this->appConfig->getAppValue(self::APP_ID, 'clientId'); - $this->clientSecret = $this->appConfig->getAppValue(self::APP_ID, 'clientSecret'); - $this->username = $this->appConfig->getAppValue(self::APP_ID, 'username'); - $this->password = $this->appConfig->getAppValue(self::APP_ID, 'password'); + $this->authMethod = $this->appConfig->getAppValue(Application::APP_ID, 'authMethod', 'ClientCredentials'); + $this->tokenEndpoint = $this->appConfig->getAppValue(Application::APP_ID, 'tokenEndpoint', 'https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token'); + $this->vaasUrl = $this->appConfig->getAppValue(Application::APP_ID, 'vaasUrl', 'wss://gateway.staging.vaas.gdatasecurity.de'); + $this->clientId = $this->appConfig->getAppValue(Application::APP_ID, 'clientId'); + $this->clientSecret = $this->appConfig->getAppValue(Application::APP_ID, 'clientSecret'); + $this->username = $this->appConfig->getAppValue(Application::APP_ID, 'username'); + $this->password = $this->appConfig->getAppValue(Application::APP_ID, 'password'); } /** @@ -146,7 +146,7 @@ public function scan(string $filePath): VaasVerdict { * @return array */ private function getAllowlist(): array { - $allowlist = $this->appConfig->getAppValue(self::APP_ID, 'allowlist'); + $allowlist = $this->appConfig->getAppValue(Application::APP_ID, 'allowlist'); $allowlist = preg_replace('/\s+/', '', $allowlist); if (empty($allowlist)) { return []; @@ -159,7 +159,7 @@ private function getAllowlist(): array { * @return array */ private function getBlocklist(): array { - $blocklist = $this->appConfig->getAppValue(self::APP_ID, 'blocklist'); + $blocklist = $this->appConfig->getAppValue(Application::APP_ID, 'blocklist'); $blocklist = preg_replace('/\s+/', '', $blocklist); if (empty($blocklist)) { return []; diff --git a/lib/Settings/VaasAdmin.php b/lib/Settings/VaasAdmin.php index 15c3f8a5..dd505764 100644 --- a/lib/Settings/VaasAdmin.php +++ b/lib/Settings/VaasAdmin.php @@ -2,12 +2,12 @@ namespace OCA\GDataVaas\Settings; +use OCA\GDataVaas\AppInfo\Application; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\ISettings; class VaasAdmin implements ISettings { - private const APP_ID = 'gdatavaas'; private IConfig $config; @@ -17,24 +17,24 @@ public function __construct(IConfig $config) { public function getForm(): TemplateResponse { $params = [ - 'username' => $this->config->getAppValue(self::APP_ID, 'username'), - 'password' => $this->config->getAppValue(self::APP_ID, 'password'), - 'clientId' => $this->config->getAppValue(self::APP_ID, 'clientId'), - 'clientSecret' => $this->config->getAppValue(self::APP_ID, 'clientSecret'), - 'authMethod' => $this->config->getAppValue(self::APP_ID, 'authMethod', 'ClientCredentials'), - 'tokenEndpoint' => $this->config->getAppValue(self::APP_ID, 'tokenEndpoint', 'https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token'), - 'vaasUrl' => $this->config->getAppValue(self::APP_ID, 'vaasUrl', 'wss://gateway.staging.vaas.gdatasecurity.de'), - 'quarantineFolder' => $this->config->getAppValue(self::APP_ID, 'quarantineFolder', 'Quarantine'), - 'autoScanFiles' => $this->config->getAppValue(self::APP_ID, 'autoScanFiles', false), - 'scanOnlyNewFiles' => $this->config->getAppValue(self::APP_ID, 'scanOnlyNewFiles', true), - 'prefixMalicious' => $this->config->getAppValue(self::APP_ID, 'prefixMalicious', true), - 'disableUnscannedTag' => $this->config->getAppValue(self::APP_ID, 'disableUnscannedTag', false), - 'allowlist' => $this->config->getAppValue(self::APP_ID, 'allowlist'), - 'blocklist' => $this->config->getAppValue(self::APP_ID, 'blocklist'), - 'scanQueueLength' => $this->config->getAppValue(self::APP_ID, 'scanQueueLength', 5), + 'username' => $this->config->getAppValue(Application::APP_ID, 'username'), + 'password' => $this->config->getAppValue(Application::APP_ID, 'password'), + 'clientId' => $this->config->getAppValue(Application::APP_ID, 'clientId'), + 'clientSecret' => $this->config->getAppValue(Application::APP_ID, 'clientSecret'), + 'authMethod' => $this->config->getAppValue(Application::APP_ID, 'authMethod', 'ClientCredentials'), + 'tokenEndpoint' => $this->config->getAppValue(Application::APP_ID, 'tokenEndpoint', 'https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token'), + 'vaasUrl' => $this->config->getAppValue(Application::APP_ID, 'vaasUrl', 'wss://gateway.staging.vaas.gdatasecurity.de'), + 'quarantineFolder' => $this->config->getAppValue(Application::APP_ID, 'quarantineFolder', 'Quarantine'), + 'autoScanFiles' => $this->config->getAppValue(Application::APP_ID, 'autoScanFiles', false), + 'scanOnlyNewFiles' => $this->config->getAppValue(Application::APP_ID, 'scanOnlyNewFiles', true), + 'prefixMalicious' => $this->config->getAppValue(Application::APP_ID, 'prefixMalicious', true), + 'disableUnscannedTag' => $this->config->getAppValue(Application::APP_ID, 'disableUnscannedTag', false), + 'allowlist' => $this->config->getAppValue(Application::APP_ID, 'allowlist'), + 'blocklist' => $this->config->getAppValue(Application::APP_ID, 'blocklist'), + 'scanQueueLength' => $this->config->getAppValue(Application::APP_ID, 'scanQueueLength', 5), ]; - return new TemplateResponse(self::APP_ID, 'admin', $params); + return new TemplateResponse(Application::APP_ID, 'admin', $params); } public function getSection(): string {