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: Expressions anywhere in the configuration #930

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

skrashevich
Copy link
Contributor

@skrashevich skrashevich commented Feb 6, 2024

This PR introduces the ability to preprocess configuration data to evaluate expressions contained within it.

The ability to preprocess and evaluate expressions within the configuration could simplify dynamic configuration scenarios and reduce the need for external templating tools.

example:

streams:
  test:
    - http://192.168.88.158/live/index.m3u${{ 4+4 }}

will be pre-processed to http://192.168.88.158/live/index.m3u8

Roadmap:

  • test for regressions and backward compatibility
  • assess the impact on security
  • add support for this syntax to the configuration editor

This commit introduces the ability to preprocess configuration data to evaluate expressions contained within it before the data is unmarshalled into Go structures. It leverages a new function, `ProcessConfig`, from the `expr` package, which searches for and evaluates expressions denoted by `${{...}}` syntax.

Additionally, this commit includes comprehensive tests for both the `LoadConfig` function and the newly added `processConfig` logic to ensure that expressions are correctly evaluated and that the configuration loading behaves as expected, even when faced with invalid configurations or expressions.

The ability to preprocess and evaluate expressions within the configuration could simplify dynamic configuration scenarios and reduce the need for external templating tools.
@felipecrs
Copy link
Contributor

Just wondering, why not add support for go-template the config file directly?

@skrashevich
Copy link
Contributor Author

Just wondering, why not add support for go-template the config file directly?

What do you mean? Go-template is a template engine, but my idea is in a dynamic calculated configuration file

@felipecrs
Copy link
Contributor

If you make the config file a template, and use go-template to render it before consuming from it, it should give a similar result but maybe more powerful.

streams:
  test:
    - rtps://{{ env "MY_USER" }}:{{ env "MY_PASS" }}@myhost.com

@AlexxIT AlexxIT added the doubt label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants