Offline sensitive-data detection, redaction, JSON and streaming pipelines for MoonBit applications.
pub(all) struct BatchResult {
lines : Array[String]
summary : BatchSummary
changed_indices : Array[Int]
} derive(Eq, Debug)pub(all) struct BatchSummary {
lines : Int
changed_lines : Int
findings : Int
access_tokens : Int
bearer_tokens : Int
jwts : Int
credentials : Int
emails : Int
ipv4s : Int
payment_cards : Int
private_keys : Int
url_credentials : Int
custom_secrets : Int
resident_ids : Int
mac_addresses : Int
uuids : Int
ipv6s : Int
phones : Int
public_keys : Int
wallet_addresses : Int
webhook_urls : Int
high_entropy_secrets : Int
} derive(Eq, Debug)type ChunkScannertest {
let scanner = @moon_scrub.ChunkScanner::new(overlap=64)
ignore(scanner.push("password=hunter2 padding padding padding padding"))
inspect(scanner.finish().length(), content="1")
}test {
let scanner = @moon_scrub.ChunkScanner::new(overlap=64)
inspect(
scanner
.push(
"token=ghp_1234567890abcdefghij " +
"padding padding padding padding padding padding padding padding",
)
.length(),
content="1",
)
}pub(all) struct Finding {
kind : SensitiveKind
start : Int
end : Int
confidence : Confidence
} derive(Eq, Debug)pub(all) struct JsonRedactionResult {
text : String
changed_fields : Int
findings : Array[JsonFinding]
parsed : Bool
} derive(Eq, Debug)pub(all) struct ScanConfig {
detect_access_token : Bool
detect_bearer : Bool
detect_jwt : Bool
detect_private_key : Bool
detect_url_credential : Bool
detect_assignment : Bool
detect_email : Bool
detect_ipv4 : Bool
detect_payment_card : Bool
detect_resident_id : Bool
detect_webhook : Bool
detect_wallet : Bool
detect_public_key : Bool
detect_phone : Bool
detect_high_entropy : Bool
detect_ipv6 : Bool
detect_uuid : Bool
detect_mac : Bool
suppress_version_ipv4 : Bool
require_known_card_prefix : Bool
suppress_example_domains : Bool
extra_prefixes : Array[TokenPrefixRule]
extra_patterns : Array[PatternRule]
} derive(Eq, Debug)pub(all) struct StructuredResult {
fields : Array[StructuredFieldResult]
changed_fields : Int
findings : Int
} derive(Eq, Debug)test {
let lines = @moon_scrub.explain("mail a@b.co")
inspect(lines.length(), content="1")
inspect(lines[0], content="EMAIL 5-11 HIGH")
}test {
let rows = @moon_scrub.findings_summary("a@b.co x@y.org")
inspect(rows.length(), content="1")
inspect(rows[0].kind.to_string(), content="EMAIL")
inspect(rows[0].count, content="2")
}test {
let result = @moon_scrub.redact("user=demo@example.com password=x")
inspect(
result.text,
content="user=[REDACTED:EMAIL] password=[REDACTED:CREDENTIAL]",
)
}fn redact_batch(lines : Array[String], style? : RedactionStyle, policy? : ScanPolicy) -> BatchResulttest {
let result = @moon_scrub.redact_batch(["password=x", "plain"])
inspect(result.summary.changed_lines, content="1")
}fn redact_batch_with_config(lines : Array[String], config : ScanConfig, style? : RedactionStyle) -> BatchResultfn redact_except(text : String, keep : Array[String], style? : RedactionStyle, config? : ScanConfig) -> RedactionResultfn redact_fields(fields : Array[StructuredField], style? : RedactionStyle, policy? : ScanPolicy) -> StructuredResultfn redact_fields_with_config(fields : Array[StructuredField], config : ScanConfig, style? : RedactionStyle) -> StructuredResultfn redact_full(text : String, rules : Array[CustomRule], config : ScanConfig, style? : RedactionStyle) -> RedactionResulttest {
let doc = @moon_scrub.redact_json("{\"k\": \"password=hunter2\"}")
inspect(doc.text, content="{\"k\":\"password=[REDACTED:CREDENTIAL]\"}")
}fn redact_json_with_rules(text : String, rules : Array[CustomRule], config? : ScanConfig, style? : RedactionStyle) -> JsonRedactionResultfn redact_with_config(text : String, config : ScanConfig, style? : RedactionStyle) -> RedactionResultfn redact_with_rules(text : String, rules : Array[CustomRule], style? : RedactionStyle, policy? : ScanPolicy) -> RedactionResulttest {
let kept = @moon_scrub.scan_except("ip 10.0.0.1 ip 10.0.0.2", ["10.0.0.1"])
inspect(kept.length(), content="1")
}test {
let config = @moon_scrub.ScanConfig::secrets_only()
let findings = @moon_scrub.scan_with_config("ip 10.0.0.8", config)
inspect(findings.length(), content="0")
}fn scan_with_rules(text : String, rules : Array[CustomRule], policy? : ScanPolicy) -> Array[Finding]test {
let clean = @moon_scrub.redact("password=hunter2").text
inspect(@moon_scrub.verify_clean(clean), content="true")
}Install
Download zipOffline sensitive-data detection, redaction, JSON and streaming pipelines for MoonBit applications.