You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
939 B
33 lines
939 B
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"tera-clone/services/tera-api/internal/domain"
|
|
"tera-clone/services/tera-api/internal/logpolicy"
|
|
)
|
|
|
|
func portLogDisplay(event domain.PortLogEvent) domain.PortLogEvent {
|
|
if len(event.Payload) == 0 {
|
|
return event
|
|
}
|
|
text, redacted := logpolicy.SanitizeMultiline(strings.ToValidUTF8(string(event.Payload), "�"), logpolicy.MaxSerialPayloadBytes)
|
|
event.Redacted = event.Redacted || redacted
|
|
bytes := event.Payload
|
|
if event.Redacted {
|
|
bytes = []byte(text)
|
|
}
|
|
ascii := strings.ReplaceAll(strings.ReplaceAll(text, "\r\n", "\n"), "\r", "\n")
|
|
switch event.DisplayFormat {
|
|
case "hex":
|
|
event.DisplayText = fmt.Sprintf("% X", bytes)
|
|
case "ascii_hex":
|
|
event.DisplayText = "ASCII\n" + ascii + "\nHEX\n" + fmt.Sprintf("% X", bytes)
|
|
default:
|
|
event.DisplayText = ascii
|
|
}
|
|
// Raw bytes remain in the journal; API responses expose only the sanitized view.
|
|
event.Payload = nil
|
|
return event
|
|
}
|
|
|