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): implement config lexicon #44371

Closed
wants to merge 5 commits into from

Conversation

ArtificialOwl
Copy link
Member

@ArtificialOwl ArtificialOwl commented Mar 21, 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 force-pushed the feature/noid/wrapped-appconfig branch from f374de6 to b7c0296 Compare March 21, 2024 00:35
@ArtificialOwl ArtificialOwl added 1. to develop Accepted and waiting to be taken care of 2. developing Work in progress enhancement labels Mar 21, 2024
@ArtificialOwl ArtificialOwl added this to the Nextcloud 30 milestone Mar 21, 2024
lib/private/AppConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch from b7c0296 to eee62ee Compare March 22, 2024 00:21
@ArtificialOwl ArtificialOwl changed the title feat(config): frame config keys/values feat(config): implement config lexicon Apr 3, 2024
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch from 837a165 to e49c1a5 Compare April 3, 2024 17:14
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
@ChristophWurst ChristophWurst added the pending documentation This pull request needs an associated documentation update label Apr 8, 2024
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch from e49c1a5 to c0eb002 Compare April 22, 2024 12:22
@ArtificialOwl ArtificialOwl added 3. to review Waiting for reviews and removed 1. to develop Accepted and waiting to be taken care of 2. developing Work in progress labels Apr 22, 2024
@ArtificialOwl ArtificialOwl marked this pull request as ready for review April 22, 2024 12:26
@ArtificialOwl ArtificialOwl added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Apr 22, 2024
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch from c0eb002 to 1eb6edc Compare April 22, 2024 17:36
lib/private/AppConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch from 1eb6edc to 923d52a Compare April 22, 2024 19:27
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch 2 times, most recently from 7ac3ee4 to 161314f Compare April 23, 2024 00:28
@ArtificialOwl ArtificialOwl requested review from a team, icewind1991, yemkareems, sorbaugh, artonge and come-nc and removed request for a team April 24, 2024 08:35
This was referenced Jul 30, 2024
@Altahrim Altahrim mentioned this pull request Aug 5, 2024
@skjnldsv skjnldsv added 2. developing Work in progress stale Ticket or PR with no recent activity and removed 3. to review Waiting for reviews labels Aug 6, 2024
@Altahrim Altahrim mentioned this pull request Aug 7, 2024
@skjnldsv skjnldsv mentioned this pull request Aug 13, 2024
@skjnldsv skjnldsv modified the milestones: Nextcloud 30, Nextcloud 31 Aug 14, 2024
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch from 899b6fc to e2e345d Compare October 1, 2024 15:50
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch 3 times, most recently from 05c5e81 to 725f11d Compare November 13, 2024 10:19
@ArtificialOwl ArtificialOwl force-pushed the feature/noid/wrapped-appconfig branch from 9f5b8d3 to a9051c2 Compare November 15, 2024 09:13
@ArtificialOwl
Copy link
Member Author

moved to #49399

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 stale Ticket or PR with no recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants