Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/config/loading/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ 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> =
Lazy::new(|| Regex::new(r"SECRET\[([[:word:]]+)\.([[:word:].]+)\]").unwrap());
pub const SECRET_BACKEND_PATTERN: &str = r"SECRET\[([[:word:]]+)\.([[:word:].]+)\]";
static COLLECTOR: Lazy<Regex> = Lazy::new(|| Regex::new(SECRET_BACKEND_PATTERN).unwrap());

/// Helper type for specifically deserializing secrets backends.
#[derive(Debug, Default, Deserialize, Serialize)]
Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ 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,
SECRET_BACKEND_PATTERN,
};
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_PATTERN};
pub use vector_core::config::{
init_log_schema, log_schema, proxy::ProxyConfig, LogSchema, OutputId,
};
Expand Down
27 changes: 13 additions & 14 deletions src/config/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ use std::collections::HashMap;

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 const ENVIRONMENT_VARIABLE_INTERPOLATION_PATTERN: &str = r"(?x)
Comment thread
wbew marked this conversation as resolved.
Outdated
\$\$|
\$([[:word:].]+)|
\$\{([[:word:].]+)(?:(:?-|:?\?)([^}]*))?\}";

/// (result, warnings)
pub fn interpolate(
input: &str,
Expand All @@ -10,20 +22,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 re = Regex::new(ENVIRONMENT_VARIABLE_INTERPOLATION_PATTERN).unwrap();

let interpolated = re
.replace_all(input, |caps: &Captures<'_>| {
Expand Down