Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/nerdctl/apparmor_inspect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"

"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/cmd/apparmor"
"github.com/containerd/nerdctl/pkg/defaults"
"github.com/spf13/cobra"
Expand All @@ -38,7 +37,5 @@ func newApparmorInspectCommand() *cobra.Command {
}

func apparmorInspectAction(cmd *cobra.Command, args []string) error {
options := &types.ApparmorInspectCommandOptions{}
options.Writer = cmd.OutOrStdout()
return apparmor.Inspect(options)
return apparmor.Inspect(cmd.OutOrStdout())
}
21 changes: 14 additions & 7 deletions cmd/nerdctl/apparmor_ls_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,25 @@ func newApparmorLsCommand() *cobra.Command {
return cmd
}

func apparmorLsAction(cmd *cobra.Command, args []string) error {
options := &types.ApparmorListCommandOptions{}
func processApparmorListCommandOptions(cmd *cobra.Command) (types.ApparmorListCommandOptions, error) {
quiet, err := cmd.Flags().GetBool("quiet")
if err != nil {
return err
return types.ApparmorListCommandOptions{}, err
}
options.Quiet = quiet
options.Writer = cmd.OutOrStdout()
format, err := cmd.Flags().GetString("format")
if err != nil {
return types.ApparmorListCommandOptions{}, err
}
return types.ApparmorListCommandOptions{
Quiet: quiet,
Format: format,
}, nil
}

func apparmorLsAction(cmd *cobra.Command, args []string) error {
options, err := processApparmorListCommandOptions(cmd)
if err != nil {
return err
}
options.Format = format
return apparmor.List(options)
return apparmor.List(options, cmd.OutOrStdout())
}
5 changes: 1 addition & 4 deletions cmd/nerdctl/apparmor_unload_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"

"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/cmd/apparmor"
"github.com/containerd/nerdctl/pkg/defaults"
"github.com/spf13/cobra"
Expand All @@ -43,9 +42,7 @@ func apparmorUnloadAction(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
target = args[0]
}
options := &types.ApparmorUnloadCommandOptions{}
options.Target = target
return apparmor.Unload(options)
return apparmor.Unload(target)
}

func apparmorUnloadShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
14 changes: 0 additions & 14 deletions pkg/api/types/apparmor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,9 @@

package types

import "io"

type ApparmorInspectCommandOptions struct {
// Writer is the output writer
Writer io.Writer
}

type ApparmorUnloadCommandOptions struct {
// Target is the profile name
Target string
}

type ApparmorListCommandOptions struct {
// Only display profile names
Quiet bool
// Format the output using the given go template
Format string
// Writer is the output writer
Writer io.Writer
}
6 changes: 3 additions & 3 deletions pkg/cmd/apparmor/inspect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ package apparmor

import (
"fmt"
"io"

"github.com/containerd/containerd/contrib/apparmor"
"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/defaults"
)

func Inspect(options *types.ApparmorInspectCommandOptions) error {
func Inspect(stdout io.Writer) error {
b, err := apparmor.DumpDefaultProfile(defaults.AppArmorProfileName)
if err != nil {
return err
}
_, err = fmt.Fprint(options.Writer, b)
_, err = fmt.Fprint(stdout, b)
return err
}
7 changes: 4 additions & 3 deletions pkg/cmd/apparmor/list_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"io"
"text/tabwriter"
"text/template"

Expand All @@ -28,14 +29,14 @@ import (
"github.com/containerd/nerdctl/pkg/formatter"
)

func List(options *types.ApparmorListCommandOptions) error {
func List(options types.ApparmorListCommandOptions, stdout io.Writer) error {
quiet := options.Quiet
w := options.Writer
w := stdout
var tmpl *template.Template
format := options.Format
switch format {
case "", "table", "wide":
w = tabwriter.NewWriter(options.Writer, 4, 8, 4, ' ', 0)
w = tabwriter.NewWriter(stdout, 4, 8, 4, ' ', 0)
if !quiet {
fmt.Fprintln(w, "NAME\tMODE")
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/cmd/apparmor/unload_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package apparmor

import (
"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/apparmorutil"
"github.com/sirupsen/logrus"
)

func Unload(options *types.ApparmorUnloadCommandOptions) error {
logrus.Infof("Unloading profile %q", options.Target)
return apparmorutil.Unload(options.Target)
func Unload(target string) error {
logrus.Infof("Unloading profile %q", target)
return apparmorutil.Unload(target)
}