Skip to content

Commit

Permalink
fix(config): Avoid parsing configuration files without secrets
Browse files Browse the repository at this point in the history
Which caused #20974

Reverts: #17759

Signed-off-by: Jesse Szwedko <[email protected]>
  • Loading branch information
jszwedko committed Aug 1, 2024
1 parent 70e61fc commit b4c8f75
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,6 @@ pub async fn load_configs(
paths = ?config_paths.iter().map(<&PathBuf>::from).collect::<Vec<_>>()
);

// config::init_log_schema should be called before initializing sources.
config::init_log_schema(&config_paths, true).map_err(handle_config_errors)?;

let mut config = config::load_from_paths_with_provider_and_secrets(
&config_paths,
signal_handler,
Expand All @@ -500,6 +497,7 @@ pub async fn load_configs(
.await
.map_err(handle_config_errors)?;

config::init_log_schema(config.global.log_schema.clone(), true);
config::init_telemetry(config.global.telemetry.clone(), true);

if !config.healthchecks.enabled {
Expand Down
12 changes: 1 addition & 11 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,9 @@ 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_lib::config::{
init_telemetry, log_schema, proxy::ProxyConfig, telemetry, LogSchema, OutputId,
init_log_schema, init_telemetry, log_schema, proxy::ProxyConfig, telemetry, LogSchema, OutputId,
};

/// Loads Log Schema from configurations and sets global schema.
/// Once this is done, configurations can be correctly loaded using
/// configured log schema defaults.
/// If deny is set, will panic if schema has already been set.
pub fn init_log_schema(config_paths: &[ConfigPath], deny_if_set: bool) -> Result<(), Vec<String>> {
let builder = load_builder_from_paths(config_paths)?;
vector_lib::config::init_log_schema(builder.global.log_schema, deny_if_set);
Ok(())
}

#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum ConfigPath {
File(PathBuf, FormatHint),
Expand Down
15 changes: 14 additions & 1 deletion src/config/unit_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,24 @@ impl UnitTest {
}
}

/// Loads Log Schema from configurations and sets global schema.
/// Once this is done, configurations can be correctly loaded using
/// configured log schema defaults.
/// If deny is set, will panic if schema has already been set.
fn init_log_schema_from_paths(
config_paths: &[ConfigPath],
deny_if_set: bool,
) -> Result<(), Vec<String>> {
let builder = config::loading::load_builder_from_paths(config_paths)?;
vector_lib::config::init_log_schema(builder.global.log_schema, deny_if_set);
Ok(())
}

pub async fn build_unit_tests_main(
paths: &[ConfigPath],
signal_handler: &mut signal::SignalHandler,
) -> Result<Vec<UnitTest>, Vec<String>> {
config::init_log_schema(paths, false)?;
init_log_schema_from_paths(paths, false)?;
let mut secrets_backends_loader = loading::load_secret_backends_from_paths(paths)?;
let config_builder = if secrets_backends_loader.has_secrets_to_retrieve() {
let resolved_secrets = secrets_backends_loader
Expand Down
4 changes: 1 addition & 3 deletions src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ pub fn validate_config(opts: &Opts, fmt: &mut Formatter) -> Option<Config> {
fmt.title(format!("Failed to load {:?}", &paths_list));
fmt.sub_error(errors);
};
config::init_log_schema(&paths, true)
.map_err(&mut report_error)
.ok()?;
let builder = config::load_builder_from_paths(&paths)
.map_err(&mut report_error)
.ok()?;
config::init_log_schema(builder.global.log_schema.clone(), true);

// Build
let (config, warnings) = builder
Expand Down

0 comments on commit b4c8f75

Please sign in to comment.