Skip to content

Commit a3183f7

Browse files
Merge pull request #54739 from nextcloud/fix/noid/limit-spam-on-strictness
2 parents 74804b6 + 46ced9d commit a3183f7

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

lib/private/AppConfig.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class AppConfig implements IAppConfig {
6969
/** @var array<string, array{entries: array<string, Entry>, aliases: array<string, string>, strictness: Strictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
7070
private array $configLexiconDetails = [];
7171
private bool $ignoreLexiconAliases = false;
72+
private array $strictnessApplied = [];
73+
7274
/** @var ?array<string, string> */
7375
private ?array $appVersionsCache = null;
7476
private ?ICache $localCache = null;
@@ -1698,7 +1700,7 @@ private function matchAndApplyLexiconDefinition(
16981700
}
16991701

17001702
if (!array_key_exists($key, $configDetails['entries'])) {
1701-
return $this->applyLexiconStrictness($configDetails['strictness'], 'The app config key ' . $app . '/' . $key . ' is not defined in the config lexicon');
1703+
return $this->applyLexiconStrictness($configDetails['strictness'], $app . '/' . $key);
17021704
}
17031705

17041706
// if lazy is NULL, we ignore all check on the type/lazyness/default from Lexicon
@@ -1743,22 +1745,26 @@ private function matchAndApplyLexiconDefinition(
17431745
* @throws AppConfigUnknownKeyException if strictness implies exception
17441746
* @see \OCP\Config\Lexicon\ILexicon::getStrictness()
17451747
*/
1746-
private function applyLexiconStrictness(
1747-
?Strictness $strictness,
1748-
string $line = '',
1749-
): bool {
1748+
private function applyLexiconStrictness(?Strictness $strictness, string $configAppKey): bool {
17501749
if ($strictness === null) {
17511750
return true;
17521751
}
17531752

1753+
$line = 'The app config key ' . $configAppKey . ' is not defined in the config lexicon';
17541754
switch ($strictness) {
17551755
case Strictness::IGNORE:
17561756
return true;
17571757
case Strictness::NOTICE:
1758-
$this->logger->notice($line);
1758+
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
1759+
$this->strictnessApplied[] = $configAppKey;
1760+
$this->logger->notice($line);
1761+
}
17591762
return true;
17601763
case Strictness::WARNING:
1761-
$this->logger->warning($line);
1764+
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
1765+
$this->strictnessApplied[] = $configAppKey;
1766+
$this->logger->warning($line);
1767+
}
17621768
return false;
17631769
}
17641770

lib/private/Config/UserConfig.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class UserConfig implements IUserConfig {
6666
/** @var array<string, array{entries: array<string, Entry>, aliases: array<string, string>, strictness: Strictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
6767
private array $configLexiconDetails = [];
6868
private bool $ignoreLexiconAliases = false;
69+
private array $strictnessApplied = [];
6970

7071
public function __construct(
7172
protected IDBConnection $connection,
@@ -1903,7 +1904,7 @@ private function matchAndApplyLexiconDefinition(
19031904
}
19041905

19051906
if (!array_key_exists($key, $configDetails['entries'])) {
1906-
return $this->applyLexiconStrictness($configDetails['strictness'], 'The user config key ' . $app . '/' . $key . ' is not defined in the config lexicon');
1907+
return $this->applyLexiconStrictness($configDetails['strictness'], $app . '/' . $key);
19071908
}
19081909

19091910
// if lazy is NULL, we ignore all check on the type/lazyness/default from Lexicon
@@ -1970,21 +1971,28 @@ private function getSystemDefault(string $appId, Entry $configValue): ?string {
19701971
*
19711972
* @return bool TRUE if conflict can be fully ignored
19721973
* @throws UnknownKeyException
1973-
*@see ILexicon::getStrictness()
1974+
* @see ILexicon::getStrictness()
19741975
*/
1975-
private function applyLexiconStrictness(?Strictness $strictness, string $line = ''): bool {
1976+
private function applyLexiconStrictness(?Strictness $strictness, string $configAppKey): bool {
19761977
if ($strictness === null) {
19771978
return true;
19781979
}
19791980

1981+
$line = 'The user config key ' . $configAppKey . ' is not defined in the config lexicon';
19801982
switch ($strictness) {
19811983
case Strictness::IGNORE:
19821984
return true;
19831985
case Strictness::NOTICE:
1984-
$this->logger->notice($line);
1986+
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
1987+
$this->strictnessApplied[] = $configAppKey;
1988+
$this->logger->notice($line);
1989+
}
19851990
return true;
19861991
case Strictness::WARNING:
1987-
$this->logger->warning($line);
1992+
if (!in_array($configAppKey, $this->strictnessApplied, true)) {
1993+
$this->strictnessApplied[] = $configAppKey;
1994+
$this->logger->warning($line);
1995+
}
19881996
return false;
19891997
case Strictness::EXCEPTION:
19901998
throw new UnknownKeyException($line);

0 commit comments

Comments
 (0)