mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-14 23:43:56 +01:00
feat(prebuild): add builder opt to build tasks.
This commit is contained in:
parent
02e3334949
commit
2dd6046697
@ -30,6 +30,6 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (b ABI3) Apply(profile string) (string, error) {
|
||||
func (b ABI3) Apply(opt *Option, profile string) (string, error) {
|
||||
return regAbi4To3.Replace(profile), nil
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (b Complain) Apply(profile string) (string, error) {
|
||||
func (b Complain) Apply(opt *Option, profile string) (string, error) {
|
||||
flags := []string{}
|
||||
matches := regFlags.FindStringSubmatch(profile)
|
||||
if len(matches) != 0 {
|
||||
|
@ -7,6 +7,7 @@ package builder
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/arduino/go-paths-helper"
|
||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||
)
|
||||
|
||||
@ -21,7 +22,20 @@ var (
|
||||
// Main directive interface
|
||||
type Builder interface {
|
||||
cfg.BaseInterface
|
||||
Apply(profile string) (string, error)
|
||||
Apply(opt *Option, profile string) (string, error)
|
||||
}
|
||||
|
||||
// Builder options
|
||||
type Option struct {
|
||||
Name string
|
||||
File *paths.Path
|
||||
}
|
||||
|
||||
func NewOption(file *paths.Path) *Option {
|
||||
return &Option{
|
||||
Name: file.Base(),
|
||||
File: file,
|
||||
}
|
||||
}
|
||||
|
||||
func Register(names ...string) {
|
||||
@ -37,3 +51,15 @@ func Register(names ...string) {
|
||||
func RegisterBuilder(d Builder) {
|
||||
Builders[d.Name()] = d
|
||||
}
|
||||
|
||||
func Run(file *paths.Path, profile string) (string, error) {
|
||||
var err error
|
||||
opt := NewOption(file)
|
||||
for _, b := range Builds {
|
||||
profile, err = b.Apply(opt, profile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return profile, nil
|
||||
}
|
||||
|
@ -238,7 +238,8 @@ func TestBuilder_Apply(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := tt.b.Apply(tt.profile)
|
||||
opt := &Option{}
|
||||
got, err := tt.b.Apply(opt, tt.profile)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Builder.Apply() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
|
@ -31,6 +31,6 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (b Dev) Apply(profile string) (string, error) {
|
||||
func (b Dev) Apply(opt *Option, profile string) (string, error) {
|
||||
return regDev.Replace(profile), nil
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (b Enforce) Apply(profile string) (string, error) {
|
||||
func (b Enforce) Apply(opt *Option, profile string) (string, error) {
|
||||
matches := regFlags.FindStringSubmatch(profile)
|
||||
if len(matches) == 0 {
|
||||
return profile, nil
|
||||
|
@ -28,6 +28,6 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (b FullSystemPolicy) Apply(profile string) (string, error) {
|
||||
func (b FullSystemPolicy) Apply(opt *Option, profile string) (string, error) {
|
||||
return regFullSystemPolicy.Replace(profile), nil
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (b Userspace) Apply(profile string) (string, error) {
|
||||
func (b Userspace) Apply(opt *Option, profile string) (string, error) {
|
||||
p := aa.DefaultTunables()
|
||||
p.ParseVariables(profile)
|
||||
p.ResolveAttachments()
|
||||
|
@ -83,11 +83,9 @@ func Build() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, b := range builder.Builds {
|
||||
profile, err = b.Apply(profile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
profile, err = builder.Run(file, profile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
profile, err = directive.Run(file, profile)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user