Skip to content

Commit da137a7

Browse files
Merge pull request #5134 from AkihiroSuda/dump-apparmor
apparmor: add DumpDefaultProfile
2 parents a72fe7d + 0580bd6 commit da137a7

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

contrib/apparmor/apparmor.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package apparmor
2020

2121
import (
22+
"bytes"
2223
"context"
2324
"io/ioutil"
2425
"os"
@@ -79,3 +80,17 @@ func LoadDefaultProfile(name string) error {
7980
}
8081
return nil
8182
}
83+
84+
// DumpDefaultProfiles dumps the default profile with the given name.
85+
func DumpDefaultProfile(name string) (string, error) {
86+
p, err := loadData(name)
87+
if err != nil {
88+
return "", err
89+
}
90+
91+
var buf bytes.Buffer
92+
if err := generate(p, &buf); err != nil {
93+
return "", err
94+
}
95+
return buf.String(), nil
96+
}

contrib/apparmor/apparmor_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,16 @@ Copyright 2009-2018 Canonical Ltd.
104104
}
105105
}
106106
}
107+
108+
func TestDumpDefaultProfile(t *testing.T) {
109+
if _, err := getVersion(); err != nil {
110+
t.Skipf("AppArmor not available: %+v", err)
111+
}
112+
name := "test-dump-default-profile"
113+
prof, err := DumpDefaultProfile(name)
114+
if err != nil {
115+
t.Fatal(err)
116+
}
117+
t.Logf("Generated profile %q", name)
118+
t.Log(prof)
119+
}

0 commit comments

Comments
 (0)