Skip to content
Open
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
55 changes: 31 additions & 24 deletions lib/private/GlobalScale/Config.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\GlobalScale;

use OCP\IConfig;
use Override;

class Config implements \OCP\GlobalScale\IConfig {
/** @var IConfig */
private $config;

/**
* Config constructor.
*
* @param IConfig $config
*/
public function __construct(IConfig $config) {
$this->config = $config;
public function __construct(
private readonly IConfig $config,
) {
}

/**
* check if global scale is enabled
*
* @since 12.0.1
* @return bool
*/
public function isGlobalScaleEnabled() {
#[Override]
public function isGlobalScaleEnabled(): bool {
return $this->config->getSystemValueBool('gs.enabled', false);
}

/**
* check if federation should only be used internally in a global scale setup
*
* @since 12.0.1
* @return bool
*/
public function onlyInternalFederation() {
#[Override]
public function onlyInternalFederation(): bool {
// if global scale is disabled federation works always globally
$gsEnabled = $this->isGlobalScaleEnabled();
if ($gsEnabled === false) {
Expand All @@ -48,4 +35,24 @@ public function onlyInternalFederation() {

return $enabled === 'internal';
}

#[Override]
public function isPrimary(): bool {
return $this->isGlobalScaleEnabled()
&& ($this->config->getSystemValueString('gss.mode', 'slave') === 'master'
|| $this->config->getSystemValueString('gss.mode', 'slave') === 'primary');
}

#[Override]
public function isSecondary(): bool {
return $this->isGlobalScaleEnabled()
&& ($this->config->getSystemValueString('gss.mode', 'slave') === 'slave'
|| $this->config->getSystemValueString('gss.mode', 'slave') === 'secondary');
}

#[Override]
public function isPrimaryAdmin(string $userId): bool {
return in_array($userId, $this->config->getSystemValue('gss.master.admin', []))
|| in_array($userId, $this->config->getSystemValue('gss.primary.admin', []));
}
}
43 changes: 37 additions & 6 deletions lib/public/GlobalScale/IConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,60 @@
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCP\GlobalScale;

use OCP\AppFramework\Attribute\Consumable;

/**
* Interface IConfig
*
* Configuration of the global scale architecture
*
* @since 12.0.1
*/
#[Consumable(since: '12.0.1')]
interface IConfig {
/**
* check if global scale is enabled
* Check if global scale is enabled.
*
* @since 12.0.1
* @return bool
*/
public function isGlobalScaleEnabled();
public function isGlobalScaleEnabled(): bool;

/**
* check if federation should only be used internally in a global scale setup
* Check if federation should only be used internally in a global scale setup.
*
* @since 12.0.1
* @return bool
*/
public function onlyInternalFederation();
public function onlyInternalFederation(): bool;

/**
* Check if the current instance is the primary instance.
*
* This instance is then only used to log in the users and then redirect them
* to their associated secondary instance.
*
* @since 34.0.3
*/
public function isPrimary(): bool;

/**
* Check if the current instance is one of the secondary instance.
*
* These instances are the actual instance of a user and hold all their data.
*
* @since 34.0.3
*/
public function isSecondary(): bool;

/**
* Check if the given user is one of the admin on the primary instance.
*
* These users won't be redirected to a secondary instance and instead will
* stay on the primary instance to manage the configuration of the instance.
*
* @since 34.0.3
*/
public function isPrimaryAdmin(string $userId): bool;
}
Loading