From ac2c6503d13136941362b972e35e29c0c9a06705 Mon Sep 17 00:00:00 2001 From: Karsten Kosmala Date: Mon, 12 Feb 2024 21:57:39 +0100 Subject: [PATCH 1/3] send empty FirewallRule instead of null --- internal/cmd/firewall/delete_rule.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go index 69577e49..052f7543 100644 --- a/internal/cmd/firewall/delete_rule.go +++ b/internal/cmd/firewall/delete_rule.go @@ -114,6 +114,9 @@ var DeleteRuleCmd = base.Cmd{ if len(rules) == len(firewall.Rules) { return fmt.Errorf("the specified rule was not found in the ruleset of Firewall %d", firewall.ID) } + if len(rules) == 0 { + rules = []hcloud.FirewallRule{} + } actions, _, err := s.Client().Firewall().SetRules(s, firewall, hcloud.FirewallSetRulesOpts{Rules: rules}, ) From 2c09dace2abfe8332ea9c8562ec89bb5de1a541d Mon Sep 17 00:00:00 2001 From: Karsten Kosmala Date: Mon, 12 Feb 2024 22:18:54 +0100 Subject: [PATCH 2/3] initialize empty list of FirewallRule --- internal/cmd/firewall/delete_rule.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go index 052f7543..52df4fa0 100644 --- a/internal/cmd/firewall/delete_rule.go +++ b/internal/cmd/firewall/delete_rule.go @@ -105,7 +105,7 @@ var DeleteRuleCmd = base.Cmd{ } } - var rules []hcloud.FirewallRule + var rules = make([]hcloud.FirewallRule, 0) for _, existingRule := range firewall.Rules { if !reflect.DeepEqual(existingRule, rule) { rules = append(rules, existingRule) @@ -114,9 +114,6 @@ var DeleteRuleCmd = base.Cmd{ if len(rules) == len(firewall.Rules) { return fmt.Errorf("the specified rule was not found in the ruleset of Firewall %d", firewall.ID) } - if len(rules) == 0 { - rules = []hcloud.FirewallRule{} - } actions, _, err := s.Client().Firewall().SetRules(s, firewall, hcloud.FirewallSetRulesOpts{Rules: rules}, ) From 964325724e69d42d44e0bb04efab67de3de4d236 Mon Sep 17 00:00:00 2001 From: Karsten Kosmala Date: Tue, 13 Feb 2024 10:28:12 +0100 Subject: [PATCH 3/3] fix test on deleting last fw rule --- internal/cmd/firewall/delete_rule_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/firewall/delete_rule_test.go b/internal/cmd/firewall/delete_rule_test.go index b693a79f..297456fd 100644 --- a/internal/cmd/firewall/delete_rule_test.go +++ b/internal/cmd/firewall/delete_rule_test.go @@ -36,7 +36,7 @@ func TestDeleteRule(t *testing.T) { Get(gomock.Any(), "test"). Return(fw, nil, nil) fx.Client.FirewallClient.EXPECT(). - SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{Rules: nil}). + SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{Rules: []hcloud.FirewallRule{}}). Return([]*hcloud.Action{{ID: 123}, {ID: 321}}, nil, nil) fx.ActionWaiter.EXPECT(). WaitForActions(gomock.Any(), gomock.Any(), []*hcloud.Action{{ID: 123}, {ID: 321}}).