1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/contrib/apparmor/main.go
Jessica Frazelle f8db9a09e0
check version for docker-default aa profile
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2015-11-30 10:18:12 -08:00

58 lines
1.2 KiB
Go

package main
import (
"fmt"
"log"
"os"
"path"
"text/template"
"github.com/docker/docker/pkg/aaparser"
)
type profileData struct {
MajorVersion int
MinorVersion int
}
func main() {
if len(os.Args) < 2 {
log.Fatal("pass a filename to save the profile in.")
}
// parse the arg
apparmorProfilePath := os.Args[1]
majorVersion, minorVersion, err := aaparser.GetVersion()
if err != nil {
log.Fatal(err)
}
data := profileData{
MajorVersion: majorVersion,
MinorVersion: minorVersion,
}
fmt.Printf("apparmor_parser is of version %+v\n", data)
// 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), 0755); err != nil {
log.Fatal(err)
}
f, err := os.OpenFile(apparmorProfilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
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)
}