diff --git a/.editorconfig b/.editorconfig index af01f73..6aee114 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,7 @@ indent_style = space insert_final_newline = true max_line_length = 80 trim_trailing_whitespace = true + +[*.rs] +indent_size = 4 +tab_width = 4 diff --git a/src/config.rs b/src/config.rs index 3c281a9..779e0a9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,4 @@ -use {super::error, serde::Deserialize}; +use {super::error, serde::Deserialize, std::str::FromStr}; const DEFAULT_PORT_NUMBER: u16 = 3001; const DEFAULT_LOG_LEVEL: &str = "WARN"; @@ -39,6 +39,10 @@ impl Configuration { pub fn is_valid(&self) -> error::Result<()> { Ok(()) } + + pub fn log_level(&self) -> tracing::Level { + tracing::Level::from_str(self.log_level.as_str()).unwrap_or(tracing::Level::INFO) + } } fn default_port() -> u16 { diff --git a/src/handlers/save_message.rs b/src/handlers/save_message.rs index e57c1f6..9bb1c67 100644 --- a/src/handlers/save_message.rs +++ b/src/handlers/save_message.rs @@ -27,8 +27,7 @@ pub struct HistoryPayload { pub async fn handler( StateExtractor(state): StateExtractor>, - // RequireValidSignature(Json(payload)): RequireValidSignature>, - Json(payload): Json, + RequireValidSignature(Json(payload)): RequireValidSignature>, ) -> error::Result { debug!("Received `save_message` query: {:?}", payload); diff --git a/src/lib.rs b/src/lib.rs index d9d2fdf..181cb9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,6 @@ use { cors::{AllowOrigin, CorsLayer}, trace::{DefaultMakeSpan, DefaultOnRequest, DefaultOnResponse, TraceLayer}, }, - tracing::Level, }; pub mod auth; @@ -101,10 +100,10 @@ pub async fn bootstrap( .layer( TraceLayer::new_for_http() .make_span_with(DefaultMakeSpan::new().include_headers(true)) - .on_request(DefaultOnRequest::new().level(Level::INFO)) + .on_request(DefaultOnRequest::new().level(config.log_level())) .on_response( DefaultOnResponse::new() - .level(Level::INFO) + .level(config.log_level()) .include_headers(true), ), ) diff --git a/src/relay/signature.rs b/src/relay/signature.rs index 07442c7..bca899a 100644 --- a/src/relay/signature.rs +++ b/src/relay/signature.rs @@ -7,6 +7,7 @@ use { MissingTimestampHeader, ToBytesError, }, + log::prelude::*, state::State, }, async_trait::async_trait, @@ -63,14 +64,20 @@ where .and_then(|header| header.to_str().ok()); match (signature_header, timestamp_header) { - (Some(signature), Some(timestamp)) - if signature_is_valid(signature, timestamp, &body, &public_key).await? => - { - let req = Request::::from_parts(parts, bytes.into()); - Ok(T::from_request(req, state) - .await - .map(Self) - .map_err(|_| FromRequestError)?) + (Some(signature), Some(timestamp)) => { + match signature_is_valid(signature, timestamp, &body, &public_key).await { + Ok(_) => { + let req = Request::::from_parts(parts, bytes.into()); + Ok(T::from_request(req, state) + .await + .map(Self) + .map_err(|_| FromRequestError)?) + } + Err(err) => { + warn!("relay signature is not valid: {err:?}"); + Err(err) + } + } } (Some(_), None) => Err(MissingTimestampHeader), (None, Some(_)) => Err(MissingSignatureHeader), diff --git a/terraform/main.tf b/terraform/main.tf index 7be76f4..90374dc 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -89,8 +89,6 @@ module "ecs" { allowed_app_ingress_cidr_blocks = module.vpc.vpc_cidr_block allowed_lb_ingress_cidr_blocks = module.vpc.vpc_cidr_block docdb-connection_url = module.history_docdb.connection_url - - log_level = "DEBUG" } ################################################################################