浏览代码

pkg/aaparser: remove, and integrate into profiles/apparmor

This package provided utilities to obtain the apparmor_parser version, as well
as loading a profile.

Commit e3e715666f95c056390a88e0f3d1033a1aac2762 (included in v24.0.0 through
bfffb0974e92928764845df935d092e6bdcb542d) deprecated GetVersion, as it was no
longer used, which made LoadProfile the only utility remaining in this package.

LoadProfile appears to have no external consumers, and the only use in our code
is "profiles/apparmor".

This patch moves the remaining code (LoadProfile) to profiles/apparmor as a
non-exported function, and deletes the package.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 年之前
父节点
当前提交
6fae583dba
共有 2 个文件被更改,包括 18 次插入25 次删除
  1. 0 22
      pkg/aaparser/aaparser.go
  2. 18 3
      profiles/apparmor/apparmor.go

+ 0 - 22
pkg/aaparser/aaparser.go

@@ -1,22 +0,0 @@
-// Package aaparser is a convenience package interacting with `apparmor_parser`.
-package aaparser // import "github.com/docker/docker/pkg/aaparser"
-
-import (
-	"fmt"
-	"os/exec"
-	"strings"
-)
-
-// LoadProfile runs `apparmor_parser -Kr` on a specified apparmor profile to
-// replace the profile. The `-K` is necessary to make sure that apparmor_parser
-// doesn't try to write to a read-only filesystem.
-func LoadProfile(profilePath string) error {
-	c := exec.Command("apparmor_parser", "-Kr", profilePath)
-	c.Dir = ""
-
-	output, err := c.CombinedOutput()
-	if err != nil {
-		return fmt.Errorf("running `%s %s` failed with output: %s\nerror: %v", c.Path, strings.Join(c.Args, " "), output, err)
-	}
-	return nil
-}

+ 18 - 3
profiles/apparmor/apparmor.go

@@ -4,13 +4,13 @@ package apparmor // import "github.com/docker/docker/profiles/apparmor"
 
 import (
 	"bufio"
+	"fmt"
 	"io"
 	"os"
+	"os/exec"
 	"path"
 	"strings"
 	"text/template"
-
-	"github.com/docker/docker/pkg/aaparser"
 )
 
 // profileDirectory is the file store for apparmor profiles and macros.
@@ -94,7 +94,7 @@ func InstallDefault(name string) error {
 		return err
 	}
 
-	return aaparser.LoadProfile(profilePath)
+	return loadProfile(profilePath)
 }
 
 // IsLoaded checks if a profile with the given name has been loaded into the
@@ -122,3 +122,18 @@ func IsLoaded(name string) (bool, error) {
 
 	return false, nil
 }
+
+// loadProfile runs `apparmor_parser -Kr` on a specified apparmor profile to
+// replace the profile. The `-K` is necessary to make sure that apparmor_parser
+// doesn't try to write to a read-only filesystem.
+func loadProfile(profilePath string) error {
+	c := exec.Command("apparmor_parser", "-Kr", profilePath)
+	c.Dir = ""
+
+	output, err := c.CombinedOutput()
+	if err != nil {
+		return fmt.Errorf("running `%s %s` failed with output: %s\nerror: %v", c.Path, strings.Join(c.Args, " "), output, err)
+	}
+
+	return nil
+}