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

Add: Use external toml file for plugin configuration #706

Closed
wants to merge 11 commits into from

Conversation

ghost
Copy link

@ghost ghost commented May 14, 2024

What

Use an external toml file to store plugin configurations.
Rewrite http_links_in_tags plugin to use external config for exclusions as a demonstration of how other plugins can use it.

The location of the file is specified by the --plugins-config-file command-line argument added to the parser.
This argument has a default value of 'troubadix_config.toml'. This is the same as the config file in the vt repo.
This makes this release compatible with all old workflows and aliases that use Troubadix, as long as the new config file is present.
Otherwise, a different file must be specified, as Troubadix will no longer be able to run without a valid config file.
If no plugin is being run that uses external configuration, an empty but existing file is sufficient to be valid.
This is done to make it less likely that Troubadix will run without a configuration when it should have one.

This file must have an entry with the same name as the plugins Plugin.name attribute for each plugin that is executed during the Troubadix run that uses the new system.

[Plugin.name]
exclusions = ["foo", "bar"]

Plugins that are not executed or that do not use the new system do not need an entry in the toml file.

The values of the plugin entries can be any valid Toml structure that can be parsed into Python types.
This should allow the configuration of most plugins.
For example, http_tags_in_link just wants a list of exclusions. Which maps 1 to 1 from toml to python.

Plugins must use a class attribute to indicate if they depend on an external configuration. If nothing is set, as in existing plugins, the default of False is used. And then none of the new changes will apply to this plugin. Its function remains the same.

Plugins that use external config are passed the entire config, and are responsible for validating and extracting only the parts they want. They can then access the config via an instance attribute `config

Why

The purpose is to unify the configuration for all Troubadix plugins that are use case dependent / come from outside Troubadix.

Exclusion changes that are necessary for VT development, but do not change the Troubadix plugins, can then be part of the same PR that introduces the VT, and not require an additional Troubadix PR anymore.

Changes for VT Development

Rollout Step1

A toml file must be placed in the VT repository that contains all configuration for plugins that use the new file.

Rollout Step2

If a config file from a location other than the default location is to be used for QA, the troubadix invocation must be changed to reflect this.

Changes to config during normal VT development

Changes to the configuration of plugins that use the new system must be made in the vt repo toml file, not in Troubadix.
Changes to the config of plugins that have not yet been converted still need a Troubadix PR.

Converting existing plugins / Creating new Plugin with external config

Set class attribute requires_external_config = True
Override validate_plugin_config of the 'Plugin' base class.
Access config via self.config["key"].

References

VTOPS-115

Checklist

  • Tests

Copy link

github-actions bot commented May 14, 2024

Conventional Commits Report

Type Number
Changed 10
Added 1

🚀 Conventional commits found.

@ghost ghost force-pushed the poc_plugins_config_file branch 2 times, most recently from cb89348 to 70c0d1a Compare May 15, 2024 12:10
Copy link

codecov bot commented May 15, 2024

Codecov Report

Attention: Patch coverage is 71.73913% with 13 lines in your changes missing coverage. Please review.

Project coverage is 79.48%. Comparing base (318f02a) to head (81961da).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
troubadix/troubadix.py 40.00% 6 Missing ⚠️
troubadix/plugin.py 78.94% 2 Missing and 2 partials ⚠️
troubadix/runner.py 66.66% 2 Missing ⚠️
troubadix/argparser.py 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #706      +/-   ##
==========================================
- Coverage   79.51%   79.48%   -0.04%     
==========================================
  Files          86       86              
  Lines        2910     2944      +34     
  Branches      611      616       +5     
==========================================
+ Hits         2314     2340      +26     
- Misses        450      457       +7     
- Partials      146      147       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tests/plugins/__init__.py Outdated Show resolved Hide resolved
tests/plugins/__init__.py Outdated Show resolved Hide resolved
plugins_config.toml Outdated Show resolved Hide resolved
troubadix/argparser.py Outdated Show resolved Hide resolved
troubadix/plugins/http_links_in_tags.py Outdated Show resolved Hide resolved
troubadix/runner.py Outdated Show resolved Hide resolved
troubadix/troubadix.py Outdated Show resolved Hide resolved
troubadix/plugin.py Fixed Show fixed Hide fixed
troubadix/plugin.py Outdated Show resolved Hide resolved
troubadix/runner.py Outdated Show resolved Hide resolved
troubadix/argparser.py Outdated Show resolved Hide resolved
troubadix/argparser.py Outdated Show resolved Hide resolved
troubadix_config.toml Outdated Show resolved Hide resolved
troubadix/plugins/http_links_in_tags.py Outdated Show resolved Hide resolved
troubadix/runner.py Outdated Show resolved Hide resolved
@ghost ghost force-pushed the poc_plugins_config_file branch from 06ec035 to 69c69b2 Compare June 19, 2024 06:40
@NiklasHargarter NiklasHargarter force-pushed the poc_plugins_config_file branch from 69c69b2 to b681049 Compare July 2, 2024 10:58
@NiklasHargarter NiklasHargarter marked this pull request as ready for review July 2, 2024 13:13
@NiklasHargarter NiklasHargarter requested a review from a team as a code owner July 2, 2024 13:13
pyproject.toml Outdated Show resolved Hide resolved
troubadix_config.toml Outdated Show resolved Hide resolved
troubadix_config.toml Outdated Show resolved Hide resolved
troubadix/argparser.py Outdated Show resolved Hide resolved
@NiklasHargarter NiklasHargarter force-pushed the poc_plugins_config_file branch from 2c291d1 to 81961da Compare August 9, 2024 10:07
@cfi-gb cfi-gb deleted the poc_plugins_config_file branch November 4, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants