diff --git a/pkg/aa/template.go b/pkg/aa/template.go index 8ee6d7562..4f433c091 100644 --- a/pkg/aa/template.go +++ b/pkg/aa/template.go @@ -15,10 +15,10 @@ import ( var ( // Default indentation for apparmor profile (2 spaces) - TemplateIndentation = " " + Indentation = " " // The current indentation level - TemplateIndentationLevel = 0 + IndentationLevel = 0 //go:embed templates/*.j2 //go:embed templates/rule/*.j2 @@ -122,7 +122,7 @@ func renderTemplate(name string, data any) string { var res strings.Builder template, ok := tmpl[name] if !ok { - panic("template not found") + panic("template '" + name + "' not found") } err := template.Execute(&res, data) if err != nil { @@ -188,19 +188,19 @@ func typeToValue(i reflect.Type) string { func setindent(i string) string { switch i { case "++": - TemplateIndentationLevel++ + IndentationLevel++ case "--": - TemplateIndentationLevel-- + IndentationLevel-- } return "" } func indent(s string) string { - return strings.Repeat(TemplateIndentation, TemplateIndentationLevel) + s + return strings.Repeat(Indentation, IndentationLevel) + s } func indentDbus(s string) string { - return strings.Join([]string{TemplateIndentation, s}, " ") + return strings.Join([]string{Indentation, s}, " ") } func getLetterIn(alphabet []string, in string) string { diff --git a/pkg/prebuild/directive/dbus.go b/pkg/prebuild/directive/dbus.go index e1e64a649..f98105b56 100644 --- a/pkg/prebuild/directive/dbus.go +++ b/pkg/prebuild/directive/dbus.go @@ -61,8 +61,8 @@ func (d Dbus) Apply(opt *Option, profile string) string { r = d.talk(opt.ArgMap) } - aa.TemplateIndentationLevel = strings.Count( - strings.SplitN(opt.Raw, Keyword, 1)[0], aa.TemplateIndentation, + aa.IndentationLevel = strings.Count( + strings.SplitN(opt.Raw, Keyword, 1)[0], aa.Indentation, ) generatedDbus := r.String() lenDbus := len(generatedDbus) diff --git a/pkg/prebuild/directive/exec.go b/pkg/prebuild/directive/exec.go index b2899baa5..a7a8c7367 100644 --- a/pkg/prebuild/directive/exec.go +++ b/pkg/prebuild/directive/exec.go @@ -54,8 +54,8 @@ func (d Exec) Apply(opt *Option, profileRaw string) string { } } - aa.TemplateIndentationLevel = strings.Count( - strings.SplitN(opt.Raw, Keyword, 1)[0], aa.TemplateIndentation, + aa.IndentationLevel = strings.Count( + strings.SplitN(opt.Raw, Keyword, 1)[0], aa.Indentation, ) rules.Sort() new := rules.String()