feat: add support to forward x-request-id to keymanager service (#5803)

This commit is contained in:
Arjun Karthik
2024-09-06 19:54:45 +05:30
committed by GitHub
parent a03ad53e43
commit 36cd5c1c41
5 changed files with 28 additions and 11 deletions

View File

@ -23,6 +23,8 @@ use crate::{
const CONTENT_TYPE: &str = "Content-Type";
static ENCRYPTION_API_CLIENT: OnceCell<reqwest::Client> = OnceCell::new();
static DEFAULT_ENCRYPTION_VERSION: &str = "v1";
#[cfg(feature = "km_forward_x_request_id")]
const X_REQUEST_ID: &str = "X-Request-Id";
/// Get keymanager client constructed from the url and state
#[instrument(skip_all)]
@ -104,18 +106,25 @@ where
let url = format!("{}/{endpoint}", &state.url);
logger::info!(key_manager_request=?request_body);
let mut header = vec![];
header.push((
HeaderName::from_str(CONTENT_TYPE)
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
HeaderValue::from_str("application/json")
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
));
#[cfg(feature = "km_forward_x_request_id")]
if let Some(request_id) = state.request_id {
header.push((
HeaderName::from_str(X_REQUEST_ID)
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
HeaderValue::from_str(request_id.as_hyphenated().to_string().as_str())
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
))
}
let response = send_encryption_request(
state,
HeaderMap::from_iter(
vec![(
HeaderName::from_str(CONTENT_TYPE)
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
HeaderValue::from_str("application/json")
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
)]
.into_iter(),
),
HeaderMap::from_iter(header.into_iter()),
url,
method,
request_body,