Skip to main content

redact_discovery_token

Function redact_discovery_token 

Source
pub fn redact_discovery_token(line: &str) -> Cow<'_, str>
Expand description

Redacts the token value from a discovery line for safe logging/display.

Given a log line that may contain a devtools discovery announcement (e.g., frust-devtools listening on 54321 token abc123def456), returns it with the token value replaced by <redacted>. This is used to strip the authentication token from human-visible logs where it should not be exposed.

If the line does not contain DISCOVERY_PREFIX or no [TOKEN_MARKER] follows the port, returns the line unchanged (borrowed, no allocation).

Like parse_discovery_line, uses substring (not anchored) search to tolerate host-logger prefixes (timestamps, tags, etc.).

ยงExamples

use frust_devtools_protocol::redact_discovery_token;
use std::borrow::Cow;

// Redact a token
let with_token = "frust-devtools listening on 54321 token abc123";
let redacted = redact_discovery_token(with_token);
assert_eq!(redacted.as_ref(), "frust-devtools listening on 54321 token <redacted>");

// Line without a token is returned borrowed (no allocation)
let without_token = "frust-devtools listening on 54321";
let unchanged = redact_discovery_token(without_token);
assert!(matches!(unchanged, Cow::Borrowed(_)));