mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-01-31 07:17:22 +01:00
feat(aa-log): improve the regex helper type.
This commit is contained in:
parent
84247e390c
commit
e3545cc3bb
4 changed files with 12 additions and 9 deletions
|
@ -71,9 +71,7 @@ func (t *TestSuite) Write(path *paths.Path) error {
|
||||||
`{{`, `{{ `,
|
`{{`, `{{ `,
|
||||||
`}}`, ` }}`,
|
`}}`, ` }}`,
|
||||||
})
|
})
|
||||||
for _, aa := range regClean {
|
res = regClean.Replace(res)
|
||||||
res = aa.Regex.ReplaceAllLiteralString(res, aa.Repl)
|
|
||||||
}
|
|
||||||
_, err = file.WriteString("---\n" + res)
|
_, err = file.WriteString("---\n" + res)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,7 @@ func GetApparmorLogs(file io.Reader, profile string) []string {
|
||||||
|
|
||||||
// Clean & remove doublon in logs
|
// Clean & remove doublon in logs
|
||||||
res = util.DecodeHexInString(res)
|
res = util.DecodeHexInString(res)
|
||||||
for _, aa := range regCleanLogs {
|
res = regCleanLogs.Replace(res)
|
||||||
res = aa.Regex.ReplaceAllLiteralString(res, aa.Repl)
|
|
||||||
}
|
|
||||||
logs := strings.Split(res, "\n")
|
logs := strings.Split(res, "\n")
|
||||||
return util.RemoveDuplicate(logs)
|
return util.RemoveDuplicate(logs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,9 +184,7 @@ func DirectiveStack(file *paths.Path, profile string) string {
|
||||||
panic(fmt.Sprintf("No profile found in %s", name))
|
panic(fmt.Sprintf("No profile found in %s", name))
|
||||||
}
|
}
|
||||||
stackedRules := m[1]
|
stackedRules := m[1]
|
||||||
for _, aa := range regCleanStakedRules {
|
stackedRules = regCleanStakedRules.Replace(stackedRules)
|
||||||
stackedRules = aa.Regex.ReplaceAllLiteralString(stackedRules, aa.Repl)
|
|
||||||
}
|
|
||||||
res += " # Stacked profile: " + name + "\n" + stackedRules + "\n"
|
res += " # Stacked profile: " + name + "\n" + stackedRules + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RegexReplList []RegexRepl
|
||||||
|
|
||||||
type RegexRepl struct {
|
type RegexRepl struct {
|
||||||
Regex *regexp.Regexp
|
Regex *regexp.Regexp
|
||||||
Repl string
|
Repl string
|
||||||
|
@ -58,3 +60,10 @@ func ToRegexRepl(in []string) []RegexRepl {
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rr RegexReplList) Replace(str string) string {
|
||||||
|
for _, aa := range rr {
|
||||||
|
str = aa.Regex.ReplaceAllLiteralString(str, aa.Repl)
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue