Skip to content

Commit

Permalink
🐛 fix last chunk of command not being applied (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-haley authored Aug 24, 2022
1 parent 12f5cbd commit b16a6df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions pkg/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ func CmdsToData(cmds []string, op string) []api.Cmd {

// mapToCmds maps an interface to an array of VyOS commands
func mapToCmds(top bool, cmds *[]string, nm interface{}, prefix string) error {
assign := func(cmd string, v interface{}, array bool) error {
assign := func(cmd string, v interface{}, array bool, ignoreValue bool) error {
switch v := v.(type) {
case map[string]interface{}, []interface{}:
if err := mapToCmds(false, cmds, v, cmd); err != nil {
return err
}
case string:
if array {
if array || !ignoreValue {
*cmds = append(*cmds, cmd+" "+v)
} else {
*cmds = append(*cmds, cmd)
Expand All @@ -92,29 +92,29 @@ func mapToCmds(top bool, cmds *[]string, nm interface{}, prefix string) error {
res := string(r)

if res == "{}" {
if err := assign(cmd, k, false); err != nil {
if err := assign(cmd, k, false, true); err != nil {
return err
}
continue
}
// again, very crude but check if we're looking at an array of string
if strings.HasPrefix(res, "[") && strings.HasSuffix(res, "]") {
for _, val := range v.([]interface{}) {
if err := assign(cmd, val, true); err != nil {
if err := assign(cmd, val, true, false); err != nil {
return err
}
}
continue
}

if err := assign(cmd, v, false); err != nil {
if err := assign(cmd, v, false, false); err != nil {
return err
}
}
case []interface{}:
for _, v := range nm {
cmd := buildCmd(true, prefix, "")
if err := assign(cmd, v, false); err != nil {
if err := assign(cmd, v, false, false); err != nil {
return err
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (

var (
testCommands = []string{
"test firewall ipv6-name WAN_IN default-action",
"test firewall ipv6-name WAN_IN rule 10 state established",
"test firewall ipv6-name WAN_IN rule 10 state related",
"test firewall ipv6-name WAN_IN rule 10 action",
"test firewall ipv6-name WAN_IN rule 20 action",
"test firewall ipv6-name WAN_IN rule 20 protocol",
"test firewall ipv6-name WAN_IN default-action drop",
"test firewall ipv6-name WAN_IN rule 10 state established enable",
"test firewall ipv6-name WAN_IN rule 10 state related enable",
"test firewall ipv6-name WAN_IN rule 10 action accept",
"test firewall ipv6-name WAN_IN rule 20 action accept",
"test firewall ipv6-name WAN_IN rule 20 protocol ipv6-icmp",
"test firewall ipv6-name WAN_IN rule 30",
"test service mdns repeater interface eth1.10",
"test service mdns repeater interface eth2.20",
Expand Down

0 comments on commit b16a6df

Please sign in to comment.