Skip to content

Commit

Permalink
Use default value if present
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <[email protected]>
  • Loading branch information
adam-cattermole committed Aug 9, 2024
1 parent bc03ad4 commit 40ecfaf
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/policy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::attribute::get_attribute;
use crate::attribute::Attribute;
use crate::configuration::{DataItem, DataType, PatternExpression};
use crate::envoy::{RateLimitDescriptor, RateLimitDescriptor_Entry};
use crate::filter::http_context::Filter;
Expand Down Expand Up @@ -126,7 +126,25 @@ impl Policy {
Some(key) => key.to_owned(),
};

let value = get_attribute(filter, selector_item.selector.as_str()).ok()?;
let attribute_path = selector_item.path();
let value = match filter.get_property(attribute_path.tokens()) {
None => {
debug!(
"#{} build_single_descriptor: selector not found: {}",
filter.context_id, attribute_path
);
match &selector_item.default {
None => return None, // skipping the entire descriptor
Some(default_value) => default_value.clone(),
}
}
// TODO(eastizle): not all fields are strings
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes
Some(attribute_bytes) => Attribute::parse(attribute_bytes)
.inspect_err(|e| debug!("#{} build_single_descriptor: failed to parse selector value: {}, error: {}",
filter.context_id, attribute_path, e))
.ok()?,
};
let mut descriptor_entry = RateLimitDescriptor_Entry::new();
descriptor_entry.set_key(descriptor_key);
descriptor_entry.set_value(value);
Expand Down

0 comments on commit 40ecfaf

Please sign in to comment.