Skip to content
Open
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
12 changes: 9 additions & 3 deletions crates/apollo_node_config/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ pub fn config_to_preset(config_map: &Value) -> Value {
}
}

/// Keep "{prefix}.#is_none": true, remove all other "{prefix}.*" keys.
/// Keep "{prefix}.#is_none": true, remove all other "{prefix}.*" keys and also the bare
/// "{prefix}" key.
pub fn prune_by_is_none(mut v: Value) -> Value {
let obj: &mut Map<String, Value> =
v.as_object_mut().expect("prune_by_is_none: expected a JSON object");
Expand All @@ -115,9 +116,13 @@ pub fn prune_by_is_none(mut v: Value) -> Value {
}
}

// Remove keys that begin with any such prefix, except the "#is_none" flag itself
// Remove keys that begin with any such prefix, or equal the bare prefix, except the "#is_none"
// flag itself
obj.retain(|k, _| {
if let Some(p) = unset_optional_param_paths.iter().find(|p| k.starts_with(&***p)) {
if let Some(p) = unset_optional_param_paths
.iter()
.find(|p| k.starts_with(&***p) || k.as_str() == p.trim_end_matches(FIELD_SEPARATOR))
{
// keep only the "{prefix}.#is_none" key
k == &format!("{p}{IS_NONE_MARK}")
} else {
Expand Down Expand Up @@ -202,6 +207,7 @@ impl DeploymentBaseAppConfig {

// Extract only the required fields from the config map.
let preset = config_to_preset(&config_as_map);
let preset = prune_by_is_none(preset);
validate_all_pointer_targets_set(preset.clone()).expect("Pointer target not set");
preset
}
Expand Down
4 changes: 3 additions & 1 deletion crates/apollo_node_config/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::collections::HashMap;

use apollo_config::dumping::{ConfigPointers, Pointers};
use apollo_config::{ParamPath, SerializedContent, SerializedParam};
use serde_json::{to_value, Value};
#[cfg(any(feature = "testing", test))]
use serde_json::to_value;
use serde_json::Value;

#[derive(Debug, Clone, Default)]
pub struct ConfigPointersMap(HashMap<ParamPath, (SerializedParam, Pointers)>);
Expand Down