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 1 commit 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 isStrict(): bool {
		return false;
	}

	public function getAppConfigs(): array {
		return [
			new ConfigLexiconEntry('key1', IConfigLexiconEntry::TYPE_STRING, defintion: 'this is a test config key', lazy: true),
			new ConfigLexiconEntry('key2', IConfigLexiconEntry::TYPE_STRING, sensitive: true),
			new ConfigLexiconEntry('key3', IConfigLexiconEntry::TYPE_INT, 42),
			new ConfigLexiconEntry('key4', IConfigLexiconEntry::TYPE_STRING),
		];
	}

	public function getUserPreferences(): array {
		return [];
	}
}

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

If configured as strict, setting an unlisted config values returns 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress enhancement pending documentation This pull request needs an associated documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant