Skip to content

Commit

Permalink
Fix slow firewall list command (#318)
Browse files Browse the repository at this point in the history
* Update firewall_list.go

* Fix import order and create networkMap

---------

Co-authored-by: Haardik Dharma <haardik@civo.com>
  • Loading branch information
haardikdharma10 and haardikdharma10 committed May 17, 2023
1 parent 50b0606 commit 88db175
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions cmd/firewall/firewall_list.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package firewall

import (
"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"

"os"
"strconv"

"github.com/spf13/cobra"

"github.com/civo/civogo"
"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
)

var firewallListCmd = &cobra.Command{
Expand Down Expand Up @@ -43,15 +44,25 @@ Example: civo firewall ls -o custom -f "ID: Name"`,
os.Exit(1)
}

networks, err := client.ListNetworks()
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}

var networkMap map[string]string
var network civogo.Network
for _, network = range networks {
networkMap = map[string]string{network.ID: network.Label}
}
ow := utility.NewOutputWriter()
for _, firewall := range firewalls {
network, _ := client.FindNetwork(firewall.NetworkID)

ow.StartLine()

ow.AppendDataWithLabel("id", firewall.ID, "ID")
ow.AppendDataWithLabel("name", firewall.Name, "Name")
ow.AppendDataWithLabel("network", network.Label, "Network")
ow.AppendDataWithLabel("network", networkMap[network.Label], "Network")
ow.AppendDataWithLabel("rules_count", strconv.Itoa(firewall.RulesCount), "Total rules")
ow.AppendDataWithLabel("instances_count", strconv.Itoa(firewall.InstanceCount), "Total Instances")
ow.AppendDataWithLabel("clusters_count", strconv.Itoa(firewall.ClusterCount), "Total Clusters")
Expand Down

0 comments on commit 88db175

Please sign in to comment.