Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/Migration/Version040000Date20250911150115.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Gitlab\Migration;

use Closure;
use OCA\Gitlab\AppInfo\Application;
use OCA\Gitlab\Service\ConfigService;
use OCP\IAppConfig;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version040000Date20250911150115 extends SimpleMigrationStep {

public function __construct(
private IAppConfig $appConfig,
private ConfigService $configService,
) {
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
#[ \Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
// app config
foreach (['client_id', 'client_secret'] as $key) {
$value = $this->configService->getClearAppValue($key, false);
if ($value !== '') {
$this->configService->setEncryptedAppValue($key, $value, true);
}
}

$value = $this->appConfig->getValueString(Application::APP_ID, 'oauth_instance_url');
$this->appConfig->setValueString(Application::APP_ID, 'oauth_instance_url', $value, lazy: true);
}
}
24 changes: 13 additions & 11 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,62 @@
namespace OCA\Gitlab\Service;

use OCA\Gitlab\AppInfo\Application;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\PreConditionNotMetException;
use OCP\Security\ICrypto;

class ConfigService {
public function __construct(
private IConfig $config,
private IAppConfig $appConfig,
private ICrypto $crypto,
) {
}

public function getClearAppValue(string $key): string {
$value = $this->config->getAppValue(Application::APP_ID, $key);
public function getClearAppValue(string $key, bool $lazy = false): string {
$value = $this->appConfig->getValueString(Application::APP_ID, $key, lazy: $lazy);
if ($value === '') {
return $value;
}
return $this->crypto->decrypt($value);
}

public function setEncryptedAppValue(string $key, string $value): void {
public function setEncryptedAppValue(string $key, string $value, bool $lazy = false): void {
if ($value === '') {
$this->config->setAppValue(Application::APP_ID, $key, $value);
$this->appConfig->setValueString(Application::APP_ID, $key, $value, lazy: $lazy);
} else {
$encryptedValue = $this->crypto->encrypt($value);
$this->config->setAppValue(Application::APP_ID, $key, $encryptedValue);
$this->appConfig->setValueString(Application::APP_ID, $key, $encryptedValue, lazy: $lazy);
}
}

public function getAdminClientId(): string {
return $this->getClearAppValue('client_id');
return $this->getClearAppValue('client_id', true);
}

public function setAdminClientId(string $clientId): void {
$this->setEncryptedAppValue('client_id', $clientId);
$this->setEncryptedAppValue('client_id', $clientId, true);
}

public function hasAdminClientSecret(): bool {
return $this->getAdminClientSecret() !== '';
}

public function getAdminClientSecret(): string {
return $this->getClearAppValue('client_secret');
return $this->getClearAppValue('client_secret', true);
}

public function setAdminClientSecret(string $clientSecret): void {
$this->setEncryptedAppValue('client_secret', $clientSecret);
$this->setEncryptedAppValue('client_secret', $clientSecret, true);
}

public function getAdminOauthUrl(): string {
return $this->config->getAppValue(Application::APP_ID, 'oauth_instance_url') ?: Application::DEFAULT_GITLAB_URL;
return $this->appConfig->getValueString(Application::APP_ID, 'oauth_instance_url', lazy: true) ?: Application::DEFAULT_GITLAB_URL;
}

public function setAdminOauthUrl(string $url): void {
$this->config->setAppValue(Application::APP_ID, 'oauth_instance_url', $url);
$this->appConfig->setValueString(Application::APP_ID, 'oauth_instance_url', $url, lazy: true);
}

public function getAdminLinkPreviewEnabled(): bool {
Expand Down
Loading