diff --git a/pkg/aa/profile_test.go b/pkg/aa/profile_test.go index 7aeaf274..30f0ec90 100644 --- a/pkg/aa/profile_test.go +++ b/pkg/aa/profile_test.go @@ -37,9 +37,7 @@ func TestAppArmorProfile_String(t *testing.T) { { name: "empty", p: &AppArmorProfile{}, - want: `profile { -} -`, + want: ``, }, { name: "foo", diff --git a/pkg/aa/templates/profile.j2 b/pkg/aa/templates/profile.j2 index 1c923b75..f275a1d0 100644 --- a/pkg/aa/templates/profile.j2 +++ b/pkg/aa/templates/profile.j2 @@ -22,20 +22,22 @@ {{ "@{" }}{{ .Name }}{{ "} = " }}{{ join .Values }} {{ end -}} -{{- "profile" -}} -{{- with .Name -}} - {{ " " }}{{ . }} +{{- if or .Name .Attachments .Attributes .Flags -}} + {{- "profile" -}} + {{- with .Name -}} + {{ " " }}{{ . }} + {{- end -}} + {{- with .Attachments -}} + {{ " " }}{{ join . }} + {{- end -}} + {{- with .Attributes -}} + {{ " xattrs=(" }}{{ join . }}{{ ")" }} + {{- end -}} + {{- with .Flags -}} + {{ " flags=(" }}{{ join . }}{{ ")" }} + {{- end -}} + {{ " {\n" }} {{- end -}} -{{- with .Attachments -}} - {{ " " }}{{ join . }} -{{- end -}} -{{- with .Attributes -}} - {{ " xattrs=(" }}{{ join . }}{{ ")" }} -{{- end -}} -{{- with .Flags -}} - {{ " flags=(" }}{{ join . }}{{ ")" }} -{{- end -}} -{{ " {\n" }} {{- $oldtype := "" -}} {{- range .Rules -}} @@ -288,4 +290,6 @@ {{- $oldtype = $type -}} {{- end -}} -{{- "}\n" -}} \ No newline at end of file +{{- if or .Name .Attachments .Attributes .Flags -}} + {{- "}\n" -}} +{{- end -}}