fix(lexicon): send single notice/warning when using unknown config key

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/54739/head
Maxence Lange 4 months ago
parent 9a0892ca30
commit 46ced9df22
  1. 20
      lib/private/AppConfig.php
  2. 18
      lib/private/Config/UserConfig.php

@ -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…
Cancel
Save