use std::sync::LazyLock;
use regex::Regex;
const SUBJECT_PREVIEW_CHARS: usize = 500;
pub fn redact_subject(subject: &str) -> String {
static SECRET_ASSIGNMENT: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"(?i)\b([A-Za-z0-9_.-]*(?:token|secret|password|passwd|api[_-]?key|apikey|auth|credential)[A-Za-z0-9_.-]*)=(\S+)",
)
.expect("static redaction pattern compiles")
});
static ENV_ASSIGNMENT: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"\b([A-Z][A-Z0-9_]{2,})=(\S+)").expect("static redaction pattern compiles")
});
static HEADER: LazyLock<Regex> = LazyLock::new(|| {
Regex::new("(?i)\\b(authorization|x-api-key|proxy-authorization):[^'\"\n]*")
.expect("static redaction pattern compiles")
});
let redacted = SECRET_ASSIGNMENT.replace_all(subject, "$1=<redacted>");
let redacted = ENV_ASSIGNMENT.replace_all(&redacted, "$1=<redacted>");
let redacted = HEADER.replace_all(&redacted, "$1: <redacted>");
crate::events::preview(&redacted, SUBJECT_PREVIEW_CHARS)
}