feat(build): simplify some internal tooling.
This commit is contained in:
parent
791459e39a
commit
1915fa5175
14 changed files with 140 additions and 121 deletions
|
|
@ -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{}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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...`,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue