feat(build): simplify some internal tooling.

This commit is contained in:
Alexandre Pujol 2024-04-02 17:48:03 +01:00
parent 791459e39a
commit 1915fa5175
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
14 changed files with 140 additions and 121 deletions

View file

@ -13,10 +13,10 @@ import (
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
)
// Define the directive keyword globally
const Keyword = "#aa:"
var (
// Define the directive keyword globally
Keyword = "#aa:"
// Build the profiles with the following directive applied
Directives = map[string]Directive{}

View file

@ -9,6 +9,7 @@ import (
"github.com/roddhjav/apparmor.d/pkg/aa"
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
"github.com/roddhjav/apparmor.d/pkg/util"
"golang.org/x/exp/slices"
)
@ -21,7 +22,7 @@ func init() {
Base: cfg.Base{
Keyword: "exec",
Msg: "Exec directive applied",
Help: `#aa:exec [P|U|p|u|PU|pu|] profiles...`,
Help: Keyword + `exec [P|U|p|u|PU|pu|] profiles...`,
},
})
}
@ -37,12 +38,7 @@ func (d Exec) Apply(opt *Option, profile string) string {
p := &aa.AppArmorProfile{}
for name := range opt.ArgMap {
content, err := cfg.RootApparmord.Join(name).ReadFile()
if err != nil {
panic(err)
}
profiletoTransition := string(content)
profiletoTransition := util.MustReadFile(cfg.RootApparmord.Join(name))
dstProfile := aa.DefaultTunables()
dstProfile.ParseVariables(profiletoTransition)
for _, variable := range dstProfile.Variables {

View file

@ -25,14 +25,14 @@ func init() {
Base: cfg.Base{
Keyword: "only",
Msg: "Only directive applied",
Help: `#aa:only filters...`,
Help: Keyword + `only filters...`,
},
})
RegisterDirective(&FilterExclude{
Base: cfg.Base{
Keyword: "exclude",
Msg: "Exclude directive applied",
Help: `#aa:exclude filters...`,
Help: Keyword + `exclude filters...`,
},
})
}

View file

@ -33,7 +33,7 @@ func init() {
Base: cfg.Base{
Keyword: "stack",
Msg: "Stack directive applied",
Help: `#aa:stack profiles...`,
Help: Keyword + `stack profiles...`,
},
})
}
@ -41,12 +41,7 @@ func init() {
func (s Stack) Apply(opt *Option, profile string) string {
res := ""
for name := range opt.ArgMap {
tmp, err := cfg.RootApparmord.Join(name).ReadFile()
if err != nil {
panic(err)
}
stackedProfile := string(tmp)
stackedProfile := util.MustReadFile(cfg.RootApparmord.Join(name))
m := regRules.FindStringSubmatch(stackedProfile)
if len(m) < 2 {
panic(fmt.Sprintf("No profile found in %s", name))