Skip to content

Commit

Permalink
Deal with more types & json encode values
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Oct 23, 2024
1 parent b4d0b8b commit ed2b256
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/data/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use chrono::{DateTime, FixedOffset};
use log::{debug, error};
use protobuf::well_known_types::Struct;
use proxy_wasm::hostcalls;
use serde_json::Value;

pub const KUADRANT_NAMESPACE: &str = "kuadrant";

Expand Down Expand Up @@ -179,12 +180,25 @@ fn process_metadata(s: &Struct, prefix: String) -> Vec<(String, String)> {
format!("{prefix}\\.{key}")
};

if value.has_string_value() {
result.push((current_prefix, value.get_string_value().to_string()));
} else if value.has_struct_value() {
let json: Option<Value> = if value.has_string_value() {
Some(value.get_string_value().into())
} else if value.has_bool_value() {
Some(value.get_bool_value().into())
} else if value.has_null_value() {
Some(Value::Null)
} else if value.has_number_value() {
Some(value.get_number_value().into())
} else {
None
};

if value.has_struct_value() {
let nested_struct = value.get_struct_value();
result.extend(process_metadata(nested_struct, current_prefix));
} else if let Some(v) = json {
result.push((current_prefix, serde_json::to_string(&v).unwrap()));
}

}
result
}
Expand Down

0 comments on commit ed2b256

Please sign in to comment.