mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
Merge pull request #54739 from nextcloud/fix/noid/limit-spam-on-strictness
This commit is contained in:
commit
a3183f7a12
2 changed files with 26 additions and 12 deletions
|
|
@ -69,6 +69,8 @@ class AppConfig implements IAppConfig {
|
|||
/** @var array<string, array{entries: array<string, Entry>, aliases: array<string, string>, strictness: Strictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
|
||||
private array $configLexiconDetails = [];
|
||||
private bool $ignoreLexiconAliases = false;
|
||||
private array $strictnessApplied = [];
|
||||
|
||||
/** @var ?array<string, string> */
|
||||
private ?array $appVersionsCache = null;
|
||||
private ?ICache $localCache = null;
|
||||
|
|
@ -1698,7 +1700,7 @@ class AppConfig implements IAppConfig {
|
|||
}
|
||||
|
||||
if (!array_key_exists($key, $configDetails['entries'])) {
|
||||
return $this->applyLexiconStrictness($configDetails['strictness'], 'The app config key ' . $app . '/' . $key . ' is not defined in the config lexicon');
|
||||
return $this->applyLexiconStrictness($configDetails['strictness'], $app . '/' . $key);
|
||||
}
|
||||
|
||||
// if lazy is NULL, we ignore all check on the type/lazyness/default from Lexicon
|
||||
|
|
@ -1743,22 +1745,26 @@ class AppConfig implements IAppConfig {
|
|||
* @throws AppConfigUnknownKeyException if strictness implies exception
|
||||
* @see \OCP\Config\Lexicon\ILexicon::getStrictness()
|
||||
*/
|
||||
private function applyLexiconStrictness(
|
||||
?Strictness $strictness,
|
||||
string $line = '',
|
||||
): bool {
|
||||
private function applyLexiconStrictness(?Strictness $strictness, string $configAppKey): bool {
|
||||
if ($strictness === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$line = 'The app config key ' . $configAppKey . ' is not defined in the config lexicon';
|
||||
switch ($strictness) {
|
||||
case Strictness::IGNORE:
|
||||
return true;
|
||||
case Strictness::NOTICE:
|
||||
$this->logger->notice($line);
|
||||
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
|
||||
$this->strictnessApplied[] = $configAppKey;
|
||||
$this->logger->notice($line);
|
||||
}
|
||||
return true;
|
||||
case Strictness::WARNING:
|
||||
$this->logger->warning($line);
|
||||
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
|
||||
$this->strictnessApplied[] = $configAppKey;
|
||||
$this->logger->warning($line);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class UserConfig implements IUserConfig {
|
|||
/** @var array<string, array{entries: array<string, Entry>, aliases: array<string, string>, strictness: Strictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
|
||||
private array $configLexiconDetails = [];
|
||||
private bool $ignoreLexiconAliases = false;
|
||||
private array $strictnessApplied = [];
|
||||
|
||||
public function __construct(
|
||||
protected IDBConnection $connection,
|
||||
|
|
@ -1903,7 +1904,7 @@ class UserConfig implements IUserConfig {
|
|||
}
|
||||
|
||||
if (!array_key_exists($key, $configDetails['entries'])) {
|
||||
return $this->applyLexiconStrictness($configDetails['strictness'], 'The user config key ' . $app . '/' . $key . ' is not defined in the config lexicon');
|
||||
return $this->applyLexiconStrictness($configDetails['strictness'], $app . '/' . $key);
|
||||
}
|
||||
|
||||
// if lazy is NULL, we ignore all check on the type/lazyness/default from Lexicon
|
||||
|
|
@ -1970,21 +1971,28 @@ class UserConfig implements IUserConfig {
|
|||
*
|
||||
* @return bool TRUE if conflict can be fully ignored
|
||||
* @throws UnknownKeyException
|
||||
*@see ILexicon::getStrictness()
|
||||
* @see ILexicon::getStrictness()
|
||||
*/
|
||||
private function applyLexiconStrictness(?Strictness $strictness, string $line = ''): bool {
|
||||
private function applyLexiconStrictness(?Strictness $strictness, string $configAppKey): bool {
|
||||
if ($strictness === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$line = 'The user config key ' . $configAppKey . ' is not defined in the config lexicon';
|
||||
switch ($strictness) {
|
||||
case Strictness::IGNORE:
|
||||
return true;
|
||||
case Strictness::NOTICE:
|
||||
$this->logger->notice($line);
|
||||
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
|
||||
$this->strictnessApplied[] = $configAppKey;
|
||||
$this->logger->notice($line);
|
||||
}
|
||||
return true;
|
||||
case Strictness::WARNING:
|
||||
$this->logger->warning($line);
|
||||
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
|
||||
$this->strictnessApplied[] = $configAppKey;
|
||||
$this->logger->warning($line);
|
||||
}
|
||||
return false;
|
||||
case Strictness::EXCEPTION:
|
||||
throw new UnknownKeyException($line);
|
||||
|
|
|
|||
Loading…
Reference in a new issue