File tree Expand file tree Collapse file tree 1 file changed +6
-24
lines changed Expand file tree Collapse file tree 1 file changed +6
-24
lines changed Original file line number Diff line number Diff line change @@ -2,36 +2,18 @@ package iptables
22
33import (
44 "fmt"
5+ "os/exec"
6+ "strings"
7+
58 "github.com/go-logr/logr"
69 "github.com/jodevsa/wireguard-operator/pkg/agent"
710 "github.com/jodevsa/wireguard-operator/pkg/api/v1alpha1"
8- "os"
9- "os/exec"
10- "strings"
1111)
1212
1313func ApplyRules (rules string ) error {
14- file , err := os .CreateTemp ("/tmp" , "iptables-" )
15- if err != nil {
16- return err
17- }
18- defer os .RemoveAll (file .Name ())
19-
20- err = os .WriteFile (file .Name (), []byte (rules ), 0640 )
21-
22- if err != nil {
23- return err
24- }
25-
26- bashCommand := fmt .Sprintf ("iptables-restore < %s" , file .Name ())
27- cmd := exec .Command ("bash" , "-c" , bashCommand )
28-
29- err = cmd .Run ()
30- if err != nil {
31- return err
32- }
33-
34- return nil
14+ cmd := exec .Command ("iptables-restore" )
15+ cmd .Stdin = strings .NewReader (rules )
16+ return cmd .Run ()
3517}
3618
3719type Iptables struct {
You can’t perform that action at this time.
0 commit comments