use super::RedactionBatchDiagnostics;
use super::RedactionBatchHandle;
use super::RedactionBatchOutput;
use crate::domain::Redact;
use crate::runtime::BatchSession;
use crate::runtime::RedactionHandle;
pub struct RedactionBatch {
session: BatchSession,
}
impl RedactionBatch {
#[must_use]
pub(crate) const fn from_session(session: BatchSession) -> Self {
Self { session }
}
#[must_use]
pub fn redact_field<T>(&mut self, field: &str, value: &T) -> RedactionBatchHandle
where
T: std::fmt::Display + ?Sized,
{
let handle = self.session.redact_field(field, value);
let (batch_id, item_index) = handle.parts();
RedactionBatchHandle { batch_id, item_index }
}
#[must_use]
pub fn redact_value<T>(&mut self, value: &T) -> RedactionBatchHandle
where
T: Redact + ?Sized,
{
let handle = self.session.redact_value(value);
let (batch_id, item_index) = handle.parts();
RedactionBatchHandle { batch_id, item_index }
}
#[must_use]
pub fn redact_argv<'items, I>(&mut self, items: I) -> RedactionBatchHandle
where
I: IntoIterator<Item = crate::formats::argv::ArgvItem<'items>>,
{
Self::wrap(self.session.redact_argv(items))
}
#[must_use]
pub fn redact_heuristic_argv<'items, I>(&mut self, items: I) -> RedactionBatchHandle
where
I: IntoIterator<Item = crate::formats::argv::ArgvItem<'items>>,
{
Self::wrap(self.session.redact_heuristic_argv(items))
}
#[must_use]
pub fn redact_env(&mut self, name: &str, value: &str) -> RedactionBatchHandle {
Self::wrap(self.session.redact_env(name, value))
}
#[must_use]
pub fn redact_env_pairs<'items, I>(&mut self, pairs: I) -> RedactionBatchHandle
where
I: IntoIterator<Item = (&'items std::ffi::OsStr, &'items std::ffi::OsStr)>,
{
Self::wrap(self.session.redact_env_pairs(pairs))
}
#[must_use]
pub fn redact_process<'arguments, 'variables, A, E>(
&mut self,
program: &'arguments std::ffi::OsStr,
arguments: A,
variables: E,
) -> RedactionBatchHandle
where
A: IntoIterator<Item = crate::formats::argv::ArgvItem<'arguments>>,
E: IntoIterator<Item = (&'variables std::ffi::OsStr, &'variables std::ffi::OsStr)>,
{
Self::wrap(self.session.redact_process(program, arguments, variables))
}
#[cfg(feature = "json")]
#[must_use]
pub fn redact_json(&mut self, text: &str) -> RedactionBatchHandle {
Self::wrap(self.session.redact_json(text))
}
#[cfg(feature = "json")]
#[must_use]
pub fn redact_json_value(&mut self, value: &serde_json::Value) -> RedactionBatchHandle {
Self::wrap(self.session.redact_json_value(value))
}
#[cfg(feature = "http")]
#[must_use]
pub fn redact_http_url(&mut self, value: &str) -> RedactionBatchHandle {
Self::wrap(self.session.redact_http_url(value))
}
#[cfg(feature = "http")]
#[must_use]
pub fn redact_http_headers(&mut self, headers: &http::HeaderMap) -> RedactionBatchHandle {
Self::wrap(self.session.redact_http_headers(headers))
}
#[cfg(feature = "http")]
#[must_use]
pub fn redact_http_body(
&mut self,
capture: crate::formats::http::BodyCapture<'_>,
content_type: Option<&http::HeaderValue>,
) -> RedactionBatchHandle {
Self::wrap(self.session.redact_http_body(capture, content_type))
}
#[cfg(feature = "http")]
#[must_use]
pub fn redact_http_body_with_content_type_text(
&mut self,
capture: crate::formats::http::BodyCapture<'_>,
content_type: Option<&str>,
) -> RedactionBatchHandle {
Self::wrap(
self.session
.redact_http_body_with_content_type_text(capture, content_type),
)
}
#[cfg(feature = "uri")]
#[must_use]
pub fn redact_uri(&mut self, value: &str) -> RedactionBatchHandle {
Self::wrap(self.session.redact_uri(value))
}
#[must_use]
pub(crate) fn finish(self) -> RedactionBatchOutput {
RedactionBatchOutput::from_publication(self.session.finish())
}
#[must_use]
#[inline]
pub fn finish_for_diagnostics(self, marker: &str) -> RedactionBatchDiagnostics {
RedactionBatchDiagnostics::new(self.finish(), marker)
}
fn wrap(handle: RedactionHandle) -> RedactionBatchHandle {
let (batch_id, item_index) = handle.parts();
RedactionBatchHandle { batch_id, item_index }
}
}