Skip to content

Commit

Permalink
Use base64 when logging token, add fmt::Display impl for metadata::Va…
Browse files Browse the repository at this point in the history
…lue (#554)
  • Loading branch information
XAMPPRocky authored Aug 4, 2022
1 parent 4800db4 commit 25d9360
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/config/watch/agones/crd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'de> serde::Deserialize<'de> for GameServer {

serde_json::from_value::<Inner>(value.clone())
.map_err(|error| {
tracing::trace!(%error, ?value, "gameserver failed");
tracing::trace!(%error, %value, "gameserver failed");
Error::custom(error)
})
.map(
Expand Down
2 changes: 1 addition & 1 deletion src/filters/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Filter for Capture {
.insert(self.is_present_key.clone(), Value::Bool(capture.is_some()));

if let Some(value) = capture {
tracing::trace!(key=&**self.metadata_key, value=?value, "captured value");
tracing::trace!(key=&**self.metadata_key, %value, "captured value");
ctx.metadata.insert(self.metadata_key.clone(), value);
Some(ctx.into())
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/filters/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where

match config.branches.iter().find(|(key, _)| key == value) {
Some((value, instance)) => {
tracing::trace!(key=&*config.metadata_key, value=?value, filter=&*instance.0, "Matched against branch");
tracing::trace!(key=&*config.metadata_key, %value, filter=&*instance.0, "Matched against branch");
metrics.packets_matched_total.inc();
(and_then)(ctx, &instance.1)
}
Expand Down
5 changes: 4 additions & 1 deletion src/filters/token_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ impl Filter for TokenRouter {

if ctx.endpoints.is_empty() {
let token: &[u8] = &**token;
tracing::trace!(?token, "No endpoint matched token");
tracing::trace!(
token = &*base64::encode(token),
"No endpoint matched token"
);
self.metrics.packets_dropped_no_endpoint_match.inc();
None
} else {
Expand Down
26 changes: 26 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ impl Value {
}
}

impl std::fmt::Display for Value {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self {
Self::Bool(value) => value.fmt(f),
Self::Number(value) => value.fmt(f),
Self::String(value) => value.fmt(f),
Self::Bytes(value) => base64::encode(value).fmt(f),
Self::List(values) => {
write!(f, "[")?;
let mut first = true;
for value in values {
if first {
first = false;
} else {
write!(f, ",")?;
}

value.fmt(f)?;
}

write!(f, "]")
}
}
}
}

/// Convenience macro for generating From<T> implementations.
macro_rules! from_value {
(($name:ident) { $($typ:ty => $ex:expr),+ $(,)? }) => {
Expand Down

0 comments on commit 25d9360

Please sign in to comment.