Skip to content

Support multiple peer files from environment variable#133

Open
ceresnam wants to merge 1 commit intoMindFlavor:masterfrom
ceresnam:master
Open

Support multiple peer files from environment variable#133
ceresnam wants to merge 1 commit intoMindFlavor:masterfrom
ceresnam:master

Conversation

@ceresnam
Copy link
Copy Markdown

@ceresnam ceresnam commented Apr 5, 2025

This change enables specifying multiple WireGuard configuration files for the extract_names_config_files option using the PROMETHEUS_WIREGUARD_EXPORTER_CONFIG_FILE_NAMES environment variable.

It utilizes std::env::split_paths to automatically handle the correct OS-specific path list separator (: for Linux/Unix, ; for Windows).

Example (Environment Variable):

PROMETHEUS_WIREGUARD_EXPORTER_CONFIG_FILE_NAMES="/tmp/wg1/conf:/tmp/wg2.conf" prometheus_wireguard_exporter

This correctly parses as:

[INFO] using options: Options { extract_names_config_files: Some(["/tmp/wg1/conf", "/tmp/wg2.conf"]) }

This complements the existing command-line functionality:

prometheus_wireguard_exporter -n /tmp/wg1/conf /tmp/wg2.conf

Which also parses as:

[INFO] using options: Options { extract_names_config_files: Some(["/tmp/wg1/conf", "/tmp/wg2.conf"]) }

Copy link
Copy Markdown
Collaborator

@PascalKu PascalKu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement, thank you! Using std::env::split_paths is a good choice since it automatically handles platform-specific separators.

One thought from my side: the current implementation applies split_paths to all values, including those coming from the CLI. CLI arguments are already provided as separate values by clap, so this may unintentionally split paths that legitimately contain the separator character.

extract_names_config_files: matches
.get_many("extract_names_config_files")
.map(|e: ValuesRef<'_, String>| e.into_iter().map(|a| a.to_owned()).collect()),
.get_many::<String>("extract_names_config_files")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This splits all inputs, including CLI arguments already parsed by clap. A CLI path containing : or ; could be incorrectly split. split_paths should only be applied when parsing the environment variable, not CLI-provided values.

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.

2 participants