Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow firewall list command #318

Merged
merged 2 commits into from
May 17, 2023
Merged
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
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