Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): implementation of lexicon #49399

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ArtificialOwl
Copy link
Member

@ArtificialOwl ArtificialOwl commented Nov 20, 2024

A Config Lexicon is a list of config keys used by current app. Each entry also define the expected type for the config value, its lazyness/sensitivity.
The loading is done by registering a IConfigLexicon.

Application.php

	public function register(IRegistrationContext $context): void {
		$context->registerConfigLexicon(ConfigLexicon::class);
	}

ConfigLexicon.php

class Lexicon implements IConfigLexicon {
	public function getStrictness(): ConfigLexiconStrictness {
		return ConfigLexiconStrictness::WARNING;
	}

	public function getAppConfigs(): array {
		return [
			new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IAppConfig::FLAG_SENSITIVE),
			new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
		];
	}

	public function getUserConfigs(): array {
		return [
			new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
			new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
		];
	}
}

Note: A description of the config key can be added as 3rd parameter of the ConfigLexiconEntry. This information is not stored when running from a web process.

store and retrieve config value

Once this is done:

any code trying to wrongly type config values will get an exception

$ ./occ config:app:set myapp key1 --value 1 --type integer

In AppConfig.php line 1544:                                                                                     
  The key is typed incorrectly in relation to the app config lexicon

set/get on config values set as lazy will work even if not specified in the process

	$this->appConfig->setValueInt('myapp', 'key1', 'abc');
$ ./occ config:app:get myapp key1 --details
  - app: myapp
  - key: key1
  - value: abc
  - type: string
  - lazy: true
  - sensitive: false

default value can be overwritten

	$this->appConfig->getValueInt('myapp', 'key3', 0);

will returns 42

ConfigLexiconStrictness define the behavior when setting an unlisted config key:

  • ::IGNORE: does not limit the set/get on an unknown config key
  • ::NOTICE: does not limit the set/get on an unknown config key, but generate a notice in the logs
  • ::WARNING: unknown config key will not be set, and get will returns the default value. A warning will be issued in the logs
  • ::EXCEPTION: set/get on an unknown config key will generate an exception
$ ./occ config:app:set myapp key5 --value 1

In AppConfig.php line 1530:                                                                                
  The key is not defined in the app config lexicon  

Also, setting a config key as deprecated will generate a level 1 log entry when the config key is used

@ArtificialOwl ArtificialOwl added 2. developing Work in progress pending documentation This pull request needs an associated documentation update enhancement labels Nov 20, 2024
@ArtificialOwl ArtificialOwl added this to the Nextcloud 31 milestone Nov 20, 2024
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/config-lexicon branch 2 times, most recently from 57c612f to 7ac507e Compare November 20, 2024 15:27
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/config-lexicon branch 5 times, most recently from c8d65a4 to 31972cb Compare December 6, 2024 10:35
@ArtificialOwl ArtificialOwl added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Dec 6, 2024
lib/private/AppConfig.php Outdated Show resolved Hide resolved
lib/private/Config/UserConfig.php Outdated Show resolved Hide resolved
lib/unstable/Config/Lexicon/ConfigLexiconEntry.php Outdated Show resolved Hide resolved
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/config-lexicon branch 3 times, most recently from c8b5562 to fa36927 Compare December 12, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement pending documentation This pull request needs an associated documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants