You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RedactWithstring`alloy:"redact_with,attr,optional"`// Redact the secret with this string. Use $SECRET_NAME and $SECRET_HASH to include the secret name and hash
38
+
PartialMaskuint`alloy:"partial_mask,attr,optional"`// Show the first N characters of the secret (default: 0)
36
39
OriginLabelstring`alloy:"origin_label,attr,optional"`// The label name to use for tracking metrics by origin (if empty, no origin metrics are collected)
redacted:=component.redactLine("This is a very short secret ab in a log line", "ab", "test-rule")
630
+
require.Equal(t, "This is a very short secret <REDACTED-SECRET:test-rule> in a log line", redacted)
631
+
632
+
// Too short to be partially masked
633
+
redacted=component.redactLine("This is a short secret abc12 in a log line", "abc12", "test-rule")
634
+
require.Equal(t, "This is a short secret <REDACTED-SECRET:test-rule> in a log line", redacted)
635
+
636
+
// Will be partially masked (limited by secret length)
637
+
redacted=component.redactLine("This is a longer secret abc123 in a log line", "abc123", "test-rule")
638
+
require.Equal(t, "This is a longer secret abc<REDACTED-SECRET:test-rule> in a log line", redacted)
639
+
640
+
// Will be partially masked
641
+
redacted=component.redactLine("This is a long enough secret abcd1234 in a log line", "abcd1234", "test-rule")
642
+
require.Equal(t, "This is a long enough secret abcd<REDACTED-SECRET:test-rule> in a log line", redacted)
643
+
644
+
// Will be partially masked
645
+
redacted=component.redactLine("This is the longest secret abcdef12345678 in a log line", "abcdef12345678", "test-rule")
646
+
require.Equal(t, "This is the longest secret abcd<REDACTED-SECRET:test-rule> in a log line", redacted)
647
+
648
+
// Test with a non-ASCII character
649
+
redacted=component.redactLine("This is a line with a complex secret aBc\U0001f512De\U0001f5124 in a log line", "aBc\U0001f512De\U0001f5124", "test-rule")
650
+
require.Equal(t, "This is a line with a complex secret aBc\U0001f512<REDACTED-SECRET:test-rule> in a log line", redacted)
651
+
652
+
// Test with different secret lengths and partial masking values
0 commit comments