Skip to content

Commit e6a6f7d

Browse files
committed
fix bug after bad refactoring, cleanup
1 parent dc95a83 commit e6a6f7d

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/config/loading/config_builder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::collections::HashMap;
33
use indexmap::IndexMap;
44
use toml::value::Table;
55

6-
use super::{deserialize_table, interpolate_toml_table_with_secrets, loader};
6+
use super::{
7+
deserialize_table, interpolate_toml_table_with_secrets, loader, resolve_environment_variables,
8+
};
79
use super::{ComponentHint, Process};
810
use crate::config::{
911
ComponentKey, ConfigBuilder, EnrichmentTableOuter, SinkOuter, SourceOuter, TestDefinition,
@@ -34,6 +36,7 @@ impl ConfigBuilderLoader {
3436
impl Process for ConfigBuilderLoader {
3537
/// Prepares input for a `ConfigBuilder` by interpolating environment variables.
3638
fn postprocess(&mut self, table: Table) -> Result<Table, Vec<String>> {
39+
let table = resolve_environment_variables(table)?;
3740
self.secrets
3841
.as_ref()
3942
.map(|secrets_map| interpolate_toml_table_with_secrets(&table, secrets_map))

src/config/loading/interpolation.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,35 @@ pub fn interpolate_toml_table_with_env_vars(
8484
}
8585

8686
/// Returns a new TOML `Table` with all string values interpolated.
87-
/// Leaves original table untouched.
8887
pub fn interpolate_toml_table(
8988
table: &Table,
9089
vars: &HashMap<String, String>,
9190
interpolate_fn: InterpolateFn,
9291
) -> Result<Table, Vec<String>> {
9392
let mut result = Table::new();
94-
let mut all_errors = Vec::new();
93+
let mut errors = Vec::new();
9594

9695
for (key, value) in table {
9796
let new_key = match interpolate_fn(key, vars) {
9897
Ok(k) => k,
9998
Err(errs) => {
100-
all_errors.extend(errs);
99+
errors.extend(errs);
101100
key.clone()
102101
}
103102
};
104103

105-
let new_value = match interpolate_toml_value(value, vars, &mut all_errors, interpolate_fn) {
104+
let new_value = match interpolate_toml_value(value, vars, &mut errors, interpolate_fn) {
106105
Some(v) => v,
107106
None => value.clone(),
108107
};
109108

110109
result.insert(new_key, new_value);
111110
}
112111

113-
if all_errors.is_empty() {
112+
if errors.is_empty() {
114113
Ok(result)
115114
} else {
116-
Err(all_errors)
115+
Err(errors)
117116
}
118117
}
119118

@@ -203,12 +202,12 @@ mod test {
203202
}
204203

205204
#[test]
206-
fn test_interpolate_toml_table_recursive() {
205+
fn test_interpolate_toml_table() {
207206
let raw = indoc! {r#"
208207
# ${IN_COMMENT_BUT_DOES_NOT_EXIST}
209208
[[tests]]
210209
name = "${NAME}"
211-
# noop = "SECRET[i_dont_exist]"
210+
# This line should not cause a loading failure - "SECRET[backend_1.i_dont_exist]"
212211
[[tests.inputs]]
213212
insert_at = "${UNDEFINED:-foo}"
214213
type = "log"

src/config/loading/loader.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ pub(super) mod process {
5353
/// in here with subtly different names that can be hidden from public view, hence why
5454
/// this is nested in a private mod.
5555
pub trait Process {
56-
/// This is invoked after the input string deserialization. This can be a useful step to interpolate
56+
/// This is invoked after input deserialization. This can be a useful step to interpolate
5757
/// environment variables or perform some other post-processing on the table.
5858
fn postprocess(&mut self, table: Table) -> Result<Table, Vec<String>>;
5959

60-
/// Calls into the `prepare` method, and deserializes a `Read` to a `T`.
60+
/// Deserializes the input using the given format and runs postprocessing on the result.
61+
///
62+
/// This reads the input into a string, deserializes it into a `Table`, and then
63+
/// applies `postprocess` to the resulting table.
6164
fn load<R: Read>(&mut self, input: R, format: Format) -> Result<Table, Vec<String>> {
6265
let value = string_from_input(input)?;
6366
let table: Table = format::deserialize(&value, format)?;

src/config/loading/secret.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use toml::value::Table;
1111
use toml::Value;
1212
use vector_lib::config::ComponentKey;
1313

14-
use crate::config::loading::interpolate_toml_table;
14+
use crate::config::loading::{interpolate_toml_table, resolve_environment_variables};
1515
use crate::{
1616
config::{
1717
loading::{deserialize_table, process::Process, ComponentHint, Loader},
@@ -90,6 +90,7 @@ impl SecretBackendLoader {
9090

9191
impl Process for SecretBackendLoader {
9292
fn postprocess(&mut self, table: Table) -> Result<Table, Vec<String>> {
93+
let table = resolve_environment_variables(table)?;
9394
collect_secret_keys_from_table(&table, &mut self.secret_keys);
9495
Ok(table)
9596
}

0 commit comments

Comments
 (0)