moby/contrib/apparmor/main.go
Sebastiaan van Stijn 73894af9ff
contrib/apparmor: format code with gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-24 17:59:35 +02:00

44 lines
918 B
Go

package main
import (
"fmt"
"log"
"os"
"path"
"text/template"
)
type profileData struct{}
func main() {
if len(os.Args) < 2 {
log.Fatal("pass a filename to save the profile in.")
}
// parse the arg
apparmorProfilePath := os.Args[1]
// parse the template
compiled, err := template.New("apparmor_profile").Parse(dockerProfileTemplate)
if err != nil {
log.Fatalf("parsing template failed: %v", err)
}
// make sure /etc/apparmor.d exists
if err := os.MkdirAll(path.Dir(apparmorProfilePath), 0o755); err != nil {
log.Fatal(err)
}
f, err := os.OpenFile(apparmorProfilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
data := profileData{}
if err := compiled.Execute(f, data); err != nil {
log.Fatalf("executing template failed: %v", err)
}
fmt.Printf("created apparmor profile for version %+v at %q\n", data, apparmorProfilePath)
}