feat(aa-log): parse log file to AA object to allow easy print.
This commit is contained in:
parent
574891d445
commit
d06a474b0c
2 changed files with 82 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/roddhjav/apparmor.d/pkg/aa"
|
||||
"github.com/roddhjav/apparmor.d/pkg/util"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
|
@ -219,3 +220,26 @@ func (aaLogs AppArmorLogs) String() string {
|
|||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ParseToProfiles convert the log data into a new AppArmorProfiles
|
||||
func (aaLogs AppArmorLogs) ParseToProfiles() aa.AppArmorProfiles {
|
||||
profiles := make(aa.AppArmorProfiles, 0)
|
||||
for _, log := range aaLogs {
|
||||
name := ""
|
||||
if strings.Contains(log["operation"], "dbus") {
|
||||
name = log["label"]
|
||||
} else {
|
||||
name = log["profile"]
|
||||
}
|
||||
|
||||
if _, ok := profiles[name]; !ok {
|
||||
profile := &aa.AppArmorProfile{}
|
||||
profile.Name = name
|
||||
profile.AddRule(log)
|
||||
profiles[name] = profile
|
||||
} else {
|
||||
profiles[name].AddRule(log)
|
||||
}
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue