chore: various cosmetic changes.
This commit is contained in:
parent
256d4abde8
commit
aea0034fcc
16 changed files with 35 additions and 32 deletions
|
|
@ -17,7 +17,7 @@ type AppArmorProfiles map[string]*AppArmorProfile
|
|||
// ApparmorProfile represents a full apparmor profile.
|
||||
// Warning: close to the BNF grammar of apparmor profile but not exactly the same (yet):
|
||||
// - Some rules are not supported yet (subprofile, hat...)
|
||||
// - The structure is simplified as it only aims at writting profile, not parsing it.
|
||||
// - The structure is simplified as it only aims at writing profile, not parsing it.
|
||||
type AppArmorProfile struct {
|
||||
Preamble
|
||||
Profile
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ func GetJournalctlLogs(path string, useFile bool) (io.Reader, error) {
|
|||
return strings.NewReader(res), nil
|
||||
}
|
||||
|
||||
func GetLogFile(path string) string {
|
||||
// SelectLogFile return the path of the available log file to parse (audit, syslog, .1, .2)
|
||||
func SelectLogFile(path string) string {
|
||||
info, err := os.Stat(filepath.Clean(path))
|
||||
if err == nil && !info.IsDir() {
|
||||
return path
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func TestGetJournalctlLogs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetLogFile(t *testing.T) {
|
||||
func TestSelectLogFile(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
|
|
@ -77,7 +77,7 @@ func TestGetLogFile(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetLogFile(tt.path); got != tt.want {
|
||||
if got := SelectLogFile(tt.path); got != tt.want {
|
||||
t.Errorf("getLogFile() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ var Builds = []BuildFunc{
|
|||
|
||||
var (
|
||||
regAttachments = regexp.MustCompile(`(profile .* @{exec_path})`)
|
||||
regFlag = regexp.MustCompile(`flags=\(([^)]+)\)`)
|
||||
regFlagComplain = regexp.MustCompile(`flags=\(([^)]+)\)`)
|
||||
regProfileHeader = regexp.MustCompile(` {`)
|
||||
)
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ type BuildFunc func(string) string
|
|||
// Set complain flag on all profiles
|
||||
func BuildComplain(profile string) string {
|
||||
flags := []string{}
|
||||
matches := regFlag.FindStringSubmatch(profile)
|
||||
matches := regFlagComplain.FindStringSubmatch(profile)
|
||||
if len(matches) != 0 {
|
||||
flags = strings.Split(matches[1], ",")
|
||||
if slices.Contains(flags, "complain") {
|
||||
|
|
@ -39,7 +39,7 @@ func BuildComplain(profile string) string {
|
|||
strFlags := " flags=(" + strings.Join(flags, ",") + ") {"
|
||||
|
||||
// Remove all flags definition, then set manifest' flags
|
||||
profile = regFlag.ReplaceAllLiteralString(profile, "")
|
||||
profile = regFlagComplain.ReplaceAllLiteralString(profile, "")
|
||||
return regProfileHeader.ReplaceAllLiteralString(profile, strFlags)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func SetFlags() error {
|
|||
}
|
||||
|
||||
// Remove all flags definition, then set manifest' flags
|
||||
res := regFlag.ReplaceAllLiteralString(string(content), "")
|
||||
res := regFlagComplain.ReplaceAllLiteralString(string(content), "")
|
||||
res = regProfileHeader.ReplaceAllLiteralString(res, flags)
|
||||
if err := file.WriteFile([]byte(res)); err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue