Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config/loading/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
// - "SECRET[backend..secret.name]" will match and capture "backend" and ".secret.name"
// - "SECRET[secret_name]" will not match
// - "SECRET[.secret.name]" will not match
static COLLECTOR: Lazy<Regex> =
pub static COLLECTOR: Lazy<Regex> =
Lazy::new(|| Regex::new(r"SECRET\[([[:word:]]+)\.([[:word:].]+)\]").unwrap());

/// Helper type for specifically deserializing secrets backends.
Expand Down
4 changes: 3 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ pub use format::{Format, FormatHint};
pub use id::{ComponentKey, Inputs};
pub use loading::{
load, load_builder_from_paths, load_from_paths, load_from_paths_with_provider_and_secrets,
load_from_str, load_source_from_paths, merge_path_lists, process_paths, CONFIG_PATHS,
load_from_str, load_source_from_paths, merge_path_lists, process_paths, COLLECTOR,
CONFIG_PATHS,
};
pub use provider::ProviderConfig;
pub use secret::SecretBackend;
Expand All @@ -59,6 +60,7 @@ pub use transform::{
};
pub use unit_test::{build_unit_tests, build_unit_tests_main, UnitTestResult};
pub use validation::warnings;
pub use vars::{interpolate, ENVIRONMENT_VARIABLE_INTERPOLATION_REGEX};
pub use vector_core::config::{
init_log_schema, log_schema, proxy::ProxyConfig, LogSchema, OutputId,
};
Expand Down
35 changes: 19 additions & 16 deletions src/config/vars.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
use std::collections::HashMap;

use once_cell::sync::Lazy;
use regex::{Captures, Regex};

// Environment variable names can have any characters from the Portable Character Set other
// than NUL. However, for Vector's interpolation, we are closer to what a shell supports which
// is solely of uppercase letters, digits, and the '_' (that is, the `[:word:]` regex class).
// In addition to these characters, we allow `.` as this commonly appears in environment
// variable names when they come from a Java properties file.
//
// https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html
pub static ENVIRONMENT_VARIABLE_INTERPOLATION_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r"(?x)
\$\$|
\$([[:word:].]+)|
\$\{([[:word:].]+)(?:(:?-|:?\?)([^}]*))?\}",
)
.unwrap()
});

/// (result, warnings)
pub fn interpolate(
input: &str,
Expand All @@ -10,22 +28,7 @@ pub fn interpolate(
let mut errors = Vec::new();
let mut warnings = Vec::new();

// Environment variable names can have any characters from the Portable Character Set other
// than NUL. However, for Vector's interpolation, we are closer to what a shell supports which
// is solely of uppercase letters, digits, and the '_' (that is, the `[:word:]` regex class).
// In addition to these characters, we allow `.` as this commonly appears in environment
// variable names when they come from a Java properties file.
//
// https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html
let re = Regex::new(
r"(?x)
\$\$|
\$([[:word:].]+)|
\$\{([[:word:].]+)(?:(:?-|:?\?)([^}]*))?\}",
)
.unwrap();

let interpolated = re
let interpolated = ENVIRONMENT_VARIABLE_INTERPOLATION_REGEX
.replace_all(input, |caps: &Captures<'_>| {
let flags = caps.get(3).map(|m| m.as_str()).unwrap_or_default();
let def_or_err = caps.get(4).map(|m| m.as_str()).unwrap_or_default();
Expand Down