build: update directives with the new interface.

This commit is contained in:
Alexandre Pujol 2024-03-25 22:40:25 +00:00
parent 38e9e5f08e
commit 08d4110c2a
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
9 changed files with 63 additions and 89 deletions

View file

@ -9,12 +9,10 @@ import (
"regexp"
"strings"
"github.com/arduino/go-paths-helper"
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
"github.com/roddhjav/apparmor.d/pkg/util"
)
var rootApparmord = paths.New(".build/apparmor.d")
var (
regRules = regexp.MustCompile(`(?m)^profile.*{$((.|\n)*)}`)
regEndOfRules = regexp.MustCompile(`(?m)([\t ]*include if exists <.*>\n)+}`)
@ -27,22 +25,23 @@ var (
)
type Stack struct {
DirectiveBase
cfg.Base
}
func init() {
Directives["stack"] = &Stack{
DirectiveBase: DirectiveBase{
message: "Stack directive applied",
usage: `#aa:stack profiles_name...`,
RegisterDirective(&Stack{
Base: cfg.Base{
Keyword: "stack",
Msg: "Stack directive applied",
Help: `#aa:stack profiles...`,
},
}
})
}
func (s Stack) Apply(opt *Option, profile string) string {
res := ""
for name := range opt.ArgMap {
tmp, err := rootApparmord.Join(name).ReadFile()
tmp, err := cfg.RootApparmord.Join(name).ReadFile()
if err != nil {
panic(err)
}