Route generic App and CLI code through lifecycle and driver models. Move native macOS detail, create, settings and legacy flows into explicit files, share progress and redaction through host, and enforce the boundary with a file-scoped architecture ratchet.
37 lines
1.5 KiB
Go
37 lines
1.5 KiB
Go
// Package redact provides host-wide secret and identifier redaction.
|
|
package host
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
reLogMac = regexp.MustCompile(`(?i)\b(mac(?:_?address)?[\s:=]+)["']?[0-9a-f]{2}(?:[:-][0-9a-f]{2}){5}["']?`)
|
|
reLogSerialKV = regexp.MustCompile(`(?i)\b((?:system)?serial(?:_?number)?\s*[:=]\s*|mlb\s*[:=]\s*|smuuid\s*[:=]\s*)["']?[A-Za-z0-9-]{8,}["']?`)
|
|
reLogSerialSp = regexp.MustCompile(`(?i)\b(serial\s+)["']?(?-i:[A-Z0-9]{8,})["']?`)
|
|
reLogOSK = regexp.MustCompile(`(?i)\b(osk\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,"']+)`)
|
|
reLogBearer = regexp.MustCompile(`(?i)((?:Bearer|Basic|Authorization:\s*token)\s+)[A-Za-z0-9._~+/=-]{16,}`)
|
|
reLogTokenKV = regexp.MustCompile(`(?i)((?:REIMS_TOKEN|GITHUB_TOKEN|access_token|auth_token|token|"token")\s*[:=]\s*["']?)[A-Za-z0-9._~+/-]{16,}(["']?)`)
|
|
)
|
|
|
|
// Line removes identifiers and credentials before one line is emitted or exported.
|
|
func RedactLine(line string) string {
|
|
line = reLogMac.ReplaceAllString(line, "${1}[redacted]")
|
|
line = reLogSerialKV.ReplaceAllString(line, "${1}[redacted]")
|
|
line = reLogSerialSp.ReplaceAllString(line, "${1}[redacted]")
|
|
line = reLogOSK.ReplaceAllString(line, "${1}[redacted]")
|
|
line = reLogBearer.ReplaceAllString(line, "${1}[redacted]")
|
|
line = reLogTokenKV.ReplaceAllString(line, "${1}[redacted]${2}")
|
|
return line
|
|
}
|
|
|
|
// Text applies Line across a multi-line log or JSON text block.
|
|
func RedactText(s string) string {
|
|
lines := strings.Split(s, "\n")
|
|
for i, line := range lines {
|
|
lines[i] = RedactLine(line)
|
|
}
|
|
return strings.Join(lines, "\n")
|
|
}
|