Skip to content

Commit

Permalink
don't redefine the APP_ID in all files
Browse files Browse the repository at this point in the history
you can just import appinfo/application and use the static field there
  • Loading branch information
Simonis, Matthias authored and Simonis, Matthias committed Jun 12, 2024
1 parent 66a7d75 commit d231b97
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,7 +14,6 @@
use Psr\Log\LoggerInterface;

class FileService {
private const APP_ID = "gdatavaas";

private IUserMountCache $userMountCache;
private IRootFolder $rootFolder;
Expand All @@ -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();
Expand Down Expand Up @@ -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');
}
Expand Down
20 changes: 10 additions & 10 deletions lib/Service/VerdictService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +23,6 @@

class VerdictService {
public const MAX_FILE_SIZE = 268435456;
private const APP_ID = "gdatavaas";

private string $username;
private string $password;
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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 [];
Expand All @@ -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 [];
Expand Down
34 changes: 17 additions & 17 deletions lib/Settings/VaasAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down

0 comments on commit d231b97

Please sign in to comment.