File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919package apparmor
2020
2121import (
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+ }
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments