From 26bd9350f2ada40b324055e55333806b72b5c239 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Mon, 1 May 2023 22:21:30 +0100 Subject: [PATCH] chore(aa-log): make some resource internal only. --- pkg/logs/loggers.go | 7 +++++- pkg/logs/logs.go | 55 +++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/pkg/logs/loggers.go b/pkg/logs/loggers.go index 76504e20..09ae9828 100644 --- a/pkg/logs/loggers.go +++ b/pkg/logs/loggers.go @@ -20,6 +20,11 @@ var LogFiles = []string{ "/var/log/syslog", } +// SystemdLog is a simplified systemd json log representation. +type systemdLog struct { + Message string `json:"MESSAGE"` +} + // GetAuditLogs return a reader with the logs entries from Auditd func GetAuditLogs(path string) (io.Reader, error) { file, err := os.Open(filepath.Clean(path)) @@ -31,7 +36,7 @@ func GetAuditLogs(path string) (io.Reader, error) { // GetJournalctlLogs return a reader with the logs entries from Systemd func GetJournalctlLogs(path string, useFile bool) (io.Reader, error) { - var logs []SystemdLog + var logs []systemdLog var stdout bytes.Buffer var value string diff --git a/pkg/logs/logs.go b/pkg/logs/logs.go index df74b8fd..6cede1d5 100644 --- a/pkg/logs/logs.go +++ b/pkg/logs/logs.go @@ -16,16 +16,16 @@ import ( // Colors const ( - Reset = "\033[0m" - FgGreen = "\033[32m" - FgYellow = "\033[33m" - FgBlue = "\033[34m" - FgMagenta = "\033[35m" - FgCian = "\033[36m" - FgWhite = "\033[37m" - BoldRed = "\033[1;31m" - BoldGreen = "\033[1;32m" - BoldYellow = "\033[1;33m" + reset = "\033[0m" + fgGreen = "\033[32m" + fgYellow = "\033[33m" + fgBlue = "\033[34m" + fgMagenta = "\033[35m" + fgCian = "\033[36m" + fgWhite = "\033[37m" + boldRed = "\033[1;31m" + boldGreen = "\033[1;32m" + boldYellow = "\033[1;33m" ) var ( @@ -47,11 +47,6 @@ type AppArmorLog map[string]string // AppArmorLogs describes all apparmor log entries type AppArmorLogs []AppArmorLog -// SystemdLog is a simplified systemd json log representation. -type SystemdLog struct { - Message string `json:"MESSAGE"` -} - func splitQuoted(r rune) bool { if r == '"' { quoted = !quoted @@ -125,9 +120,9 @@ func NewApparmorLogs(file io.Reader, profile string) AppArmorLogs { func (aaLogs AppArmorLogs) String() string { // Apparmor log states state := map[string]string{ - "DENIED": BoldRed + "DENIED " + Reset, - "ALLOWED": BoldGreen + "ALLOWED" + Reset, - "AUDIT": BoldYellow + "AUDIT " + Reset, + "DENIED": boldRed + "DENIED " + reset, + "ALLOWED": boldGreen + "ALLOWED" + reset, + "AUDIT": boldYellow + "AUDIT " + reset, } // Print order of impression keys := []string{ @@ -140,17 +135,17 @@ func (aaLogs AppArmorLogs) String() string { } // Color template to use colors := map[string]string{ - "profile": FgBlue, - "label": FgBlue, - "operation": FgYellow, - "name": FgMagenta, - "mask": BoldRed, - "bus": FgCian + "bus=", - "path": "path=" + FgWhite, - "requested_mask": "requested_mask=" + BoldRed, - "denied_mask": "denied_mask=" + BoldRed, - "interface": "interface=" + FgWhite, - "member": "member=" + FgGreen, + "profile": fgBlue, + "label": fgBlue, + "operation": fgYellow, + "name": fgMagenta, + "mask": boldRed, + "bus": fgCian + "bus=", + "path": "path=" + fgWhite, + "requested_mask": "requested_mask=" + boldRed, + "denied_mask": "denied_mask=" + boldRed, + "interface": "interface=" + fgWhite, + "member": "member=" + fgGreen, } res := "" for _, log := range aaLogs { @@ -160,7 +155,7 @@ func (aaLogs AppArmorLogs) String() string { for _, key := range keys { if log[key] != "" { if colors[key] != "" { - res += " " + colors[key] + toQuote(log[key]) + Reset + res += " " + colors[key] + toQuote(log[key]) + reset } else { res += " " + key + "=" + toQuote(log[key]) }